dk4210 Posted January 13, 2012 Share Posted January 13, 2012 Hello guys, Got a question here.. If I have a database table called features with the following columns with example f_id | f_name | f_status 1 | deck | 1 2 | Fireplace | 1 3 | Alarm | 1 I have another table another table called ads that has a column called features and it has the following 1,2,3 (for example) I want to be able to query the db and display all the f_name. Here is what I have so far but it's not working and need some help // Query the ads table $result3 = mysql_query("SELECT * FROM ads WHERE ad_id='$id2'") or die(mysql_error()); $row3 = mysql_fetch_array( $result3 ); $features = $row3['features']; echo'This is the features ' . $features .''; $feature2 = explode(",", $features); print_r($feature2); echo "test" . $feature2[0]; // piece1 echo $feature2[1]; // piece2 $result = mysql_query("SELECT * FROM features WHERE f_id=$feature2[1]") or die("Sql error : " . mysql_error()); while($row = mysql_fetch_assoc ($result)){ $f_name=$row["f_name"]; echo $f_name; } Link to comment https://forums.phpfreaks.com/topic/254974-array-in-mysql-query/ Share on other sites More sharing options...
Muddy_Funster Posted January 13, 2012 Share Posted January 13, 2012 A single query should save you some head ache SELECT * FROM table1 LEFT JOIN table2 ON (table1.f_id = table2.f_id) Link to comment https://forums.phpfreaks.com/topic/254974-array-in-mysql-query/#findComment-1307364 Share on other sites More sharing options...
dk4210 Posted January 13, 2012 Author Share Posted January 13, 2012 Ok what next? Link to comment https://forums.phpfreaks.com/topic/254974-array-in-mysql-query/#findComment-1307376 Share on other sites More sharing options...
sasa Posted January 14, 2012 Share Posted January 14, 2012 try SELECT * FROM ads LEFT JOIN features ON FIND_IN_SET(features.f_id,ads.features) WHERE ads.id='$id2'[/ code]on phpMyAdmin Link to comment https://forums.phpfreaks.com/topic/254974-array-in-mysql-query/#findComment-1307497 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.