Jump to content

Array in mysql query


dk4210

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.