PHP/mySQL: mysql_query with SELECT, FROM, and WHERE?

Forget about PHP right now. This is your SQL query.

Forget about PHP right now. This is your SQL query: SELECT pageID, pageCategoryID, 'order', title FROM pages WHERE pageCategoryID='1' AND 'order'='2' In SQL, as in many other languages, you use quotes to type literal strings. Since the 'order' string will never equal the '1' string, your query will always return zero rows, no matter the other values.

If order is a column name, you cannot single-quote it. Now, given that ORDER is a reserved word, you'll have to use backticks around it. You can also type integers as integers (there's no need to quote them): SELECT pageID, pageCategoryID, `order`, title FROM pages WHERE pageCategoryID=1 AND `order`=2.

Thanks! This did the trick. Excellent job explaining it!

– Mark Rummel Nov 25 '11 at 18:17.

You are overwriting the variable for each record, maybe create an array like $data = array(); while ($nextPageArray = mysql_fetch_assoc($fetchedNextPageData)) { $data = array('id' => $nextPageArray'pageID', 'title' => $nextPageArray'title'); }.

Thank you for your solution. This did not fix the primary issue of needing to use backticks and removing some of the single quotes. Personally I find the way you wrote this to require a lot more code and not be as clear.

However, I'm still new to PHP and mySQL and maybe in time I'll see it your way. – Mark Rummel Nov 25 '11 at 18:22.

In the WHERE clause of your query try removing the quotes around order and use back ticks instead like this: `order`='$nextPageOrder' And try to avoid using keywords for table/column names! Been there.

1 I have to have the quotes around order or else I get an error. I think because it reads it as order as in ORDER BY. – Mark Rummel Nov 25 '11 at 18:01 1 @MarkRummel you then need backticks, not quotes – Damien Pirsy Nov 25 '11 at 18:06 added the back ticks.

– Aditya Naidu Nov 25 '11 at 18:09 Thanks for your answer. The backticks are correct, but I had to remove the single quotes to get it to work. – Mark Rummel Nov 25 '11 at 18:19.

You are overwriting the variable for each record, maybe create an array like.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions