Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tables in PHP 3

Status
Not open for further replies.

ZOR

Technical User
Jan 30, 2002
2,963
GB
Can someone please point me to a reference site where I can see the use of webpage tables with PHP. I have tried with snippets of example, other refernces, but still its taking hours just to try and design/view a table & data within PHP on a page.
All references I follow just lead to database tables.

I cannot see anything that jumps out in the PHP manual. Thanks
 
This isn't rocket science.

You use the print function to output all the tags necessary to make the table. Then you stop printing:

[tt]print '<html><body><table><tr><td>';[/tt]

Then you print the value of the variable or whatever that should go in that table cell:

[tt]print $a;[/tt]

Then you continue on, printing the necessary table tags:

[tt]print '</table></body></html>';[/tt]


Showing you anything beyond simple examples is impossible, as only you know that the table should look like.



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Code:
PRINT ("<table width=100% cellspacing=1 border=0>
	<tr class=boven2>
	<td>Name</td>
	<td>Technical details</td>
	<td></td>
	<td></td>
	</tr>");

$q_result = mysql_query("SELECT arname,arspecsnl from artisttable order by arname");
while ($ary = mysql_fetch_assoc($q_result)) { //one
  while (list($key,$val) = each($ary)) { //two
   $$key = $val;
  }  // end two


   print"<tr>";
   print"<td>$arname<br></td>"; 
   print"<td>$arspecsnl<br></td>"; 
   print"</tr>"; 

} //end one

print ("
</table>
</BODY>
</HTML>");

and here an little bit bigger example on how to convert database table values into an table, I can't script it shorter then this ;)

 
Thanks, I got there. I had previously got a table to work, but deleted it in error. All I could remember, even looking at past posting was to change " to '. I did it to everything in the table which I thought worked before but this time failed. I no know and wont forget to put in ' after echo or print, and at the end of the table. I looked at PHPmailer, but it will take me too long to learn to use it now. Thats a problem because I need to find a way to email the HTML table, and I don't know as I have not had the time, to see if the normal PHP mail will do it. Don't think so. I will spend time in the future to learn about PHPmailer. Regards
 
Creating tables from PHP depends on what you want to do with them.

Here is an example that creates a 2 column table that displays two numbers $i and 2x$i.

Code:
<?PHP
echo "<table><tr><td>Value of i</td><td>Two times i</td></tr>";
for($i=0;$i<=5;$i++)
{
$j=2*$i;
echo "<tr><td>" . $i . "</td><td>" . $j . "</td></tr>";
}
echo "</table>";
?>

This will create the table on the fly.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Thankyou all, that should shut me up once and for all regarding tables. Sorry if I seem to be the village idiot, but I have come across from VB6. Never worked with HTML or PHP and it's been like a nightmare so far. If I can email the table when its filled, then I can start to relax a bit. Regards
 
You must have output text strings interspersed with values from variables before. This is all you are doing here, too. If you keep that in mind, you need only remember a few vocabulary changes in order to bring your VB experience to PHP.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top