Jump to content

PHP inside a table


grahamb314

Recommended Posts

Hi all,

 

I have a PHP connection to a database which retreives data such as Name, Day, StartTime and EndTime,

I want to display the data in a table like so:

 

Monday            Tuesday            Wednesday....

first event        first event

second event    second event

third event      third event

 

At the moment I have all the data in one column:

Events:

one (Monday

two (Monday)

three (Monday)

one (Tuesday)

two (Tuesday)

etc

etc

 

Is there a sample of how to do this somewhere?

Thanks!

 

 

Link to comment
Share on other sites

Thanks!

$result = mysql_query("select * from table ORDER BY Day,StartTime");

echo '<table border="0">';

while($r=mysql_fetch_array($result)){	
   $Show=$r["Show"];
   $StartTime=$r["StartTime"];
   $EndTime=$r["EndTime"];
   $Day=$r["Day"];
   $Day++;

echo"<tr>";
echo "<td>$Show</td><td> $StartTime</td> <td> $EndTime</td><td> $Day</td>";
echo"</tr>";
}
echo "</table>";

Link to comment
Share on other sites

Here is an example..

 


<?php

echo "<table>";

$myquery=mysql_query("SELECT field1, field2 FROM mytable");
while ($row = mysql_fetch_array($myquery)) {
  echo "<tr><td>$row[field1]</td><td>$row[field2]</td></tr>";
}

echo "</table>";

?>

 

That will print a table with a new row for each field1 and field2

Link to comment
Share on other sites

Here is an example..

 


<?php

echo "<table>";

$myquery=mysql_query("SELECT field1, field2 FROM mytable");
while ($row = mysql_fetch_array($myquery)) {
  echo "<tr><td>$row[field1]</td><td>$row[field2]</td></tr>";
}

echo "</table>";

?>

 

That will print a table with a new row for each field1 and field2

 

Hi, actually what I am looking for is to only display the days on the top row and then each event under the appropriate heading.

eg go shopping goes under Monday and order take-away would be under Friday's heading for example.

Attached my plan :)

 

 

Link to comment
Share on other sites

I see.. there are several ways you can do that actually..

 

You could use nested tables..

 

Essentially have 1 outside table, the first <td> would be Monday and you list each event under this in the while loop checking each time to see if the day has changed on your query results.  If it changes then you create a new <td> therefore putting it in the next column.

 

When it comes down to it you really need to just play with the code and use logic to figure out how its going to output.

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.