JSON-PHP/MySQL - Retrieving info from DB
I am using a JSON script ot print out a list of information (later it is sent to my iPhone application, all works fine on that end) with a specific value in a row in my table in my db.
I have managed to do this, however I am looking to expand my search results.
Working Code - obviously i setup
$link = mysql_connect ($host, $uid, $pwd) or die ("Could Not Connect");
mysql_select_db($db) or die("Could Not Connect to Database");
$arr = array();
$rs = mysql_query("SELECT id, story, releasedate, title, youtube, picture FROM movies WHERE category='Action'");
while($obj = mysql_fetch_object($rs)) {
$arr[] = $obj;
}
echo '{"users":'.json_encode($arr).'}';
I guess where line #4 is, at the end of tha开发者_运维知识库t, I would like to to do the following, but cannot find any sample code for it.
Example Code:
......from Movies WHERE category CONTAINS 'Action'");
that obviously does not work and I get an error, pretty much my category row has multiple values for movies, ie DRAMA,Action Sustepnse etc in one row, as some movies are a mix of categories now a days, and would like it filtered out properly without the hassle of adding addition category rows in my db
you can do this
this will select movies that belong to one of these genres
WHERE category IN ('action', 'horror', 'comedy')
but if you want to search if the category contains action or drama or horror you need
WHERE category LIKE '%Action%' OR category LIKE '%Drama%'...
精彩评论