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!
Moderator: General Moderators
nite4000
Forum Contributor
Posts: 209 Joined: Sun Apr 12, 2009 11:31 am
Post
by nite4000 » Mon Jun 08, 2009 2:32 pm
I am trying to make a drop box list the choices i have in a table which is "Active" and "Suspended" which is in the acc_status table now in the Users table i have a field "status" which is where the choice is save but i have been unable to get it to list and update the users table.
this is what i have
Code: Select all
<select name="acctstatus" id="acctstatus">
<?php
$res = mysql_query("SELECT * FROM acc_status") or die("<option>Unable to get departments!</option>");
while($acc = mysql_fetch_array($res, MYSQL_ASSOC)) { ?>
<option value="<?php echo $acc['id']; ?>" <?php if(intval($edit['id']) == intval($acc['id'])) { echo 'selected="selected"'; } ?>><?php echo $acc['level']; ?></option>
<?php } ?>
</select>
the edit['id'] is selecting from the users but dont think i am selecting right
Code: Select all
$r = mysql_query("SELECT * FROM Users WHERE status=$acc['leve'] LIMIT 1 ") or die(mysql_error());
$edit = mysql_fetch_array($r, MYSQL_ASSOC);
@mysql_free_result($r);
Any help you can give me would be helpful
Thanks
Last edited by
Benjamin on Mon Jun 08, 2009 2:43 pm, edited 1 time in total.
Reason: Added [code=php] tags.
califdon
Jack of Zircons
Posts: 4484 Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA
Post
by califdon » Mon Jun 08, 2009 10:36 pm
Personally, I'd code it like this:
Code: Select all
<select name="acctstatus" id="acctstatus">
<?php
$res = mysql_query("SELECT * FROM acc_status") or die(mysql_error());
while($acc = mysql_fetch_assoc($res, MYSQL_ASSOC)) {
extract($acc);
echo "<option value='$id'";
if(intval($edit['id']) == intval($id)) echo " selected";
echo "> $level</option>";
}
?>
</select>
In your second query, is `status` a numeric field? If not, you need some quotes.