Page 1 of 1

PHP MySQL Select Query

Posted: Sun Apr 01, 2012 5:16 am
by RealTuty
I am getting [syntax=php]Resource id #7[/syntax] from this query while i am trying to select the posts.

[syntax=php]
$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;
[/syntax]

what is the porblem

Re: PHP MySQL Select Query

Posted: Sun Apr 01, 2012 5:53 pm
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 [syntax=sql]id AS id[/syntax] there isnt any need to do that?

[syntax=sql]SELECT `id`,`url`,`url_key`,`date`,`email` FROM `urls` WHERE `email` = {$email} ORDER BY `date` DESC[/syntax]

Try that as your query.

Re: PHP MySQL Select Query

Posted: Tue Apr 03, 2012 1:43 am
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 :)