PHP MySQL Select Query

Ask about a PHP problem here.
Post Reply
RealTuty
Posts: 11
Joined: Thu Dec 15, 2011 4:29 am

PHP MySQL Select Query

Post by RealTuty »

I am getting
Resource id #7
from this query while i am trying to select the posts.
$email = mysql_real_escape_string($email);
	$r = array();
	
	$r = mysql_query("SELECT
						id AS id,
						url AS url,
						url_key AS url_key,
						date AS date,
						email AS email
					FROM urls WHERE email = '{$email}' ORDER BY date DESC");
					
	while (($row = mysql_fetch_assoc($r)) !== false) {
		
		$r[] = array(
			'id'		=> $row['id'],
			'url'		=> $row['url'],
			'url_key'	=> $row['url_key'],
			'date'		=> $row['date']
		);
		
	}
	
	return $r;
what is the porblem
bowersbros
Posts: 534
Joined: Thu May 05, 2011 8:19 pm

Re: PHP MySQL Select Query

Post by bowersbros »

I think your problem may be stemming from the fact that you're using a keyword as a field header.

Also, why do you do
id AS id
there isnt any need to do that?
SELECT `id`,`url`,`url_key`,`date`,`email` FROM `urls` WHERE `email` = {$email} ORDER BY `date` DESC
Try that as your query.
I don't like to brag, but I wasn't circumcised. I was circumnavigated. ;)

Want to learn something new? Or maybe reinforce what you already know? Or just help out? Please subscribe to my videos: http://goo.gl/58pN9
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: PHP MySQL Select Query

Post by jacek »

You are using $r for two different things, you will need to give one of them a new name. I would also recommend not using single character variable names, why not do with $rows and $result :)

Also you do need to add the backticks as above :)
Image
Post Reply