Lodius2000 Posted October 9, 2008 Share Posted October 9, 2008 so making a display of all rows in the db for my blog, one of the <td>'s is called live, it should have a form inside with a select menu, with yes or no as the values (i am aware that there is no submit button but i will js it in later) either way i am getting a weird format to my forms here is the relevant code <?php $list = $db->getAll('SELECT article_id, live, username, email, article_title, article, timestamp FROM text_cms ORDER BY article_id DESC '); //make the array of live options, yes and no $live = array('yes' => 1, 'no' => 0); if ($_POST['_submit_check']){ $defaults = $_POST; } else { $defaults = array('live' => $row['live']); } foreach ($list as $row) { $lastRowNumber++; $i = $row[article_id]; print '<tr class="' . $styles[$i % 2] .'"><td><a href="../editform/index.php?id=' . $row[article_id] .'">' . $row[article_id] .'</td> <td> <form method="POST" action="'.htmlentities($_SERVER['PHP_SELF']).'">'. input_select($row['article_id'], $defaults, $live).' <input type="hidden" name="_submit_check" value="1" /> </form> </td> <td><a href="../editform/index.php?id=' . $row[article_id] .'">' . stripslashes($row[article_title]) . '</td> <td>' . $row[timestamp] . '</td> <td style="text-align:center;"> <img src="../images/rex.png"></td></tr>'; print "\n"; } ?> and input_select defined <?php //print a select menu function input_select($element_name, $selected, $options, $multiple = false){ //print out the <select> tag print '<select name="' . $element_name; // if multiple choices are permitted, add the multiple attribute // and add a [] to the end of the tag name if ($multiple){ print '[]" multiple="multiple'; } print '">'; //set up the list of things to be selected $selected_options = array(); if ($multiple) { foreach ($selected[$element_name] as $val){ $selected_options[$val] = true; } } else { $selected_options[ $selected[$element_name] ] = true; } //print out the <option> tags foreach ($options as $option=>$label) { print '<option value="' . htmlentities($option) . '"'; if ($selected_options[$option]){ print ' selected="selected"'; } print '>' . htmlentities($label) . '</option>'; } print '</select>'; } ?> the attached jpg is how things are displaying (blurred the article title's to protect my privacy) any help would be appreciated thanks [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
CroNiX Posted October 9, 2008 Share Posted October 9, 2008 Don't know if this has anything to do with it, but you have 2 anchor tags that you don't close. Quote Link to comment Share on other sites More sharing options...
Lodius2000 Posted October 9, 2008 Author Share Posted October 9, 2008 I did close those but still have the same problem, but thanks for the good spot anyone else with help? thanks Quote Link to comment Share on other sites More sharing options...
AndyB Posted October 9, 2008 Share Posted October 9, 2008 Have you inspected the generated HTML code? It will show you the result of the problem, and that should help you find the cause. Quote Link to comment Share on other sites More sharing options...
Lodius2000 Posted October 9, 2008 Author Share Posted October 9, 2008 so here is a sampling, it goes on in the same format for each entry until the </table> tag <a href="../articleform/index.php">Create an Article</a> <table> <tr class='even-row'> <th><strong>ID</strong></th> <th><strong>Live</strong></th> <th><strong>Article Title</strong></th> <th><strong>Timestamp</strong></th> <th><strong>DELETE</strong></th> </tr> <select name="45"><option value="0">no</option><option value="1">yes</option></select><tr class="odd-row"><td><a href="../editform/index.php?id=45">45</a></td> <td> <form method="POST" action="/0/admin/managearticle/index2.php"> <input type="hidden" name="_submit_check" value="1" /> </form> </td> <td><a href="../editform/index.php?id=45">article title here</a></td> <td>2008-10-07 18:14:00</td> <td style="text-align:center;"> <img src="../images/rex.png"></td></tr> so why is it putting the forms out of the table when my php clearly puts the forms in the table Quote Link to comment Share on other sites More sharing options...
dropfaith Posted October 9, 2008 Share Posted October 9, 2008 your code doesnt clearly put it there inside of a table all elements need to be inside tds or ths <select name="45"><option value="0">no</option><option value="1">yes</option></select> your select is outside all elements of a row Quote Link to comment Share on other sites More sharing options...
Lodius2000 Posted October 9, 2008 Author Share Posted October 9, 2008 drop, thats what I dont get the php print '<tr class="' . $styles[$i % 2] .'"><td><a href="../editform/index.php?id=' . $row[article_id] .'">' . $row[article_id] .'</a></td> <td> <form method="POST" action="'.htmlentities($_SERVER['PHP_SELF']).'">'. input_select($row['article_id'], $defaults, $live).' <input type="hidden" name="_submit_check" value="1" /> </form> </td> <td><a href="../editform/index.php?id=' . $row[article_id] .'">' . stripslashes($row[article_title]) . '</a></td> <td>' . $row[timestamp] . '</td> <td style="text-align:center;"> <img src="../images/rex.png"></td></tr>'; makes this the html <select name="45"><option value="0">no</option><option value="1">yes</option></select><tr class="odd-row"><td><a href="../editform/index.php?id=45">45</a></td> <td> <form method="POST" action="/0/admin/managearticle/index2.php"> <input type="hidden" name="_submit_check" value="1" /> </form> </td> <td><a href="../editform/index.php?id=45">article title here</a></td> <td>2008-10-07 18:14:00</td> <td style="text-align:center;"> <img src="../images/rex.png"></td></tr> and the two things are not in the same order, its odd Quote Link to comment Share on other sites More sharing options...
AndyB Posted October 10, 2008 Share Posted October 10, 2008 Are you 100% sure that the script you think you're using is what's on your server? Quote Link to comment Share on other sites More sharing options...
Lodius2000 Posted October 10, 2008 Author Share Posted October 10, 2008 absolutely, everytime i make a change i re-upload it Quote Link to comment Share on other sites More sharing options...
AndyB Posted October 10, 2008 Share Posted October 10, 2008 Then input_select($row['article_id'], $defaults, $live) must be doing some really creative stuff (including generating code that jumps out of where it belongs). I'm skeptical that your posted code produces the output you claim, because that just doen't seem rational. If you echo something between TD tags, that's where it stays. Quote Link to comment Share on other sites More sharing options...
Lodius2000 Posted October 10, 2008 Author Share Posted October 10, 2008 do you think it could be that $live = array('yes' => 1, 'no' => 0); if ($_POST['_submit_check']){ $defaults = $_POST; } else { $defaults = array('live' => $row['live']); } is out of the foreach loop, I dont think thats it but.... i change it to be in the loop and i still get the same results Quote Link to comment Share on other sites More sharing options...
AndyB Posted October 10, 2008 Share Posted October 10, 2008 if ($_POST['_submit_check']){ $defaults = $_POST; // this makes no sense Quote Link to comment 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.