cdoggg94 Posted December 10, 2012 Share Posted December 10, 2012 Basically I just dont know where to start.. I want to make a table that displayed as many images as there are in the DB. I want the table to only go 4 <td> wide, then move to the next line...etc.. I tried googling a few things, but I couldnt find what i wanted. If anyone can send a link, or has some advice, it would be greatly appreciated. Thanks Quote Link to comment Share on other sites More sharing options...
Beeeeney Posted December 10, 2012 Share Posted December 10, 2012 This should explain: <?php if (isset($_GET['page'])) { include "includes.php"; $query = "SELECT * FROM cruise"; $result = mysql_query($query); $num=mysql_numrows($result); mysql_close(); ?> <br /><a href="form.php">Hide all bookings</a><br><br> <table border="1" cellspacing="2" cellpadding="2"> <tr> <td><font face="Arial"><b>Name</b></font></td> <td><font face="Arial"><b>Address</b></font></td> <td><font face="Arial"><b>Cruise Line</b></font></td> <td><font face="Arial"><b>Ship Name</b></font></td> <td><font face="Arial"><b>Destination</b></font></td> <td><font face="Arial"><b>Departure Date</b></font></td> <td><font face="Arial"><b>Agent Name</b></font></td> <td><font face="Arial"><b>TIMESTAMP</b></font></td> </tr> <?php $i=0; while ($i < $num) { $Name=mysql_result($result,$i,"Name"); $Address=mysql_result($result,$i,"Address"); $CruiseLine=mysql_result($result,$i,"Cruise_Line"); $ShipName=mysql_result($result,$i,"Ship_Name"); $Destination=mysql_result($result,$i,"Destination"); $DepartureDate=mysql_result($result,$i,"Departure_Date"); $AgentName=mysql_result($result,$i,"Agent_Name"); $TimeStamp=mysql_result($result,$i,"TIMESTAMP"); ?> <tr> <td><font face="arial"><?php echo $Name; ?></font></td> <td><font face="arial"><?php echo $Address; ?></font></td> <td><font face="arial"><?php echo $CruiseLine; ?></font></td> <td><font face="arial"><?php echo $ShipName; ?></font></td> <td><font face="arial"><?php echo $Destination; ?></font></td> <td><font face="arial"><?php echo $DepartureDate; ?></font></td> <td><font face="arial"><?php echo $AgentName; ?></font></td> <td><font face="arial"><?php echo $TimeStamp; ?></font></td> </tr> <?php $i++; } } ?> Made that for work when I first started learning PHP. Very simple. Quote Link to comment Share on other sites More sharing options...
cdoggg94 Posted December 10, 2012 Author Share Posted December 10, 2012 Thanks for getting back. I have a question though. This looks like something that is going to repeat information for as many records as there are in its own <tr> In the attached image, fig 1 shows what i want to happen if there are 3 entries. fig 2 shows what would happen if there were 7. after the forth entry, the next 3 would go down to the next line..the same would happen if there were 100 entries..never more then 4 on one line and it there is a 5th or whatever it starts a new line. maybe you script its exactly that haha...but at a glance it looks like its not. Quote Link to comment Share on other sites More sharing options...
cdoggg94 Posted December 10, 2012 Author Share Posted December 10, 2012 Quote Link to comment Share on other sites More sharing options...
Beeeeney Posted December 10, 2012 Share Posted December 10, 2012 Thanks for getting back. I have a question though. This looks like something that is going to repeat information for as many records as there are in its own <tr> In the attached image, fig 1 shows what i want to happen if there are 3 entries. fig 2 shows what would happen if there were 7. after the forth entry, the next 3 would go down to the next line..the same would happen if there were 100 entries..never more then 4 on one line and it there is a 5th or whatever it starts a new line. maybe you script its exactly that haha...but at a glance it looks like its not. I'm going to teach you some very advanced HTML now, it will blow your mind. <br> Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted December 10, 2012 Share Posted December 10, 2012 You would use a counter to determine when you close out one row and start the next - http://forums.phpfreaks.com/topic/11572-multi-column-results/ Quote Link to comment Share on other sites More sharing options...
cdoggg94 Posted December 10, 2012 Author Share Posted December 10, 2012 good lesson.. I dont think thats going to be my solution though... thanks anyways Quote Link to comment Share on other sites More sharing options...
cdoggg94 Posted December 10, 2012 Author Share Posted December 10, 2012 @PFMaBiSmAd , Thank you I will try it right now Quote Link to comment Share on other sites More sharing options...
cdoggg94 Posted December 10, 2012 Author Share Posted December 10, 2012 I just have a question, where does $product get it value ? the code asks if its empty or blank, but i dont get where its getting its value, which I think should be the content i want to display.. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted December 10, 2012 Share Posted December 10, 2012 (edited) That comes from the column name that was selected in the query statement. Unfortunately, someone broke a rule of clear code writing and used the extract statement to magically produce php variables in that code. You would normally, and less magically, use $row['product'] in that code. Edited December 10, 2012 by PFMaBiSmAd Quote Link to comment Share on other sites More sharing options...
cdoggg94 Posted December 10, 2012 Author Share Posted December 10, 2012 that make a lot more sense haha Quote Link to comment Share on other sites More sharing options...
cdoggg94 Posted December 10, 2012 Author Share Posted December 10, 2012 my server went down for a while so i couldnt test it....now that i changed it over it works perfect thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.