Jump to content

Confusing Layout for a Selection List help


ciber

Recommended Posts

OK hopefully this makes sense

I have a mysql table, which has an id, an a category name.

My product table has its information, and a category id.

 

Now my problem, when I am editing a product, I want the category to be selected. How do I get php to echo all the items in the category, but get it to also add the selected attribute to the item which is selected in the products database

 

Thanks

Make a function to display it and pass the variable to it. Here is one I wrote to select formats for an old project

function formats($val=""){
    echo "<select name='formats' class='vshort'>\n<option value='0' rel='none'>Format</option>\n";
    $c_q = @debug_mysql_query("SELECT format_id, format_name, format_rel FROM album_format");
    while($c = mysql_fetch_array($c_q)){
        $cid = $c["format_id"];
        $name = htmlize($c["format_name"]);
        $selected = ($cid == $val)?"selected":"";
        echo "<option $selected value='$cid' rel='" . $c[format_rel] . "'>$name</option>\n";}
    echo "</select>";
}

 

Theres some functions in there you will need to change but hopefully it gives you an idea.

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.