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
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
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
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
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.

Edited by PFMaBiSmAd
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.