...

View Full Version : How to query text field from mysql



jlsohio
02-19-2006, 04:36 PM
I have the following code in one of my php files to pull from mysql database:

$result = mysql_query("SELECT DATE_FORMAT(date, '%m-%d-%y') AS formattedDate , track, horse, price FROM claimers where track_code =1 ORDER BY date DESC");

It works fine, when the database field is an integer.

The problem I'm having is when the database field is a CHAR field. I don't know how to use the where clause?

Thanks.

jls

Jak-S
02-19-2006, 04:55 PM
if the track_code field was a CHAR field then you would need to wrap the value in single quotes, like this:


$result = mysql_query("SELECT DATE_FORMAT(date, '%m-%d-%y') AS formattedDate , track, horse, price FROM claimers where track_code = '1' ORDER BY date DESC");

Should work.

jlsohio
02-19-2006, 06:54 PM
OK, I tried it, but it didn't work. I got this error message: (note I changed the field name from above example)

Parse error: parse error, unexpected T_STRING

Here's my line of php code:

$result = @mysql_query('SELECT horse, farm, state, earnings, age, time, fee FROM 2006_stallion_fees where gait= 'P' ORDER BY fee DESC limit 35');

The database field "gait" is a char(1)

Thanks again.

Jak-S
02-19-2006, 08:05 PM
Oh, sorry, my mistake, i forgot to escape the quatation marks. Either wrap the entire query in double quatation marks and leave the single ones as they are, like this:



$result = @mysql_query("SELECT horse, farm, state, earnings, age, time, fee FROM 2006_stallion_fees where gait= 'P' ORDER BY fee DESC limit 35");


Or leave the query wrapped in single quatation marks and escape the ones within the string, like this:


$result = @mysql_query('SELECT horse, farm, state, earnings, age, time, fee FROM 2006_stallion_fees where gait= \'P\' ORDER BY fee DESC limit 35');

I personally prefer the first method.

jlsohio
02-19-2006, 08:27 PM
Yep, that was it. Thanks for helping me.

jls



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum