refiking Posted January 20, 2008 Share Posted January 20, 2008 I want to run a query on the db based on the first letter of the event_id. How can I use an if statement based on the first letter of the event_id? Here is the code that I have so far: $event_id = $_GET['event']; $s1 = "INSERT INTO Pending(user_id,event_id)VALUES('$user','$event_id')"; mysql_query($s1) or die; //IF ($event_id starts with T) { //blah blah blah Quote Link to comment https://forums.phpfreaks.com/topic/86865-solved-help-with-if-statement/ Share on other sites More sharing options...
KrisNz Posted January 20, 2008 Share Posted January 20, 2008 You can treate strings as arrays so if ($event_id[0] == 'T') { .... Quote Link to comment https://forums.phpfreaks.com/topic/86865-solved-help-with-if-statement/#findComment-444050 Share on other sites More sharing options...
refiking Posted January 20, 2008 Author Share Posted January 20, 2008 Couple Questions.... 1) Does it matter that I already have the event_id from the $_GET function? 2) Does it matter that the event_id is more than just the letter T? Thanks for your explanation in advance! Quote Link to comment https://forums.phpfreaks.com/topic/86865-solved-help-with-if-statement/#findComment-444053 Share on other sites More sharing options...
KrisNz Posted January 20, 2008 Share Posted January 20, 2008 1) No. 2) Yes, in that case you'll need to use strpos() e.g if (strpos($event_id,"foo") === 0 ) { //does event id begin with "foo"... Quote Link to comment https://forums.phpfreaks.com/topic/86865-solved-help-with-if-statement/#findComment-444056 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.