Jump to content

script is working but output has problem


plodos

Recommended Posts

<?php
$q = "select * from research_field order by id asc";
$query = mysql_query($q);
while ($row = mysql_fetch_array($query)) {
$opstr ="
<table border='0' width='100%' id='table3'>
    <tr>
	<td><input type='checkbox' name='state[]' value='{$row['id']}'>{$row['field']}</td>
	<td><input type='checkbox' name='state[]' value='{$row['id']}'>{$row['field']}</td>
</tr>
<table>
";
echo $opstr;	
}
?>

output is like that because i used $row['id'] and $row['field']  two times

aaaa aaaaa

bbbb bbbbb

ccccc ccccccc

dddd ddddd

 

but i want to seperate with two colums like

aaaa bbbb

ccccc dddd

 

how can I get the next $row['id'] value ?

<td><input type='checkbox' name='state[]' value='{$row['id']}'>{$row['field']}</td>
	<td><input type='checkbox' name='state[]' value='{$row['id++']}'>{$row['field++']}</td>

Untested but try this

<?php
$q = "select * from research_field order by id asc";
$query = mysql_query($q);
echo "<table border='0' width='100%' id='table3'><tr>";
$rows = 2;
$row=1;
while ($row = mysql_fetch_array($query))
{
$opstr ="<td><input type='checkbox' name='state[]' value='{$row['id']}'>{$row['field']}</td>";
if($row==$rows)
{
	$row=0;
	echo "</tr><tr>$opstr";
}else{
	$row++;
	echo $opstr;
}
}
echo "</tr></table>";
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.