0

I need to print one row from a table so a while loop isn't necessary, is there any other method?

4 Answers 4

3

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 } 
Sign up to request clarification or add additional context in comments.

1 Comment

Although you should be using PDO.
1
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.

Comments

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

Comments

0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.