i have a problem with this code amay any one help me am doing a class project but stuck here is the code its bring an error
Warning: mysql_num_fields(): supplied argument is not a valid MySQL result resource in C:\wamp\www\kawempe_HC\staf.php on line 7

Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in C:\wamp\www\kawempe_HC\staf.php on line 16

<?php
$query="select * from staff";
$result=mysql_query($query);

echo "<table border=1>";
echo "<tr>"; 
for($i=0;$i<mysql_num_fields($result);$i++) 
{

    echo "<th>"; 
    echo mysql_field_name($result, $i); 
    echo "</th>"; 
}


while($row=mysql_fetch_row($result))
{
    echo "<tr>"; 
    for($j=0;$j<$i;$j++) 
    { 
    echo "<td>";
    echo $row[$j]; 
    echo "</td>"; 
    }
    echo "</tr>"; 
}

echo "</tr>"; 
echo "</table>"; 

?>

are you sure that you have any data in your table ?
just do an: <?php echo mysql_num_fields($results);?>

goodmorning am doing a class project but this code cant echo ann array it just echos 1 field yet i want an array from all data in the table

<?php//The code is for selecting all patients records in the database
//This selects the database and connects to the database
require_once('Connections/Database.php');
mysql_select_db($database_Database, $Database);
//$stat="select * from patients";
//$stat2=mysql_query($stat) or die('Error, query failed,we cant select any records');

$tbl_name="patients";

$user_result="select * from patients";
$qry=mysql_query($user_result) Or die(mysql_error());



$user_array=mysql_fetch_array($qry);
echo"<center>";
echo"<table CELLPADDING=10 border=1>";
echo"<tr>";
echo"<td>Patients ID</td>";

echo"<td>Village</td>";

echo"<td>Lastname</td>";

echo"<td>Firstname</td>";
echo"<td>Department</td>";
echo"<td>Age</td>";

echo"<td>Sex</td>";


echo"<td>Tribe</td>";
echo"<td>symptoms</td>";
echo"<td>Date</td>";
echo"<td>Weight</td>";
echo"<td>Height</td>";
echo"<td>Temperature</td>";
echo"<td>Blood Pressure</td>";

echo"</tr>";
echo"<tr>";
echo"<td>".$user_array['pID']."</td>";


echo"<td>".$user_array['village']."</td>";

echo"<td>".$user_array['pName']."</td>";
echo"<td>".$user_array['pfName']."</td>";
echo"<td>".$user_array['dept'] ."</td>";
echo"<td>".$user_array['age'] ."</td>";

echo"<td>".$user_array['sex']."</td>";


echo"<td>".$user_array['tribe']."</td>";
echo"<td>".$user_array['symptoms']."</td>";

echo"<td>".$user_array['day']."" .$user_array['month']."".$user_array['year']."</td>";
echo"<td>".$user_array['wgt']."</td>";
echo"<td>".$user_array['hgt']."</td>";
echo"<td>".$user_array['temp']."</td>";
echo"<td>".$user_array['bldp']."</td>";


echo"</table>";


mysql_close();?>

pliz help me

This article has been dead for over six months. Start a new discussion instead.