mysql_fetch_array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
robjime
Forum Commoner
Posts: 46
Joined: Sat Apr 03, 2004 12:26 pm
Location: the RO

mysql_fetch_array

Post 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'];
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

check the return code from [php_man]mysql_query()[/php_man], hint: [php_man]mysql_error()[/php_man]
Skilo
Forum Newbie
Posts: 2
Joined: Tue Dec 28, 2004 10:12 am

Post by Skilo »

Try
$info = mysql_fetch_row($result);
unless
$info = mysql_fetch_row($result);
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

[php_man]mysql_fetch_row()[/php_man] returns numeric indexed arrays, robjime is using named indices.
Robert Plank
Forum Contributor
Posts: 110
Joined: Sun Dec 26, 2004 9:04 pm
Contact:

Post by Robert Plank »

feyd is right, never do a query without error checking. It should be: $result = mysql_query($query) or die(mysql_error());
User avatar
protokol
Forum Contributor
Posts: 353
Joined: Fri Jun 21, 2002 7:00 pm
Location: Cleveland, OH
Contact:

Post by protokol »

Don't ever die() in a script. Always exit gracefully.
robjime
Forum Commoner
Posts: 46
Joined: Sat Apr 03, 2004 12:26 pm
Location: the RO

Post 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.
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post 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....
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Re: mysql_fetch_array

Post 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'];
Post Reply