gpt4 book ai didi

php - 从 mysql 表中获取文本,编辑它并使用 php 打印它

转载 作者:行者123 更新时间:2023-11-29 08:57:23 25 4
gpt4 key购买 nike

我想要做的是从我的数据库中获取每个产品的详细信息,使其具有一定数量的字符,例如至少 200 个长度,但我想对其进行编辑,以便它不显示半个单词。这是我组装的代码,但没有运气。

<?php 
//Block to show the latest products
$dynamicList="";
$sql=mysql_query("SELECT * FROM products ORDER BY date_added DESC LIMIT 6");
$product_count=mysql_num_rows($sql);

if($product_count > 0){

while($row = mysql_fetch_array($sql)){

$id=$row["id"];
$product_name=$row["product_name"];
$price=$row["price"];
$details[]=$row["details"];
$details = substr($details, 0, 490);
for($counter = strlen($details); $counter >= 0; $counter--){

if($details[$counter] != " "){
$details=substr($details, 0, ($counter -1));
}else if($details[$counter] == " "){
break;
}

}


$date_added=strftime("%b %d, %Y", strtotime($row["date_added"]));
$dynamicList .='<table width="100%" border="0" cellspacing="0" cellpadding="1">
<tr>
<td width="20%" height="121" valign="top">
<a href="product.php?id=' . $id . '">
<img src="inventory_images/' . $id . '.jpg" alt="' . $product_name . '" width="auto" style="border:#FFFFFF 1px solid" height="150" border="1"/></a></td>
<td width="80%" valign="top">
<p><a href="product.php?id=' . $id . '">' . $product_name . '</a></p>
<p>' . $details . '</p>

<p>' . $price . '€</p>
<form id="form1" name="form1" method="post" action="cart.php">
<input type="hidden" name="pid" id="pid" value="'.$id.'" />
<input type="submit" name="button" id="button" value="Προσθήκη στο Καλάθι" />
</form>

</td>
</tr>
</table>';
}

}else{

$dynamicList="We have no products in our store yet";

}

?>

最佳答案

您的问题是 $details 是一个数组,并且在该部分您没有使用数组索引。如果您想使用字符串,最好的办法是重命名其中一个,这样 PHP 就不会混淆两者。

关于php - 从 mysql 表中获取文本,编辑它并使用 php 打印它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9609341/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com