PDA

View Full Version : mysql query help needed


Miran
9-27-05, 04:23 PM
Ok, so my problem is following.
I'm trying to get data out of a mysql database but have an problem with it (more explanation after the code)

for ($letter=65 ; $letter<=90 ; $letter++) {
$query = "SELECT * FROM books WHERE Title >= \"".chr($letter)."\" AND Title < \"".chr($letter+1)."\" ORDER BY Ime ASC";

there is more of the code but i dont think it's relevant to my problem.
The problem is that this way of querying mysql database works excellent for all letters except letter Z. If there is any record in database he just ignores it, doesnt recognize it or whatever (tested with a Z letter record in the actual database).
The code works excellent on my localhost but after placing it on my account, cant get data startin with the letter Z out of the table

All help is most needed, thanks!

Miran

mitchind
9-27-05, 06:08 PM
Ok, so my problem is following.
for ($letter=65 ; $letter<=90 ; $letter++) {
$query = "SELECT * FROM books WHERE Title >= \"".chr($letter)."\" AND Title < \"".chr($letter+1)."\" ORDER BY Ime ASC";

Miran

Since it's strings you're dealing with, why not just use the LIKE operator.

$query = "SELECT * FROM books WHERE Title LIKE \"" . chr($letter) . "\*\" ORDER BY Ime ASC";

Miran
9-28-05, 05:55 AM
Mitchind thanx for tryin to help but the line u gave me doesn't return any record from mysql. Dont really know why, but I identified my problem in my code.
U'll probably find this very unlikely but it works. The problem is that a query to mysql database didn't return any results when i tried to compare it with the letter Z cause somehow if the record in mysql starts with a Z when you query database he identifies that letter as this letter ^ or ASCII 94 and doesnt return result.
Anyway thanks for tryin to help, it's most appreciated.

omega-systems
9-28-05, 08:16 AM
Use this statement:
$query = "SELECT * FROM pet WHERE name LIKE \'".$letter($letter)."%\' ORDER BY Ime ASC";
Also i may not use php chr-function at all.