我有下面的代码设置和mysql_num_rows回声2,因为它应该是。 我想以某种方式访问已被选中的第二行,但无法弄清楚如何。 echo $ lTitl总是以随机顺序从第一行返回标题,但我还想在此之后访问行。我该怎么做呢?如何在选择它们后访问所有行的列值?
$sql = "SELECT id, seller, title, kondition, price, shippingcost FROM items WHERE active='1' ORDER BY rand() LIMIT 2";
$item_query = mysql_query($sql, $connect);
foreach ($row = mysql_fetch_assoc($item_query) as $test) {
$id = $row["id"];
$seller = $row["seller"];
$lTitl = $row["title"];
$lCond = $row["kondition"];
//$lPrimIma = $row["primaryimage"];
$lPric = $row["price"];
$lShip = $row["shippingcost"];
}
echo $lTitl;
mysql_fetch_assoc()只返回一个行,所以你的foreach(mysql_fetch_assoc()为$测试)只会循环一次。你想mysql_fetch_all – Rottingham
看到我的答案@willi http://stackoverflow.com/a/21056095/1607528 – 2014-01-10 23:07:41