SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    May 2011
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Displaying info from MySQL in Columns

    Hi there,

    Now i have a bunch rows in a SQL Database that i want to have displayed in a table but each rows info must be displayed in a column, for example the rows has data like this:

    1, 2, 3, 4, 5, 6, 7, 8, 9, 10

    so, lets say there is 3 rows it should display it like this :

    1 1 1
    2 2 2
    3 3 3
    4 4 4
    5 5 5
    6 6 6
    7 7 7
    8 8 8
    9 9 9
    10 10 10

    this is the code i have so far:

    Code PHP:
     $query  = "SELECT 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 FROM info ORDER BY id";
     $result = mysql_query($query) or die('Error : ' . mysql_error());
     
     $content = "<table>";
     
      //code goes here, i guess it will be some kind of foreach loop or something
     
     $content .= "</table>";
     
    echo $content;

    I guess it will be a foreach loop i guess, i know how to work with the while loop but then it creates a column below each other and not next to each other. Help Please...Thank u

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,509
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    First you use the while loop to load the mysql result set in a multi-dimensional array.
    Then you use the foreach loop to loop through the array and display the data as you want to.

  3. #3
    SitePoint Member
    Join Date
    May 2011
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, but okay i tried this:

    Code PHP:
     
            $content .= '<table>';
     
            while($row = mysql_fetch_array($result, MYSQL_NUM))
    	{
    		foreach($row as $1 => $9) 
    		{
    			$content .= "
    			<tr><td>$1</td></tr>";
    		}
    	}
     
    	$content .= '</table>';

    but then it only displays the second row not this first one or the rest?


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
  •