Jump to content

putting forms inside <td></td>


Lodius2000

Recommended Posts

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]

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.