I am having trouble displaying the item listed in my drop box. It is not showing up anything. The list is blank. I don't know what the problem is. At first I thought it was because of an undefine varialbe, but thanks to Keith help with the undefine variable issue, I learned that was not the reason my list is not displaying.

May someone please help me solve this headache.
thanks

<?php
// manage colors
// pull associated color/products and display them
// give ability to delete associations and add


// Remove association 
if(isset($_POST['submit']) && isset($_POST['attid'])){
    $q = 'DELETE FROM color_list_attribute WHERE attributeid='.$_POST['attid'];
    $r = mysql_query($q);
    if($r !== false) echo '<h2>Color Product Association removed.</h2><br><br><br>';
}
// Add new color
if(isset($_POST['submit']) && isset($_POST['color'])){
    $r =mysql_query('INSERT INTO color_list VALUES ("","'.$_POST['color'].'")');
    if($r !== false) echo '<h2>New Color Added</h2><br><br><br>';
}
// Make association
if(isset($_POST['submit']) && isset($_POST['colorid'])){
    $r= mysql_query('INSERT INTO color_list_attribute VALUES ("",'.$_POST['colorid'].','.$_POST['productid'].')');
    if($r !== false) echo '<h2>Color Product Association Complete.</h2><br><br><br>';
}

// Display add new color
echo '<h2>Add new color</h2>';
?>
<form action="?content=colors" method="post">
    <b>Color Name</b><input type="text" name="color" value=""><input type="submit" name="submit" value="Add Color">
</form>
<?php

// Display add color asccoiation
$q = 'SELECT description,prodid FROM products';
$r = mysql_query($q);
$prod_options = '';
while($row = mysql_fetch_array($r))
    $prod_options .= '<option value="'.$row['prodid'].'">'.$row['description'].'</option>';

$q = 'SELECT item_color,colorid FROM color_list';
$r = mysql_query($q);
$color_options = '';
while($row = mysql_fetch_array($r))
    $color_options .= '<option value="'.$row['colorid'].'">'.$row['item_color'].'</option>';
?>
<br>
<h2>Color Product Associate</h2>
<form action="?content=colors" method="post">
<b>Product</b>&nbsp;<select name="productid"><?=$prod_options;?></select>
<br>
<b>Color&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b><select name="colorid"><?=$color_options;?></select> 
<br><input type="submit" name="submit" value="Associate">
</form>
<?php

// Display associations
$q = 'SELECT p.description, c.item_color, cp.attributeid FROM products p, color_list_attribute cp, color_list c WHERE cp.prodid = p.prodid AND cp.colorid = c.colorid ORDER BY p.description';
$r = mysql_query($q);
echo '<h2>Product Color Associations</h2>';
echo '<table><tr><td>Product</td><td>Color</td><td>&nbsp;</td></tr>';
while($row = mysql_fetch_array($r)){
    echo '<tr><td>'.$row['description'].'</td><td>'.$row['item_color'].'</td><td><form action="?content=colors" method="post"><input type="hidden" name="attid" value="'.$row['attributeid'].'"><input type="submit" name="submit" value="Delete"></form></td></tr>';
}
echo '</table>';

incorrect code - will repost

would a foreach loop not be a better option?

<?php
    $sql = "SELECT p.description, c.item_color, cp.attributeid FROM products p, color_list_attribute cp, color_list c WHERE cp.prodid = p.prodid AND cp.colorid = c.colorid ORDER BY p.description";

    $result = mysql_query($sql);

    echo "<h2>Product Color Associations</h2>";
    echo "<table><tr><td>Product</td><td>Color</td><td>&nbsp;</td></tr>";

    foreach($rows as $row) {

	echo "<tr><td>".$row['description']."</td><td>".$row['item_color']."</td><td><form action=\"?content=colors\" method=\"post\"><input type=\"hidden\" name=\"attid\" value=\"".$row['attributeid']."\"><input type=\"submit\" name=\"submit\" value=\"Delete\"></form></td></tr>";


    }

    echo "</table>";
?>

i change all the single quotes to double quotes to double quotes as i have had issues in the past and diong it the hard way sometimes just works.

Thanks Leviathan, but thats not the problem. I do thank you for trying though. I am going to make the code shorter where the problem exactly is.

<?php
// manage colors
// pull associated color/products and display them
// give ability to delete associations and add


// Remove association 
if(isset($_POST['submit']) && isset($_POST['attid'])){
    $q = 'DELETE FROM color_list_attribute WHERE attributeid='.$_POST['attid'];
    $r = mysql_query($q);
    if($r !== false) echo '<h2>Color Product Association removed.</h2><br><br><br>';
}
// Add new color
if(isset($_POST['submit']) && isset($_POST['color'])){
    $r =mysql_query('INSERT INTO color_list VALUES ("","'.$_POST['color'].'")');
    if($r !== false) echo '<h2>New Color Added</h2><br><br><br>';
}
// Make association
if(isset($_POST['submit']) && isset($_POST['colorid'])){
    $r= mysql_query('INSERT INTO color_list_attribute VALUES ("",'.$_POST['colorid'].','.$_POST['productid'].')');
    if($r !== false) echo '<h2>Color Product Association Complete.</h2><br><br><br>';
}

// Display add new color
echo '<h2>Add new color</h2>';
?>
<form action="?content=colors" method="post">
    <b>Color Name</b><input type="text" name="color" value=""><input type="submit" name="submit" value="Add Color">
</form>
<?php

// Display add color asccoiation 
****This is the Select query to call to the database***
$q = 'SELECT description,prodid FROM products';
$r = mysql_query($q);
$prod_options = '';
while($row = mysql_fetch_array($r))
    $prod_options .= '<option value="'.$row['prodid'].'">'.$row['description'].'</option>';

$q = 'SELECT item_color,colorid FROM color_list';
$r = mysql_query($q);
$color_options = '';
while($row = mysql_fetch_array($r))
    $color_options .= '<option value="'.$row['colorid'].'">'.$row['item_color'].'</option>';
?>
<br>
<h2>Color Product Associate</h2> 
*******This is the code for the drop down box to list the items, this is where I hae the problem of it not displaying****
<form action="?content=colors" method="post"><b>Product</b>&nbsp;<select name="prodid"><?=$prod_options;?></select>
<br>
<b>Color&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b><select name="colorid"><?=$color_options;?></select> 
<br><input type="submit" name="submit" value="Associate">
</form>

Instead of <?=$prod_options;?> try <?php echo $prod_options; ?>

Thank you Keith, you are a life saver. I been tackling this problem since around 6am this morning. Now I can take a break for atleast an hour and tackle my other issues.
It is weird though, because I honestly tried to use echo but in the beginning of select name tag. Ofourse that did not work. But I am happy to see atleast I was thinking slightly on the right track. such a small code give me sucha a huge headache. Geesh and thanks a million. If you live in Oregon that would be too cool and if you have spare time. I am looking for a tutor to break down php to me in a way I can understand it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.