peppericious Posted December 30, 2011 Share Posted December 30, 2011 I have a little blog which allows users reply to posts. Replies go into a 'replies' table, awaiting moderation. The table has a moderation_level column. Values in this column are 1, 2 or 3, denoting 'Queued', 'Accepted', 'Rejected', respectively. moderation_queue.php will display recent replies and allow me to alter the moderation_level value by clicking a radio button. Each reply on this page will have three radio buttons - 'Queued', 'Accepted' and 'Rejected' - one of which should be selected according to the current value of the moderation_level column in the db. (By default, all replies are initially assigned a value of '1'.) However I can't figure out how to have the appropriate radio button for each reply selected, or not, according to this value. Any help greated appreciated. Thanks in advance. Here's my code on moderation_queue.php: function get_replies_to_moderate() { global $dbc; $q = "SELECT id, f_blogpost_id, body, f_responder, DATE_FORMAT(created, '%Y') AS year, DATE_FORMAT(created, '%b') AS month, DATE_FORMAT(created, '%d') AS day, DATE_FORMAT(created, '%H:%i') AS time, moderation_level FROM blog_replies WHERE moderation_level = 1 ORDER BY id DESC"; $r = mysqli_query($dbc, $q); if (mysqli_num_rows($r) > 0) { while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { ?> <tr> <td><?php echo $row['id']; ?></td> <td><?php echo $row['f_blogpost_id']; ?></td> <td><?php echo $row['body']; ?></td> <td><?php echo $row['f_responder']; ?></td> <td><?php echo $row['time'] . ' ' . $row['day'] . ' ' . $row['month'] . ' ' . $row['year']; ?></td> <td> <label> <input name="moderation_level" type="radio" value="queued" <?php // not sure what to put here... ?> /> Queued</label> <label> <label> <input name="moderation_level" type="radio" value="accept" <?php // not sure what to put here... ?> /> Accepted</label> <label> <input name="moderation_level" type="radio" value="reject" <?php // not sure what to put here... ?> /> Rejected</label> </td> </tr> <?php } // close WHILE } // close if-posts-exist IF } Quote Link to comment https://forums.phpfreaks.com/topic/254095-how-to-display-radio-buttons-as-selected-according-to-value-in-db-column/ Share on other sites More sharing options...
SergeiSS Posted December 30, 2011 Share Posted December 30, 2011 I like to answer such questions - when TS does something and needs to clarify just a small part OK. Change this <?php // not sure what to put here... ?> to <?php if( any_condition ) echo 'selected="selected"'; ?> any_condition depends on information from DB (if you like to set the default value for radio - it seems it's your case) or from the $_POST or $_GET array (if this script depends on previous one). And of course just one condition must be true, for one radio from the set. Quote Link to comment https://forums.phpfreaks.com/topic/254095-how-to-display-radio-buttons-as-selected-according-to-value-in-db-column/#findComment-1302689 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.