Free Web Hosting Forum
Go Back   Free Web Hosting Forum > Website Building > Web Programming
Reload this Page dropdown variable default value inside a while
Reply
 
Thread Tools Display Modes
(#1 (permalink))
Old
Member
cbarg is on a distinguished road
 
Posts: 54
Join Date: Sep 2011
Default dropdown variable default value inside a while - 09-16-2011, 05:50 AM

ok, this is a better place to make my question:
I have this piece of code- basically is a select (dropdown menu) where the options are within a while sentence. Now I need to set one as default, but I can't figure out how to do it Here the code goes:

echo '<select name="topic_cat">';
while($row = mysql_fetch_assoc($result))
{
echo '<option value="' . $row['cat_id'] . '">' . $row['cat_name'] . '</option></select><br />';
}

and I want the selected (default) one to be called $topic_cat where cat_id = topic_cat

FYI this is part of editing a post which is already made.

Any idea?
Thanks!!
Reply With Quote
Sponsored Links
(#2 (permalink))
Old
Member
cbarg is on a distinguished road
 
Posts: 54
Join Date: Sep 2011
Default 09-16-2011, 06:10 AM

well, I fixed it :-)


echo '<select name="topic_cat">';
while($row = mysql_fetch_array($result))
{
echo '<option ';
if ($row['cat_id'] == $topic_cat)
{
echo 'selected="selected" ';
}
echo 'value=" '.$row['cat_id'].' "> '.$row['cat_name']. '</option>';
}
echo '</select>';
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Forum Jump



Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.5.2
vBulletin Skin developed by: vBStyles.com