php - 在页面中我有 for 循环函数吗?在 for($i=0;$i<=$max;$i++){ Size 查询中只从 mysql 数据库检索一行?

标签 php javascript mysql

在页面中我有for循环函数吗?在for($i=0;$i<=$max;$i++){ Size Query只检索一个 row来自 mysql 数据库和 for loop repeat that size row again and again什么时候new product is entered?

页面功能

    <?php
if(is_array($_SESSION['cart'])){
echo '<tr bgcolor="#FFFFFF" style="font-weight:bold"><td align="center"><font style="font-family:Arial,Helvetica,sans-serif;  font-size:14px; color:#000;">Item Code</font></td><td align="center"><font style="font-family:Arial,Helvetica,sans-serif;  font-size:14px; color:#000;">Product Name</font></td>
<td align="center"><font style="font-family:Arial,Helvetica,sans-serif;  font-size:14px; color:#000;">Product Image</font></td>
<td><font style="font-family:Arial,Helvetica,sans-serif;  font-size:14px; color:#000;">Price</font></td>
<td><div><font style="font-family:Arial,Helvetica,sans-serif;  font-size:14px; color:#000;">Size</font></div></td>
<td><font style="font-family:Arial,Helvetica,sans-serif;  font-size:14px; color:#000;">Options</font></td></tr>';

 $max=count($_SESSION['cart'] );
 for($i=0;$i<=$max;$i++){
 $id=$_SESSION['cart'][$i]['id'];
 $q=$_SESSION['cart'][$i]['qty'];
 $product=get_product_name($id);
 $image=get_product_image($id);
 $ids=get_id($id);
 $itemcode=get_itemcode($id);
 $size=get_size($id);
 if($q==0) continue;

 ?>
 </table>


 <diiv style="float:left; margin-left:42px;"><font style="font-family:Arial,Helvetica,sans-serif;  font-size:15px; color:#000;">
 <?php echo $itemcode; ?>
 <input type="hidden" name="itemcode[]" value="<?php echo $itemcode?>" /></font></div><br />

 <div style="float: left;margin-left: 122px; margin-top: -14px;"><font style="font-family:Arial,Helvetica,sans-serif;  font-size:15px; color:#000;">
 <?php echo $product?>
 <input type="hidden" name="product[]" value="<?php echo $product?>" /></font></div><br />


<div style="float: left;margin-left: 387px;margin-top: -24px;"><font style="font-family:Arial,Helvetica,sans-serif;  font-size:15px; color:#000;">
<img name="image" id="image" src="admin/uploads/small0_<?php echo $image?>" width="150" height="150">
<input type="hidden" name="image[]" id="image"  value="<?php echo $image?>"  /> </font></div><br />

<div style="float: left;margin-left: 548px;margin-top: -147px;"><font style="font-family:Arial,Helvetica,sans-serif;  font-size:15px; color:#000;">
<?php echo get_price($id) ?>
<input type="hidden" name="price[]" id="price" value="<?php echo get_price($id)?>" /></font></div><br />

<?php //foreach ($size as $sizes) { ?>
<div style="float: left;margin-left: 625px;margin-top: -149px;"><font style="font-family:Arial,Helvetica,sans-serif;font-size:15px; color:#000;">
<?php echo $size; ?> 
</font><input type="hidden" name="size" value="<?php echo $size; ?>" /></font></div><?php //}?><br />

<div style="float: left;margin-left:686px;margin-top: -150px;"><a href="javascript:del(<?php echo $id?>)">
<input type="button" class="button5" value="Remove" /></a></div><br /> 
<hr style="width:800px" />  

<?php                   
}
?>

 <?php
 }
 else{
 echo "There are no items in your shopping cart!";
 }
 ?>

尺码查询

function get_size($id){
$result=mysql_query("SELECT size FROM mywishlist order by id") or die("My Wish Size Problem"."<br/><br/>".mysql_error());
while($row=mysql_fetch_array($result)){
return $row['size'];
}}

Mywishlist 表格屏幕截图 now see there are two sizes in the size column

页面截图 page screenshot

最佳答案

因为您的 get_size() 函数每次调用该函数时都会重新运行查询,因此您立即从循环中返回第一行。

简而言之,你需要学习基本的编程。

关于php - 在页面中我有 for 循环函数吗?在 for($i=0;$i<=$max;$i++){ Size 查询中只从 mysql 数据库检索一行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15342334/

相关文章:

php - laravel v4.2 中 Redis 服务器连接错误

php - MySQL 如果存在则更新一行,如果不存在则插入,以及一般查询建议

mysql - 在安装在/var/lib/mysql上的lv上安装mysql-server 5.7

javascript - Apple如何在其新的mac pro说明页面上使html5视频向后播放?

javascript - 升级到 v14 时 Discord.js v13 代码中断

mysql - 无法在 jenkins 上创建 PoolableConnectionFactory

javascript - ajax:如何从数据库获取数据到html?

php - 除非在 CakePHP 中启用调试,否则为什么我的索引页面不会出现?

php - GIF 到 mp4 转换

javascript - 从javascript中的嵌套数组中过滤数组