Special features of mysql_fetch_array
-
Got a list of DB tables. But it's not working with these data.
$str = "show TABLEs LIKE 'dialog_".$_POST['login']."%'"; $res = mysql_query($str); $num = mysql_num_rows($res);
$row = mysql_fetch_array($res);
print $row[0];$row = mysql_fetch_array($res);
print $row[0];for ($i=0; $i<mysql_num_rows($res); $i++)
{
print $i." ";
$row = mysql_fetch_row($res);
print $row[0];
}
The problem is, this code is working.
$row = mysql_fetch_array($res);
print $row[0];$row = mysql_fetch_array($res);
print $row[0];
This is not the case.
for ($i=0; $i<mysql_num_rows($res); $i++)
{
print $i." ";
$row = mysql_fetch_array($res);
print $row[0];
}
What am I doing wrong?
-
Functional characteristics
mysql_fetch_array()
and, in general, all directional functions are that they are moving forward with a line from the resulting table. So if you have only two records in your table, and you're twice calling.mysql_fetch_array()
the subsequent challenges do not lead to anything, as the cadet points to the end of the resulting table. In order to set a courseor at the beginning, you'll need to perform your function.mysql_data_seek()
♪$str = "show TABLEs LIKE 'dialog_".$_POST['login']."%'"; $res = mysql_query($str); $num = mysql_num_rows($res);
$row = mysql_fetch_array($res);
print $row[0];$row = mysql_fetch_array($res);
print $row[0];mysql_data_seek($res);
for ($i=0; $i<mysql_num_rows($res); $i++)
{
print $i." ";
$row = mysql_fetch_row($res);
print $row[0];
}