Php mysql pdo的简短预览
我无法使用LEFT()和substr()进行简短预览,只能使用RIGHT()和mysql PDO进行简短预览,但我需要显示描述的前100个字符,而不是最后一个字符…我的代码中的错误在哪里 代码:Php mysql pdo的简短预览,php,mysql,pdo,Php,Mysql,Pdo,我无法使用LEFT()和substr()进行简短预览,只能使用RIGHT()和mysql PDO进行简短预览,但我需要显示描述的前100个字符,而不是最后一个字符…我的代码中的错误在哪里 代码: 正如您在评论中提到的,oferta_mensaje的类型是长文本。在这种情况下,可以使用CAST() "SELECT id_oferta, oferta_titulo, oferta_subtitulo, CAST(oferta_mensaje as char(50))
正如您在评论中提到的,oferta_mensaje的类型是长文本。在这种情况下,可以使用
CAST()
"SELECT id_oferta, oferta_titulo, oferta_subtitulo,
CAST(oferta_mensaje as char(50))
AS oferta_mensaje, oferta_precio, oferta_foto
FROM OFERTAS ORDER BY id_oferta DESC";
LEFT(blog,100),因为blog
适合我。@davidstrachan-when不在if内!空的
也为我工作,但是如果我的代码在If!空的
不向我显示带有左的博客消息,只有带有右的…或者在某些页面中正在工作(管理页面),而在其他页面中没有(网页)…上面的代码中没有提到如果!空的
**请**显示所有相关代码。@davidstrachan就像我在不同的代码或页面中告诉过你的那样,左边的代码可以工作,但在其他代码或页面中则不行。我添加了与LEFT一起工作的代码,第一个直到现在才工作…只有使用RIGHT()才能作为前导空格tryLEFT(LTRIM(blog),100)
<?php
$sql = "SELECT id_oferta, oferta_titulo, oferta_subtitulo, LEFT(oferta_mensaje, 50) AS oferta_mensaje, oferta_precio, oferta_foto FROM OFERTAS ORDER BY id_oferta DESC";
$result = $conn->query($sql);
while($row = $result->fetch(PDO::FETCH_ASSOC)) { ?>
<?php if (!empty($row['id_oferta'])) { echo '
<div class="span3" id"'.$row["id_oferta"].'">
<div class="tile">
<div>
<img src="../admin/assets/img/ofertas/'.$row["oferta_foto"].'" alt="'.$row["oferta_titulo"].'" class="img-circle" style="max-width:100px; max-height:100px;" />
</div>
<a href="#myModal" id"'.$row["id_oferta"].'" role="button" class="btn btn-info" data-toggle="modal"><span>'; echo $row["oferta_titulo"]; echo '</span></a>
<h6><small>'; echo $row["oferta_subtitulo"]; echo '</small></h6>
<p>'; echo $row["oferta_mensaje"]; echo '</p>
<h5><div class="intro-icon-disc"><a href="#myModal" id"'.$row["id_oferta"].'" role="button" class="btn btn-primary" data-toggle="modal"><b>$'; echo $row["oferta_precio"]; echo '</b></a></div></h5>
</div>
<div class="pad25"></div>
</div>'; } ?>
<div id="myModal" class="modal hide fade" id"<?php echo $row["id_oferta"]; ?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
<h3 id="myModalLabel"><b>Cupón para : <?php echo $row["oferta_titulo"]; ?></b></h3>
</div>
<div class="modal-body">
<form name="cupon" id="cupon" method="post">
<div class="row-fluid grid">
<div class="span6">
<label><b>Nombres : </b></label><input type="text" class="input-block-level" name="nombres" />
</div>
<div class="span2">
</div>
<div class="span4">
<label><b>DUI : </b></label><input type="text" class="input-block-level" name="dui" />
</div>
</div>
<div class="row-fluid grid">
<div class="span6">
<label><b>Correo : </b></label><input type="text" class="input-block-level" name="corelectronico" />
</div>
</div>
<input type="hidden" name="of_titulo" type="text" value="<?php echo $row['oferta_titulo']; ?>" />
<input type="hidden" name="of_stitulo" type="text" value="<?php echo $row['oferta_subtitulo']; ?>" />
<input type="hidden" name="of_mensaje" type="text" value="<?php echo $row['oferta_mensaje']; ?>" />
<input type="hidden" name="of_precio" type="text" value="<?php echo $row['oferta_precio']; ?>" />
<input type="hidden" name="of_foto" type="text" value="<?php echo $row['oferta_foto']; ?>" />
<div class="row-fluid grid">
<div class="span4" id="div1">
<input type="hidden" name="action" value="create_cupon" />
<button class="positive btn btn-inverse" type="submit" id="enviar" name="enviar">
<i class="icon icon-save icon-white"></i>
Grabar Cupón
</button>
</div>
<div class="span4">
</div>
<div class="span4" id="div2">
<a class="negative btn btn-info" href="impcupon.php" target="popup" onClick="window.open(this.href, this.target, "scrollbars=yes,toolbar=no,menubar=no,status=no,width=parent,height=parent"); return false;" onclick="boton(this)" id="imprimir">
<i class=" icon-print icon-white"></i>
Imprimir Cupón
</a>
</div>
</div>
</form>
<div id="loading_cupon" style="display:none;"><img src="img/loaders/loader.gif" /></div>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">
Cerrar
</button>
</div>
</div><?php } ?>
"SELECT id_oferta, oferta_titulo, oferta_subtitulo,
CAST(oferta_mensaje as char(50))
AS oferta_mensaje, oferta_precio, oferta_foto
FROM OFERTAS ORDER BY id_oferta DESC";