jealy Posted August 30, 2008 Share Posted August 30, 2008 Hey guys. I'm trying to make a simple page that will query a mysql table for names of movies. I have most of it done however when you click on the letter, it shows all of the results with the letter in the name, I want it to show results that BEGIN with the letter, it's hard to explain but... http://camo.jealy.co.uk = the page Here's the line; $sql="SELECT Name FROM films WHERE Name LIKE '%" . $letter . "%'"; I just pretty much need to know the syntax or whatever they're called to find it if it begins with the $letter, instead of if it's "LIKE" it. Quote Link to comment Share on other sites More sharing options...
toplay Posted August 30, 2008 Share Posted August 30, 2008 Changing this part: LIKE '%" . $letter . "%'" to this: LIKE $letter . "%'" will find everything starting with whatever $letter value is. Quote Link to comment Share on other sites More sharing options...
jealy Posted August 30, 2008 Author Share Posted August 30, 2008 Thanks for your reply. I tried that and got an error. Parse error: syntax error, unexpected T_VARIABLE On this line; $sql="SELECT Name FROM films WHERE Name LIKE "$letter"%'"; >.< Quote Link to comment Share on other sites More sharing options...
jealy Posted August 30, 2008 Author Share Posted August 30, 2008 Fiddling around with it a bit I got the errors to go away however the query isn't showing any results, nor mysql connection errors. $sql="SELECT Name FROM films WHERE Name LIKE " . $letter . "%'"; Quote Link to comment Share on other sites More sharing options...
fenway Posted August 30, 2008 Share Posted August 30, 2008 Could you echo sql? Quote Link to comment Share on other sites More sharing options...
jealy Posted August 30, 2008 Author Share Posted August 30, 2008 May sound noobish but how do I go about doing that? Quote Link to comment Share on other sites More sharing options...
fenway Posted August 30, 2008 Share Posted August 30, 2008 Echo the $sql variable in PHP... and I assume you're catching errors in mysql_query() and checking mysql_error(). Quote Link to comment Share on other sites More sharing options...
toplay Posted August 30, 2008 Share Posted August 30, 2008 $sql = "SELECT Name FROM films WHERE Name LIKE '$letter%' "; Quote Link to comment Share on other sites More sharing options...
jealy Posted August 30, 2008 Author Share Posted August 30, 2008 $sql = "SELECT Name FROM films WHERE Name LIKE '$letter%' "; Perfect, thanks. Quote Link to comment Share on other sites More sharing options...
jealy Posted August 30, 2008 Author Share Posted August 30, 2008 Okay, now i'm trying to add something into my database using PHP. I seem to be getting an error with this, anyone know what it is? $query="INSERT INTO films ("Name", "Genre", "Year") VALUES ('".$Name."', '".$Genre."', '".$Year."')"; Quote Link to comment Share on other sites More sharing options...
toplay Posted August 30, 2008 Share Posted August 30, 2008 Read up about using quotes in PHP (and MySQL). $query="INSERT INTO films (Name, Genre, Year) VALUES ('$Name', '$Genre', '$Year')"; Quote Link to comment Share on other sites More sharing options...
jealy Posted August 30, 2008 Author Share Posted August 30, 2008 I shall do, thanks again! Quote Link to comment 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.