Searching index of table

Codes here !

Moderators: egami, macek, gesf

Post Reply
User avatar
Nullsig
php-forum Fan User
php-forum Fan User
Posts: 979
Joined: Thu Feb 17, 2011 6:52 am
Location: Racine, WI

Wed May 30, 2012 7:36 am

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.

User avatar
Nullsig
php-forum Fan User
php-forum Fan User
Posts: 979
Joined: Thu Feb 17, 2011 6:52 am
Location: Racine, WI

Wed May 30, 2012 8:09 am

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.

Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 1 guest