SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Guru
    Join Date
    Oct 2004
    Location
    uk
    Posts
    853
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    split array into 2 rows

    Hi guys

    How can i split this into 2 rows

    I have done it at the moment but its 8 on 1 side and 8 on the other

    As there could be many rows added I want it to have the same amount on each side


    Many thanks in advance
    PHP Code:




    <div><Br>        
    <Table height="500" width="100%">
    <tr>
    <td VALIGN="TOP">
     <?
    $id 
    $_GET['id'];
    $sql "SELECT * FROM Category";


    $result mysql_query ($sql);

    $i 0;
    $row mysql_fetch_array$result );

    echo 
    '<table width="100%"><tr><td valign="top"><font size=3 face="century gothic">';
    while( 
    $i<) {

    echo 
    '<a href="browsecategory.php?category=' urlencode($row[name]) . '">'; echo"$row[name]</a><br>";

        
    $row mysql_fetch_array$result );
        
    $i++;
    }

    echo 
    "</td>";
    echo 
    "<td valign=top><font size=3 face='century gothic'>";

    while( 
    $i >= && $i<14 ) {
    echo 
    '<a href="browsecategory.php?category=' urlencode($row[name]) . '">'; echo"$row[name]</a><br>";

        
    $row mysql_fetch_array$result );
        
    $i++;
    }

    echo 
    "</td></tr></table>";


    ?>

  2. #2
    SitePoint Member
    Join Date
    Jul 2007
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    $nRows = mysql_num_rows($result);
    for($i = 0; $i < $nRows/2; $i++)
       // Print first column
    for($i = 0; $i < $nRows/2; $i++)
      // Print second column

  3. #3
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This code works me fine.
    Code php:
    $id = $_GET['id'];
    $sql = "SELECT * FROM Category";
    $result = mysql_query($sql) or die(mysql_error());
    $total = mysql_num_rows($result);
    $half = ceil($total / 2);
    $counter = 1;
    echo '<table width="400" border="1" cellspacing="0" cellpadding="0"><tr><td width="200" valign="top">';
    while($rows = mysql_fetch_array($result)){
    	echo "<table><tr><td>&bull; <a href=\"browsecategory.php?category=" . urlencode($rows['name']) . "\">{$rows['name']}</a></td></tr></table>";
    	if($counter == $half) echo "</td><td width=\"200\" valign=\"top\">";
    	$counter++;
    }
    echo "</td></tr></table>";

    I am not sure whether you mean like this or not. Lol!
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  4. #4
    SitePoint Guru
    Join Date
    Oct 2004
    Location
    uk
    Posts
    853
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    how could I split into 4 rows?

  5. #5
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Code PHP:
    $values = range(1, 31);
    $rows   = array_chunk($values, 2); # array_chunk($values, 4)
    
    print '<table>';
    foreach ($rows as $row) {
        print '<tr>';
     
        foreach ($row as $value) {
            print '<td>' . $value . '</td>';
        }
     
        print '</tr>';
    }
    print '</table>';

    Will make two rows or four rows or whatever.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •