PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I am trying to pull in a dynamic list from MySQL (which works fine) and then use a stored array to hilight certain values as "selected". (does not work as written) It does not give me an error either, so it is obviously not syntax, just "ignored".
Here is the full clip from my form, $prod_set is my array:
the whole selection does not work or is there no element selected?
if you open the generated document in your browser's source view is there an <option> having the property SELECTED?
do {
if (in_array($row_rsProdsї'products_id'], $prod_set)) {
echo "equal: row_rsProdsї'products_id'] is -$row_rsProdsї'products_id']- and prod_set is -$prod_set-<br>";
} else {
echo "not equal: row_rsProdsї'products_id'] is -$row_rsProdsї'products_id']- and prod_set is -$prod_set-<br>";
}
} while ($row_rsProds = mysql_fetch_assoc($rsProds));
so you see wheter it is a syntax error or if something else is mixed up
<td>
<select name="prod_id[]" size="1" multiple id="prod_id[]">
<?php
// you can simplify the code by using a while loop instead of
// a do...while loop
while ($row_rsProds = mysql_fetch_assoc($rsProds)) {
// for debugging it may be useful to do a couple of print_r()s:
echo '<pre>$row_rsProds: ';
print_r($row_rsProds);
echo '</pre>';
echo '<pre>$prod_set: ';
print_r($prod_set);
echo '</pre>';
if (in_array($row_rsProds['products_id'], $prod_set)) {
// you need to concenate the code a bit better and remember
// you can't have double quotes within a double quoted string -
// you could escape them or, as below, use single quotes around
// the string instead.
echo '<option value="'.$row_rsProds['products_id'].'" selected="selected">'. $row_rsProds['products_name'] .'</option>';
} else {
echo '<option value="'.$row_rsProds['products_id'].'">'. $row_rsProds['products_name'] .'</option>';
}
}
// What are you trying to do with the rows below as they could
// probably be safely deleted.
/*
$rows = mysql_num_rows($rsProds);
if($rows > 0) {
mysql_data_seek($rsProds, 0);
$row_rsProds = mysql_fetch_assoc($rsProds);
}
*/
?>
</select>
</td>
Excellent. Thanks.
Although the code still does not work, I think that I can figure it out from here. Plus, I have some reading to do on concat!
It seems as though something in the above is breaking my html because I don't get any php errors, I just get blank page. no html.
I have been commenting/uncommenting by line to see where the error is and haven't been able to track it down. It works without the code in the select tags. I'll have to stare at it for an hour and perhaps the flaw will reveal itself.
check whether you closed all tags. use rights mouse click to view the html source on the php site. try to give the select thing another name, maybe the brackets are the problem.
if you view the sourcecode of the site in your browser, copy the html to a file and have it checked by w3c.
Thing is, there is no HTML to look at. The page is blank when this code is in the select statement.
So, it's almost as if there is a tag that throws an errant TD tag and then the table disappears. But, I took it out of the table entirely and it still goes away.