How to list in 2 columns?

Discussion in 'PHP' started by ozone1, Dec 3, 2007.

  1. #1
    Hi i want to list my links in 2 columns. currently it lists all links in one column alphabetically like this

    [​IMG]

    I want to make it like this

    [​IMG]

    HERE IS MY CODE

    <img src="<? echo URL; ?>templates/imgs/Hd.gif"><br><p>
    <table border="0" width="100%">
    <tr>
        <td align="center" style="padding-left: 10px; font-size:17px;"><a style="color:#339966;" href="/main.php?id=<?php echo $category; ?>&amp;&amp;l=0-9">0-9</a> | <a style="color:#339966;" href="/main.php?id=<?php echo $category; ?>&amp;&amp;l=A">A</a> | <a style="color:#339966;" href="/main.php?id=<?php echo $category; ?>&amp;&amp;l=B">B</a> | <a style="color:#339966;" href="/main.php?id=<?php echo $category; ?>&amp;&amp;l=C">C</a> | <a style="color:#339966;" href="/main.php?id=<?php echo $category; ?>&amp;&amp;l=D">D</a> | <a style="color:#339966;" href="//main.php?id=<?php echo $category; ?>&amp;&amp;l=E">E</a> | <a style="color:#339966;" href="/main.php?id=<?php echo $category; ?>&amp;&amp;l=F">F</a> | <a style="color:#339966;" href="/main.php?id=<?php echo $category; ?>&amp;&amp;l=G">G</a> | <a style="color:#339966;" href="/main.php?id=<?php echo $category; ?>&amp;&amp;l=H">H</a> | <a style="color:#339966;" href="/main.php?id=<?php echo $category; ?>&amp;&amp;l=I">I</a> | <a style="color:#339966;" href="/main.php?id=<?php echo $category; ?>&amp;&amp;l=J">J</a> | <a style="color:#339966;" href="/main.php?id=<?php echo $category; ?>&amp;&amp;l=K">K</a> | <a style="color:#339966;" href="/main.php?id=<?php echo $category; ?>&amp;&amp;l=L">L</a> | <a style="color:#339966;" href="/main.php?id=<?php echo $category; ?>&amp;&amp;l=M">M</a> | <a style="color:#339966;" href="/main.php?id=<?php echo $category; ?>&amp;&amp;l=N">N</a> | <a style="color:#339966;" href="/main.php?id=<?php echo $category; ?>&amp;&amp;l=O">O</a> | <a style="color:#339966;" href="/main.php?id=<?php echo $category; ?>&amp;&amp;l=P">P</a> | <a style="color:#339966;" href="/main.php?id=<?php echo $category; ?>&amp;&amp;l=Q">Q</a> | <a style="color:#339966;" href="/main.php?id=<?php echo $category; ?>&amp;&amp;l=R">R</a> | <a style="color:#339966;" href="/main.php?id=<?php echo $category; ?>&amp;&amp;l=S">S</a> | <a style="color:#339966;" href="/main.php?id=<?php echo $category; ?>&amp;&amp;l=T">T</a> | <a style="color:#339966;" href="/main.php?id=<?php echo $category; ?>&amp;&amp;l=U">U</a> | <a style="color:#339966;" href="/main.php?id=<?php echo $category; ?>&amp;&amp;l=V">V</a> | <a style="color:#339966;" href="/main.php?id=<?php echo $category; ?>&amp;&amp;l=W">W</a> | <a style="color:#339966;" href="/main.php?id=<?php echo $category; ?>&amp;&amp;l=X">X</a> | <a style="color:#339966;" href="/main.php?id=<?php echo $category; ?>&amp;&amp;l=Y">Y</a> | <a style="color:#339966;" href="/main.php?id=<?php echo $category; ?>&amp;&amp;l=Z">Z</a></td>
    <?php
    if	($_GET['l'] == "0-9")
    	{
        $message = "<br>You are viewing titles beginning with a number.";
        }
    else if	(isset($_GET['l']) && $_GET['l'] !== "0-9" && $_GET['l'] !== "")
    	{
        $message = "<br>You are viewing titles beginning with the letter " .  $_GET['l'] . ".";
        }
    else
    	{
        $message = "<br>You are viewing all titles";
        }
    ?>
    </tr>
    <?php
    landbanner();
    echo $message;
    if	($_GET['l'])
    	{
        if	($_GET['l'] == "0-9")
        	{
        $mresult = mysql_query("SELECT * FROM videos where `title` REGEXP '^[0-9]' AND category='".$category."' ORDER BY `title` asc");
            }
        else
        	{
        $mresult = mysql_query("SELECT * FROM videos where `title` like '".mysql_real_escape_string($_GET['l'])."%' AND category='".$category."' ORDER BY `title` asc");
        	}
        }
    else
    	{
    $mresult = mysql_query("SELECT * FROM videos WHERE category='".$category."' ORDER BY `title` ASC");
    	}
    
    while($row = mysql_fetch_array($mresult))
      {
    	$id = $row['id'];
    	$title = $row['title'];
    	?>
      <tr>
        <td style="padding-left: 10px;"> • 
        <? if($seo == 0) { ?> <a href="<? echo URL; ?>videos.php?id=<? echo $id ?>"><? echo $title ?></a><br><img src="<? echo URL; ?>templates/imgs/spacer.gif"> <?  } ?>
        <? if($seo == 1) { ?> <a href="<? echo URL; ?>videos/<? echo $id ?>"><? echo $title ?></a><br><img src="<? echo URL; ?>templates/imgs/spacer.gif"> <?  } } ?></td>
       </tr>
       <tr> <td><? echo landbanner(); ?></td></tr>
    
    
    </table>
    
    
    
    Code (markup):

    Someone please help. Thanks
     
    ozone1, Dec 3, 2007 IP
  2. vonvhen

    vonvhen Peon

    Messages:
    152
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I think you can approach this in two ways.

    One is to store your results in two arrays (one for each column), and then call a for loop to display it.

    Another, is to use the '%' function to do a comparison on the array index. So on your code, you will need to add a variable to store the index. e.g. set '$k=0;' outside the WHILE loop and put "$k++;" inside the WHILE loop. Once you have an index, you can do the '%' comparison. e.g. if (($k % 2)==0)
     
    vonvhen, Dec 3, 2007 IP
  3. ozone1

    ozone1 Member

    Messages:
    34
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    43
    #3
    Hi thanks for the reply but i dont know anything about php could you please tell me what all things i have to add in the code step by step please...
    Thanks again
     
    ozone1, Dec 3, 2007 IP
  4. vonvhen

    vonvhen Peon

    Messages:
    152
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You can try something similiar to the code below.

    Displaying is more on the HTML side. You might want to read on how to display mulitple columns with tables.

    Bold text = ADDED

    $k=0;

    while($row = mysql_fetch_array($mresult))
    {
    $id[$k] = $row['id'];
    $title[$k] = $row['title'];
    $k++;
    } //end while loop

    for($i=0;$i<=$k;$i++){ ?>

    <tr>
    <td style="padding-left: 10px;"> •
    <? if($seo == 0) { ?> <a href="<? echo URL; ?>videos.php?id=<? echo $id ?>"><? echo $title ?></a><br><img src="<? echo URL; ?>templates/imgs/spacer.gif"> <? } ?>
    <? if($seo == 1) { ?> <a href="<? echo URL; ?>videos/<? echo $id ?>"><? echo $title ?></a><br><img src="<? echo URL; ?>templates/imgs/spacer.gif"> <? } } ?></td>
    <? if (($i%2)==0){?>
    <td><a href="<? echo URL; ?>videos.php?id=<? echo $id ?>"><? echo $title ?></a><br><img src="<? echo URL; ?>templates/imgs/spacer.gif"></td>
    <?}else{?>
    <td></td>
    <?}?>
    </tr>
    <tr> <td colspan="2"><? echo landbanner(); ?></td></tr>

    <?} //end forloop ?>

    </table>
     
    vonvhen, Dec 4, 2007 IP
  5. ozone1

    ozone1 Member

    Messages:
    34
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    43
    #5
    Thanks bruv lemme try it
     
    ozone1, Dec 4, 2007 IP