Jump to content

question about getting query elements.


onedumbcoder

Recommended Posts

if i have

$result = mysql_query("...")

 

and i keep doing

 

$list = mysql_fetch_array($result );

echo $list['name']

 

$list = mysql_fetch_array($result );

echo $list['name']

 

$list = mysql_fetch_array($result );

echo $list['name']

 

what will happen if there is no more elements left? will it through an exception?

 

and is there a way to check if there is any more elements left

 

for example

 

if(mysql_has_next($result))

 

 

Link to comment
https://forums.phpfreaks.com/topic/106463-question-about-getting-query-elements/
Share on other sites

Use a while loop. It will automatically stop processing once the elements run out.

 

From the manual:

array mysql_fetch_array  ( resource $result  [, int $result_type  ] )

Returns an array that corresponds to the fetched row and moves the internal data pointer ahead.

It knows.

 

<?php
$result = mysql_query("...");
if (mysql_num_rows($result) > 0)
{
while ($list = mysql_fetch_array($result))
{
	echo $list['name'];
}
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.