Searching index of table

  • Thread starter Thread starter Anonymous
  • Start date Start date
A

Anonymous

Guest
Seems like your query is failing. More than likely the table you are accessing doesn't have a field named "index" when you put single quotes around "index" you changed the meaning of the query so it stopped failing but still returned no results.

I will explain why.

Your initial query:
"SELECT * FROM children WHERE index = $kknumber"

Translates to:
Select all fields in the table "children" where the field with name "index" is equal to the value of $kknumber


Your other query
"SELECT * FROM children WHERE 'index' = $kknumber";

Translates to:
Select all fields in the table children when the word 'index' is equal to the value of $kknumber

Your second query doesn't consider any of the table data in the WHERE clause. Since I assume $kknumber is an integer (or float) value it will never be equal to the string of "index" so your query resolves as false and returns 0 rows.


You need to make sure your query works. You should test it in mysql command shell or in PHPMyAdmin to see what the error is.
 
It's based on the data type of the field you are comparing. In general you should always have the single quotes around the comparator.

One of the reasons for this is dealing with SQL injection. The other reason is that for most people it is easier to just put single quotes on everything than to learn what does and does not need the quotes.
 
Back
Top