【问题标题】:php retrieve multiple rows from database in for loopphp在for循环中从数据库中检索多行
【发布时间】:2013-02-26 00:13:05
【问题描述】:

如何在 for 循环中从数据库中检索多行?我的购物车页面中有for($i=0;$i<=$max;$i++) 循环为size query because of for loop repeating only one row ? 创建了问题,即使我在数据库中size column 的行中有两个不同的size Small Or Medium

i repeated same question because of my problem is still not solved

http://stackoverflow.com/questions/15333897/
what-can-i-do-if-for-loop-repeat-single-row-from-mysql-database 

【问题讨论】:

  • 显示一些php代码..我们需要查看查询和for循环。
  • 你为什么要第二次转发你的问题?
  • @redreggae 什么第二次?
  • @redreggae 你有这个问题的答案吗?
  • @redreggae 现在发生了什么你需要查看查询和 for 循环?

标签: php database shopping-cart shopping


【解决方案1】:

没有你在做什么的细节,所以这里是一般结构:

$query = "select * from some_table where something='some_value'";
if(!$result = mysql_query($query)) die("\n$query\n".mysql_error()."\n");
while($row = mysql_fetch_object($result))
{
    echo $row->some_field."\n";
}

【讨论】:

    【解决方案2】:

    您有$size=get_size($id);,但该函数没有输入参数。

    所以改变:

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

    【讨论】:

    • for($i=0;$i
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-09
    • 2020-09-07
    • 1970-01-01
    • 1970-01-01
    • 2023-03-26
    • 1970-01-01
    相关资源
    最近更新 更多