php在for循环中从数据库中检索多行

时间:2013-03-10 21:47:37

标签: php database shopping-cart shopping

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

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 

2 个答案:

答案 0 :(得分:0)

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

$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";
}

答案 1 :(得分:0)

你有$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'];
}