Page 1 of 1
mysql_fetch_array
Posted: Tue Dec 28, 2004 8:47 am
by robjime
It seems that im doing everything write my the info from the data base isn't showing up.
Code: Select all
include('config.inc.php');
$id = $_GET['p'];
mysql_connect($dblocal, $dbuser, $dbpassword);
mysql_select_db($database) or die( "Unable to select database");
$query = "Select * From rr_posts Where id = '$id'";
$result = mysql_query($query);
$info = mysql_fetch_array($result);
$pid=$info['id'];
$title=$info['title'];
$content=$info['content'];
$date=$info['date'];
$cata=$info['cat'];
Posted: Tue Dec 28, 2004 8:52 am
by feyd
check the return code from [php_man]mysql_query()[/php_man], hint: [php_man]mysql_error()[/php_man]
Posted: Tue Dec 28, 2004 10:33 am
by Skilo
Try
$info = mysql_fetch_row($result);
unless
$info = mysql_fetch_row($result);
Posted: Tue Dec 28, 2004 11:29 am
by feyd
[php_man]mysql_fetch_row()[/php_man] returns numeric indexed arrays, robjime is using named indices.
Posted: Tue Dec 28, 2004 11:40 am
by Robert Plank
feyd is right, never do a query without error checking. It should be: $result = mysql_query($query) or die(mysql_error());
Posted: Tue Dec 28, 2004 2:00 pm
by protokol
Don't ever die() in a script. Always exit gracefully.
Posted: Tue Dec 28, 2004 2:18 pm
by robjime
Well it seems like the query is executing correctly, i tested it. Also when i echo $info shouldn't it return ARRAY, its not.
Posted: Tue Dec 28, 2004 2:50 pm
by magicrobotmonkey
echo the query and run it and see if its returning any rows. if it returns no rows it wont return a error, but you can use mysql_num_rows() to see how many returned....
Re: mysql_fetch_array
Posted: Tue Dec 28, 2004 7:41 pm
by m3rajk
try the following:
robjime wrote:It seems that im doing everything write my the info from the data base isn't showing up.
Code: Select all
include('config.inc.php');
$id = $_GET['p'];
mysql_connect($dblocal, $dbuser, $dbpassword);
mysql_select_db($database) or die( "Unable to select database");
$query = "Select * From rr_posts Where id = '$id'";
$result = mysql_query($query);
$err1=mysql_error(); echo "<br />#err1"; // look for any error DURING execution... sometimes not visible when taking your command out and executing it directly
$info = mysql_fetch_array($result);
$err2=mysql_error(); echo "<br />$err2"; // same as above
$pid=$info['id'];
$title=$info['title'];
$content=$info['content'];
$date=$info['date'];
$cata=$info['cat'];