Hi,
I have this strange problem, I select some data from the database, there is no problem in the query and even when I use mysql_num_rows on the query it gives me the right number of entries in the table I'm selecting from, but when I try to echo every row it echos empty values... what is the problem??

$sql = "SELECT * FROM table";
		$query = mysql_query($sql) or die(mysql_error());
		$row_number = mysql_num_rows($query);
		while ($row = mysql_fetch_array($query))
		{
			echo "row= ".$row["id"];
                         }

is it Giving any Erro?
what if u try this

while ($row = mysql_fetch_array($query))
{
$id=$row['id'];
echo "row=  $id ";

}

it is the same result, it writes "row=" as if the value is empty!

what is ur table structure,i mean the fields?

theighost,
Post complete source code.

mysql_connect('server','user','pass');
        	mysql_select_db('database');
$sql = "select * from table";
        	$query = mysql_query($sql) or die(mysql_error());
        	while($row = mysql_fetch_array($query))
        	{
        		$search_row = $row['id'];
                        echo $search_row;
             }

Try changing "$row" to "$row[0]" and see if you still get nothing.

I solved it in a really strange way guys.. wtf is this version of PHP that i'm using, that obliges me to declare the variables before using.

I just put $row=0; $search_row=0; before making the query and it worked, really strange!!!!

thanks anyway :)

Thats good you solved it. But this $row is an array. So making it 0 is a bit strange. What other thing you can do is, you can declare it as an empty array:

$row = array();

$row = mysql_fetch_array();
// Proceed with rest of the code

Yes I used some arrays in my script and had to declare some of the variable as $variable = array();

Dear Guys,
I am getting this error on ther server side.
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL

Following Codes are working fine on localhost:-

$result = mysql_query("SELECT * FROM $txt2 WHERE $txt3 LIKE '%$txt%'");
 
echo "<table border='2' bordercolor='black' cellspacing='2' cellpadding='2'>
<tr>

<TD bgcolor='pink' align='center' width='10'>ID</TD>
<TD bgcolor='pink' align='center' width='10'>SUBJECT</TD>
<TD bgcolor='pink' align='left' width='10'>AUTHOR</TD>
<TD bgcolor='pink' align='left' width='10'>TITLE</TD>
<TD bgcolor='pink' align='left' width='10'>PUBLISHER</TD>
<TD bgcolor='pink' align='left' width='10'>ACCNO</TD>
<TD bgcolor='pink' align='left' width='10'>KEYWORD</TD>

</tr>";



while($row = mysql_fetch_array($result,MYSQL_BOTH))
   {
  echo "<tr>";
  echo "<td>" . $row['ID'] . "</td>";
  echo "<td>" . $row['SUBJECT'] . "</td>";
  echo "<td>" . $row['AUTHOR'] . "</td>";
  echo "<td>" . $row['TITLE'] . "</td>";
  echo "<td>" . $row['PUBLISHER'] . "</td>";
  echo "<td>" . $row['ACCNO'] . "</td>";
  echo "<td>" . $row['KEYWORD'] . "</td>";
  echo "</tr>";
  }
echo "</table>";

mysql_close($con);

Jay G

See the sticky at the top of this forum on how to determine the error in your query. Next time please post a new thread, instead of reviving an old one.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.