The instruction mysql_fetch_array presents the following
error
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource on line 15
The script:
<?
$db = mysql_connect("localhost", "user", "pass");
mysql_select_db("auth",$db);
$result = mysql_query("SELECT * FROM personal",$db);
if ($myrow = mysql_fetch_array($result)) {
echo "<table border=1>\n"; echo "<tr><td>Name</td><td>Position</td></tr>\n";
do {printf("<tr><td>%s %s</td><td>%s</tr>\n", $myrow["Legajo"], $myrow["Nombre"], $myrow["email1"]);
}
while ($myrow = mysql_fetch_array($result));
echo "</table>\n";} else { echo "Sorry, no records were found!"; }
?>
Array
Moderator: General Moderators
Your query failed..
Code: Select all
<?
$db = mysql_connect('localhost', 'user', 'pass');
if (!$db) die('Unable to connect to db');
if (!mysql_select_db('auth',$db)) die('Unable to select db');
$result = mysql_query('SELECT Legajo,Nombre,email1 FROM personal',$db);
if (!$result) die('Query failed: '.mysql_error());
if ($myrow = mysql_fetch_assoc($result)) {
?><table border=1>
<tr><td>Name</td><td>Position</td></tr>
<?php
do {
printf("<tr><td>%s %s</td><td>%s</tr>\n", $myrow["Legajo"], $myrow["Nombre"], $myrow["email1"]);
} while ($myrow = mysql_fetch_assoc($result));
?></table>
<?php
}
else { ?>Sorry, no records were found!<?php }
?>