whatg
06-21-2010, 07:30 PM
Ok so I'm not completely new to php. Have done some basic scripts. Thought I would try and be clever by displaying information from one of my tables in mysql. That didn't go quite to plan.
When I ran the script I got this error:"mysql_num_rows(): supplied argument is not a valid"
Apparently the most common mistake is connecting to the wrong table, I have checked and re-checked this and I sure that I'm (also checked upper/lowercase ). I also ran a simple script to just connect to the database, that works.
Any help would be great, thanks. :D
This is my code:
<?php
//set variables to connect
$host='localhost';
$user='grahame2';
$pass='Q2JKWP@F';
$db='grahame2_test';
//connect to mysql
mysql_connect($host,$user,$pass,$db) or die("Unable to connect to the database");
$query="SELECT * FROM family";
$result=mysql_query($query) or die("Ivalid query");
$num=mysql_num_rows($result);
$i=0;
while($i<num){
$forename=mysql_result($result,$i,"forename");
$surename=mysql_result($result,$i,"surname");
$age=mysql_result($result,$i,"age");
echo "$forename,$surname,$age";
$i++;
}
?>
When I ran the script I got this error:"mysql_num_rows(): supplied argument is not a valid"
Apparently the most common mistake is connecting to the wrong table, I have checked and re-checked this and I sure that I'm (also checked upper/lowercase ). I also ran a simple script to just connect to the database, that works.
Any help would be great, thanks. :D
This is my code:
<?php
//set variables to connect
$host='localhost';
$user='grahame2';
$pass='Q2JKWP@F';
$db='grahame2_test';
//connect to mysql
mysql_connect($host,$user,$pass,$db) or die("Unable to connect to the database");
$query="SELECT * FROM family";
$result=mysql_query($query) or die("Ivalid query");
$num=mysql_num_rows($result);
$i=0;
while($i<num){
$forename=mysql_result($result,$i,"forename");
$surename=mysql_result($result,$i,"surname");
$age=mysql_result($result,$i,"age");
echo "$forename,$surname,$age";
$i++;
}
?>