Alicia Posted November 16, 2008 Share Posted November 16, 2008 Hi guys, can somebody give me an idea or anywherer i can find a reference how to output the records i fetched from the database in multiple columns and rows ? I was able to output the records in multiple columns but only in a row.,, it doesnt really add another row by itself.. please advise where to find a solution for this.. thanks, Link to comment https://forums.phpfreaks.com/topic/132977-multiple-columns-and-rows/ Share on other sites More sharing options...
redarrow Posted November 16, 2008 Share Posted November 16, 2008 use a while loop ......... if u need to do anythink more then post your database stucture or read up your self on mysql joins <?php //database connection $sql="select * from what_ever"; $result=mysql_query($sql)or die(mysql_error()); while($data=mysql_fetch_assoc($result)){ echo " <br><br> ".$date['ehat_ever_info']." <br><br>"; } ?> Link to comment https://forums.phpfreaks.com/topic/132977-multiple-columns-and-rows/#findComment-691516 Share on other sites More sharing options...
flyhoney Posted November 16, 2008 Share Posted November 16, 2008 Here is a very simple example: <?php // database connection information $hostname = 'localhost'; $username = 'username'; $password = 'password'; $database = 'database'; // open database $link = mysql_connect($hostname, $username, $password); if (!$link) { die('Could not connect: ' . mysql_error()); } mysql_select_db($database) or die("Unable to select database"); // query database $query = "SELECT column1, column2 FROM table"; $result = mysql_query($query) or die(mysql_error()); // print results ?> <table> <tr> <th>column1</th> <th>column2</th> </tr> <?php while ($row = mysql_fetch_assoc($result)): ?> <tr> <td><?php echo $row['column1'] ?></td> <td><?php echo $row['column2'] ?></td> </tr> <?php endwhile; ?> </table> Link to comment https://forums.phpfreaks.com/topic/132977-multiple-columns-and-rows/#findComment-691550 Share on other sites More sharing options...
Alicia Posted November 17, 2008 Author Share Posted November 17, 2008 Hi, I need somethng like Column 1 and column 2 in the seperate row then second and third columns will show different records.. it is like what we can see for normal online store page.. show multiple items in a page.. please advise how can i accomplish that.. thanks Link to comment https://forums.phpfreaks.com/topic/132977-multiple-columns-and-rows/#findComment-691860 Share on other sites More sharing options...
flyhoney Posted November 17, 2008 Share Posted November 17, 2008 <?php // database connection information $hostname = 'localhost'; $username = 'username'; $password = 'password'; $database = 'database'; // open database $link = mysql_connect($hostname, $username, $password); if (!$link) { die('Could not connect: ' . mysql_error()); } mysql_select_db($database) or die("Unable to select database"); // query database $query = "SELECT column1, column2 FROM table"; $result = mysql_query($query) or die(mysql_error()); // print results $number_of_columns = 3; $x = 1; ?> <table> <?php while ($row = mysql_fetch_assoc($result)): ?> <?php if ((($x - 1) % $number_of_columns) == 0): ?> <tr> <?php endif; ?> <td> <h2><?php echo $row['column1'] ?><h2> <p><?php echo $row['column2'] ?></p> </td> <?php if (($x % $number_of_columns) == 0): ?> </tr> <?php endif; ?> <?php $x++; ?> <?php endwhile; ?> </table> Link to comment https://forums.phpfreaks.com/topic/132977-multiple-columns-and-rows/#findComment-692058 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.