English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Hi,
Whats wrong with my query, i get notces saying its not a valid mysql statement....

$entrys=mysql_query("SELECT * FROM tags WHERE user_id='$user_id' AND approved_tag_flag = 1 ORDER BY date_of_tag");

while($e=mysql_fetch_array($entrys))
{
$page = $e['tag_id'];
$locationforlink = "&tagid=". $e['tag_id'];
}

2007-08-20 01:56:36 · 4 answers · asked by jeff lemon 1 in Computers & Internet Programming & Design

it cut off this in the middle:

while($e=mysql_fetch_array ($entrys))

2007-08-20 01:57:09 · update #1

4 answers

Add "DESC" or "ASC":

$entrys=mysql_query("SELECT * FROM tags WHERE user_id='$user_id' AND approved_tag_flag = 1 ORDER BY date_of_tag DESC");

And... "entries", not "entrys" :P

2007-08-20 04:28:03 · answer #1 · answered by Bambou Chantant 6 · 1 1

I'm assuming $user_id is a php variable that you have already defined. Your query looks ok provided the fields user_id, approved_tag_flag and date_of_tag are named correctly.

I'd add 'echo $entrys' before running the query to make sure the SQL looks how you expect it to. You can then remove this once your code works as you want it to.

Can you execute a simple query like 'SELECT * FROM tags'? This will tell you if the problem is connecting to your database or if it is your SQL statement.

2007-08-20 02:12:21 · answer #2 · answered by irongut 3 · 1 0

You have not read my previous note again!

$entrys=mysql_query("SELECT * FROM tags WHERE user_id='$user_id' AND approved_tag_flag = 1 ORDER BY date_of_tag");

WHERE ` user_id ` = ' " . $user_id . " ' AND

(spaces added for visibility)

Watch the `, ', ", and . !
(You do not need to put ASCending or DESCending: it is ASCending by default)

2007-08-20 20:59:13 · answer #3 · answered by just "JR" 7 · 0 1

You need to add DESC or ASC on your order by

2007-08-20 02:38:39 · answer #4 · answered by Big D 4 · 1 1

fedest.com, questions and answers