Jump to content

Repeating Table


cdoggg94

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/271817-repeating-table/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/271817-repeating-table/#findComment-1398521
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/271817-repeating-table/#findComment-1398527
Share on other sites

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>

Link to comment
https://forums.phpfreaks.com/topic/271817-repeating-table/#findComment-1398529
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/271817-repeating-table/#findComment-1398554
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.