开发者

PHP print from database without 'while'

开发者 https://www.devze.com 2023-04-07 14:14 出处:网络
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.

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

精彩评论

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

关注公众号