Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
Fábio Selinger
Forum Newbie
Posts: 7 Joined: Wed Jul 17, 2002 3:21 am
Location: Porto Alegre/RS
Post
by Fábio Selinger » Thu Aug 22, 2002 12:07 pm
please, look my code... it´s works... but not showing the first record, is it all right?
Code: Select all
$existe = mysql_query("SELECT * FROM amigos", $conn);
$rows = mysql_fetch_array($existe, MYSQL_NUM);
if($rows){
print("<center>
<table width='75%' border='1'>");
while (list($nom, $sen, $nic) = mysql_fetch_array($existe, MYSQL_NUM)) {
print("<tr>
<td width='50%'>
$nom
</td>
<td width='25%'>
$sen
</td>
<td width='25%'>
$nic
</td>
</tr>");
}
print("</table>
</center>");
}
else{
echo "Não há registros!";
exit;
}
nielsene
DevNet Resident
Posts: 1834 Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA
Post
by nielsene » Thu Aug 22, 2002 12:44 pm
I'm not an mysql expert, but I would guess that when you do
Code: Select all
$rows= mysql_fetch_array($existe, MYSQL_NUM);
that its advancing the recordset so when you use your while loop its grabbing the second entry and skipping the first.
I think
will fix your problem.
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Thu Aug 22, 2002 1:25 pm
right.
If you want to test wether the query failed at all or not you check 'if ($existe)'. (if this fails it's a good time to check mysql_error() )
If you want to know if there's a matching record or not you check 'if (mysql_row_num($existe) > 0)'
Fábio Selinger
Forum Newbie
Posts: 7 Joined: Wed Jul 17, 2002 3:21 am
Location: Porto Alegre/RS
Post
by Fábio Selinger » Thu Aug 22, 2002 3:17 pm
Volka, thnks, but i think the name of the function correct is msql_num_rows(), no?
and nielsene, not works! in a good portuguese"DEU NO MESMO!"
thnks
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Thu Aug 22, 2002 3:21 pm
it is
mikeq
Forum Regular
Posts: 512 Joined: Fri May 03, 2002 3:33 am
Location: Edinburgh, Scotland
Post
by mikeq » Fri Aug 23, 2002 4:35 am
$existe = mysql_query("SELECT * FROM amigos", $conn);
$rows = mysql_fetch_array($existe, MYSQL_NUM);this is getting the first record
if($rows){
print("<center>
<table width='75%' border='1'>");
while (list($nom, $sen, $nic) = mysql_fetch_array($existe, MYSQL_NUM))this part now gets the next and subsequent records {
print("<tr>
<td width='50%'>
$nom
</td>
<td width='25%'>
$sen
</td>
<td width='25%'>
$nic
</td>
</tr>");
}
print("</table>
</center>");
}
else{
echo "Não há registros!";
exit;
}
get rid of the first mysql_fetch_array
Fábio Selinger
Forum Newbie
Posts: 7 Joined: Wed Jul 17, 2002 3:21 am
Location: Porto Alegre/RS
Post
by Fábio Selinger » Sat Sep 28, 2002 1:09 pm
thnks for all, its works!!!
i used mysql_num_rows() and so SHAZAM!!!!
all worked!