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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.