开发者

PHP print from database without 'while'

I 开发者_JAVA技巧need to print one row from a table so a while loop isn't necessary, is there any other method?


You need not while.

Just do your while condition outside while 1 time.

i.e

$a=mysql_fetch_row($sql);
//use $a

instead of

while($a=mysql_fetch_row($sql)){
    //use $a
}


if (($dbResult = mysql_query("SELECT ... FROM ... LIMIT 1")) !== false)
{
  $row = mysql_fetch_array($dbResult);
  echo $row['Column_Name'];
}

Just fetch one row, no need to always loop a retrieval.


$results = mysql_query("SELECT * FROM my_table WHERE user_id = 1234");
$row = mysql_fetch_assoc($results);
echo ($row['user_id']);


Do what you would have done inside the condition of your loop, and you'll be fine.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜