Page 1 of 1

[SOLVED] adding a percent sign into the variable

Posted: Fri Mar 11, 2005 8:54 pm
by nhan
hope anyone can help me...

i have submitted a data using post and i just want to add a percent sign into that variable, how can i add that to the query? thanks! below are my code..

Code: Select all

$date1 = $_POSTї'date1'];

// i just want to add a percent sign at the end of the value of date 1
so that i can do this query...

select * from tbl where userName = '$select' and date like '$date1'

//which would appear something like this one:
select * from tbl where userName = 'name' and date like '03-05-05%'

//where name and 03-05-05 are submitted from a form
how would i do that adding the percent sign in the end?

thanks!

Posted: Fri Mar 11, 2005 8:55 pm
by smpdawg

Code: Select all

select * from tbl where userName = '{$select}' and date like '{$date1}%'

Posted: Fri Mar 11, 2005 9:23 pm
by Ambush Commander
When handling strings, you have a handy "String Cocatenation Operator", your friendly period.

If $datel is your variable, then:

Code: Select all

$datel = $datel."%";
//or
$datel .= "%";
Adds a Percent to the end.

adding a percent sign into the variable

Posted: Fri Mar 11, 2005 9:32 pm
by nhan
swamps code is working but it seem that i had an error on the query...

Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /usr/local/apache/login/user.php on line 24

Code: Select all

$query = &quote;select * from tbl where userName = '$select' and date like '{$date1}%'&quote;;
$result = mysql_query($query); 
$total_rows = mysql_num_rows($result); 
if (!$total_rows) { .....

line 24 is $total_rows = mysql_num_rows($result);

any idea? thanks!

Posted: Fri Mar 11, 2005 9:39 pm
by infolock
try :

Code: Select all

$result = mysql_query($query) or die(MySQL_Error());
adding the " or die ... " clause will present you with the actual error you have in your query... very good idea to use it whenever you are gonna query just about anything ;)

Posted: Fri Mar 11, 2005 9:45 pm
by nhan
thaks so much everybody, i made some tweaks and its all ok....

thanks all!