Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
I 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 }
Add a comment
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.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.