SpireLink Posted August 18, 2007 Share Posted August 18, 2007 Hi, I have made a script to edit an article in a list, the thing thet the article category (Author Name) is brought from another table, and to modify the data I get the catigories list from that table and list it all , i want to make the current value selected.. <table border='0' width='100%'> <form name='edit_news' method='post' action='base.php?crl=article_edit.php'> <tr> <td align='right'><b>Title:</b> </td> <td align='right'><input name='title' type='text' value='<? echo "$title"; ?>' > </td> </tr> <tr> <td align='right' valign='top'><b>intro :</b> </td> <td align='right'><textarea rows='5' cols='60' name='intro'><? echo $intro ?></textarea> </td> </tr> <tr> <td align='right' valign='top'><b>Article :</b> </td> <td align='right'><textarea rows='30' cols='60' name='article'><? echo $article ?></textarea> </td> </tr> <tr><td align='right'><b>Author :</b></td> <td align='right'> <select name='category'> <? $artcat = mysql_query("SELECT * FROM artcat ORDER BY id DESC",$db); while ($artcat_data = mysql_fetch_array($artcat)) { $artcat_id=$artcat_data["id"]; $artcat_title=$artcat_data["title"]; ?> <option value='<? echo "$artcat_id"; ?>'><? echo "$artcat_title"; ?></option> <? } ?> </select> </td></tr> <tr><td align='right'></td><td align='right'><input name='id' type="hidden" value='<? echo "$id"; ?>'></td></tr> <tr><td align='left'><input type='submit' name='submit' value='Update'></td><td align='right'></td></tr> </form> </table> Link to comment https://forums.phpfreaks.com/topic/65616-select-with-php/ Share on other sites More sharing options...
js_280 Posted August 19, 2007 Share Posted August 19, 2007 When you select the title, intro and article I assume that you are pulling them from a database table and I assume you have the current category stored there as well. If so, I would try something like this... (assume $category is the current category id pulled from your database) <select name='category'> <? $artcat = mysql_query("SELECT * FROM artcat ORDER BY id DESC",$db); while ($artcat_data = mysql_fetch_array($artcat)) { $artcat_id=$artcat_data["id"]; $artcat_title=$artcat_data["title"]; if($artcat_id = $category) { echo('<option value="'.$artcat_id.'" selected="selected">'.$artcat_title.'</option>'); } else { echo('<option value="'.$artcat_id.'">'.$artcat_title.'</option>'); } } ?> </select> Link to comment https://forums.phpfreaks.com/topic/65616-select-with-php/#findComment-327854 Share on other sites More sharing options...
js_280 Posted August 19, 2007 Share Posted August 19, 2007 Ooops... make that <select name='category'> <? $artcat = mysql_query("SELECT * FROM artcat ORDER BY id DESC",$db); while ($artcat_data = mysql_fetch_array($artcat)) { $artcat_id=$artcat_data["id"]; $artcat_title=$artcat_data["title"]; if($artcat_id == $category) { echo('<option value="'.$artcat_id.'" selected="selected">'.$artcat_title.'</option>'); } else { echo('<option value="'.$artcat_id.'">'.$artcat_title.'</option>'); } } ?> </select> Link to comment https://forums.phpfreaks.com/topic/65616-select-with-php/#findComment-328292 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.