Page 1 of 1

Array

Posted: Tue Mar 18, 2003 1:50 pm
by taboas
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!"; }
?>

Posted: Tue Mar 18, 2003 2:37 pm
by Stoker
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 }

?>

Posted: Wed Mar 19, 2003 8:33 am
by taboas
This left perfect.
Now, desire to modify the field names. This would be the instruction?

<input type="text" size=25 value $myrow["Nombre"]>

Posted: Wed Mar 19, 2003 5:48 pm
by Stoker
to output data in the value field you could something like
<input type="text" size=25 value="<?php echo htmlspecialchars($myrow["Nombre"]); ?>" name="Nombre">