Contact Us Forum Rules Search Archive
WebProWorld Part of WebProNews.com
Page One Link To Us Edit Profile Private Messages Archives FAQ RSS Feeds  
 

Go Back   WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum
Subscribe to the Newsletter FREE!


Register FAQ Members List Calendar Arcade Chatbox Mark Forums Read

Web Programming Discussion Forum Working with an API? Developing a plugin? Writing a Mod or script for your favorite blog, Web 2.0 site or Forum? Welcome.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-30-2007, 07:26 AM
edhan's Avatar
WebProWorld Veteran
 

Join Date: Aug 2003
Location: Singapore
Posts: 581
edhan RepRank 1
Question Help - How to have 2 columns???

Hi

Being new to programming, I wonder if someone can help to advice how I can create 2 columns for displaying users.

I am thinking of splitting it to 2 or 4 columns so that it will reduce the height of display in a single column.

Hope someone can give some help on this. Thanks!

Here is my current code:

Code:
<?php
$query1="SELECT `username` FROM `record` where `active` ='1' order by `userid` DESC LIMIT 100";
$result1=mysql_query($query1);

$num=mysql_numrows($result1);



echo "<b><center>Last 100 Members</center></b><br>";

if ($num>101) {
$to=1;
}else{
$to=$num;
}

$i=0;
while ($i < $to) {

$loginname=mysql_result($result1,$i,"username");

echo "<a href='$siteurl/$loginname.html'>$loginname</a><br>";

$i++;
}

?>
Reply With Quote
  #2 (permalink)  
Old 11-30-2007, 11:16 AM
wige's Avatar
Moderator
WebProWorld Moderator
 

Join Date: Jun 2006
Location: United States
Posts: 1,843
wige RepRank 4wige RepRank 4wige RepRank 4wige RepRank 4
Default Re: Help - How to have 2 columns???

I think the following should work, I am assuming here you would use a table...

PHP Code:
<?php
$query1
="SELECT `username` FROM `record` where `active` ='1' order by `userid` DESC LIMIT 100";
$result1=mysql_query($query1);

$num=mysql_numrows($result1);

echo 
"<b><center>Last 100 Members</center></b><br>";

if (
$num>101) {
$to=1// This should be 100, not 1 correct?
}else{
$to=$num;
}

$i=1;
if (
$to 10) { // Only show two colums if more than 10 entries are to be displayed - in case you want that ability
   
$midpoint = ($to 0.5) / 2// This ensures the division rounds up, this will make the first column longer for odd numbers
}
echo 
'<table><tr><td>';
while (
$i <= $to) {

   
$loginname=mysql_result($result1,$i,"username");

   echo 
"<a href='$siteurl/$loginname.html'>$loginname</a><br>";
   if (
$i == $midpoint) echo '</td><td>'// Switch to column two, if column one is full
   
$i++;
}
echo 
'</td></tr></table>';
?>
__________________
The best way to learn anything, is to question everything.

Last edited by wige : 11-30-2007 at 11:18 AM.
Reply With Quote
  #3 (permalink)  
Old 11-30-2007, 12:20 PM
WebProWorld New Member
 

Join Date: Nov 2007
Posts: 15
fahadp RepRank 0
Default Re: Help - How to have 2 columns???

Using tables can be a good approach or you can organise listing by using XHTML. If you use XHTML and css then you dont need to worry about laying down members in php code, css will take care of it.

Any how i am going to provide you with a code that uses table

PHP Code:
 
<?php
$query1
="SELECT `username` FROM `record` where `active` ='1' order by `userid` DESC LIMIT 100";
$result1=mysql_query($query1);
$num=mysql_numrows($result1);
 
echo 
"<b><center>Last 100 Members</center></b><br>";
/* added by Fahad Pervaiz */
echo "<table><tr>";
$count=1;
while (
$row mysql_fetch_assoc($result1)) 
{
 if(
$count==5)//5 colums per row
 
{
  
//add a new ROW
  
echo "</tr><tr>";
  
$intc=1;
 }
 
 echo 
"<td>".$row['username']."</td>";
 
$count++;
}
/* end Fahad Pervaiz */
?>
__________________
www.ecommerce-xperts.com
Reply With Quote
  #4 (permalink)  
Old 11-30-2007, 11:03 PM
edhan's Avatar
WebProWorld Veteran
 

Join Date: Aug 2003
Location: Singapore
Posts: 581
edhan RepRank 1
Thumbs up Re: Help - How to have 2 columns???

Thanks to both of you, now it is working fine.

Appreciate your help.
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum
Tags:



Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems with columns using CSS EmmaGale Graphics & Design Discussion Forum 13 10-10-2008 10:24 PM
getting columns same length gellnsh Graphics & Design Discussion Forum 2 09-27-2007 05:12 AM
Columns: Menu & Body WiseWizards Graphics & Design Discussion Forum 5 07-03-2004 02:01 AM
2 columns vs. 3 columns Bohak Graphics & Design Discussion Forum 4 06-08-2004 06:56 PM
HTML in databse columns alienzhavelanded Database Discussion Forum 4 01-02-2004 03:02 PM


Search Engine Optimization by vBSEO 3.2.0