Log in

View Full Version : query not executing



boogyman
05-29-2007, 03:47 PM
I created a customized query to search through my database for a given range of numbers, however when I do it the general way it cannot execute


$query = mysqli_query($conn, "SELECT doc_id,ref_number,title,description FROM docs WHERE ref_number=DD%");
-or-

$query = mysqli_query($conn, "SELECT doc_id,ref_number,title,description FROM docs WHERE ref_number LIKE DD%");

however if I change the query to search for 1 document by the ID, it will execute correctly.

$query = mysqli_query($conn, "SELECT doc_id,ref_number,title,description FROM docs WHERE doc_id=680");


is this a possible INDEXing problem?

Note: doc_id is the primary key of the table, and ref_number indexed :| or so I thought

mbrodin
05-29-2007, 04:48 PM
Hi Boogyman!

When you seach without "LIKE" you cannot use %-sign, and you forgoted to add ' between LIKE DD% Set it to LIKE 'DD%'. See if this get the results as you want it!



$query = mysqli_query($conn, "SELECT doc_id,ref_number,title,description FROM docs WHERE ref_number LIKE 'DD%'");




$query = mysqli_query($conn, "SELECT doc_id,ref_number,title,description FROM docs WHERE ref_number=DD");


Best regards,
mbrodin

boogyman
05-29-2007, 04:52 PM
you forgoted to add ' between LIKE DD% Set it to LIKE 'DD%'. See if this get the results as you want it!


ahh, the joys of minute character flaws :) Thanks Mate, that did do the trick

mbrodin
05-29-2007, 05:23 PM
ahh, the joys of minute character flaws :) Thanks Mate, that did do the trick

Great! Always nice to help! ;)

Best regards,
mbrodin