[RESOLVED]How to display data in two columns?
Hi all,
I'm creating a page where I have to take data from mysql db
and display it on page.
Data should display in two columns.
But using while{} I can display data in one column only.
here, i'm giving code
PHP Code:
<table align="center">
<tr>
<td colspan="2" align="center"><font class="txtSecHdr">
Select Menu</font></td>
</tr>
<? $disp="select m_id, menu_name from admin_menu where m_id='0' order by id";
$result=mysql_query($disp,$conn);
if(mysql_num_rows($result)){
while($row=mysql_fetch_array($result)){
?>
<tr>
<td colspan="2"><input type="checkbox" name="chk" value="<?=$row['id']?>"> <?=$row['menu_name']?></td>
</tr>
<?}
}?>
</table>
In above code i'm displaying Menu list from table. How to display these menus in two columns?
Re: How to display data in two columns?
PHP Code:
<table align="center">
<tr>
<td colspan="2" align="center"><font class="txtSecHdr">
Select Menu</font></td>
</tr>
<? $disp="select m_id, menu_name from admin_menu where m_id='0' order by id";
$result=mysql_query($disp,$conn);
if(mysql_num_rows($result)){
while($row=mysql_fetch_array($result)){
?>
<tr>
<td colspan="2"><input type="checkbox" name="chk" value="<?=$row['id']?>"></td><td><?=$row['m_name']?></td>
</tr>
<?}
}?>
</table>
*edit* apparently bold doesn't work in a php tag. You should be able to see the difference.
or am I missing something? You're only using one column in your code..so why not use two?
Re: How to display data in two columns?
Let me explain you.
See I have table called 'admin_menu'
this table has column named 'menu_name'
this column contains data like
1. Registration
2.Shopping
3.Sales
4.Marketing
now, I have to take these values from table and display it on page with checkboxes like
(i.e. result page should look like)
Select Menu
1.Registration 2. Shopping
3.Sales 4.Marketing
But i'm able to display data in one column only. within while{} I can create one column only.if I create one more column within while{}, data would be repeated..my question was how to display data of 'menu_name' field in two columns?
Re: How to display data in two columns?
So you want to split the output from menu_name from being "1. Registration" as 1 variable, to having "1." as one variable and "Registration" as another, so you can put them in columns?
If that is correct, you should look into the split function.
Re: How to display data in two columns?
No dear,
ignore those numbering. Only menu names should display in two columns
Re: How to display data in two columns?
PHP Code:
<?php
mysql_connect('localhost', 'test', 'password');
mysql_select_db('test');
$result = mysql_query("select path from menus");
echo "<table><tr>";
$count = 1;
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
extract($row);
echo "<td>MENU ITEM HERE</td>";
if ($count++ % 2 == 0) {
echo "</tr><tr>";
}
}
echo "</tr></table>";
?>
What that code will do is create a new row everytime it hits 2 columns. Good Luck :wave:
Re: How to display data in two columns?
Oh my god!!!
it was so simple!!!! :p
thanks dclamp!!!
Re: [RESOLVED]How to display data in two columns?