|
-
Oct 24th, 2007, 04:07 AM
#1
Thread Starter
Lively Member
[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?
Last edited by rasana; Oct 26th, 2007 at 07:59 AM.
-
Oct 24th, 2007, 08:46 AM
#2
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?
-
Oct 25th, 2007, 12:11 AM
#3
Thread Starter
Lively Member
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?
-
Oct 25th, 2007, 10:05 AM
#4
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.
-
Oct 25th, 2007, 11:48 PM
#5
Thread Starter
Lively Member
Re: How to display data in two columns?
No dear,
ignore those numbering. Only menu names should display in two columns
-
Oct 26th, 2007, 12:11 AM
#6
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
My usual boring signature: Something
-
Oct 26th, 2007, 07:58 AM
#7
Thread Starter
Lively Member
Re: How to display data in two columns?
Oh my god!!!
it was so simple!!!!
thanks dclamp!!!
-
Oct 26th, 2007, 04:36 PM
#8
Re: [RESOLVED]How to display data in two columns?
no problem
My usual boring signature: Something
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|