Forum Moderators: coopster

Message Too Old, No Replies

PHP & MYSQL data into html tables

         

undream2

8:40 am on Mar 7, 2008 (gmt 0)

10+ Year Member



Hi,

Sorry for the looong message.

I am in need of some help here. I am tring to extract mysql data with php into tables. I need to input the data of the fields into html extactly as below.

<table>
<tr>
<TD ALIGN=left WIDTH="sizeofcontent" bgcolor="#ffffff"></td>
</tr>

<tr>
<td width=150 valign=top>
<img src="graphic.jpg">
</td>

<td>
<font face=verdana size=4>Title</font><br>
<font face=arial size=3>Description</font><br>
<font face=verdana size=3><b><u>Date</u>: </b>March 5th 2008</font> &nbsp;&nbsp;&nbsp;&nbsp;
<font face=verdana size=3><b><u>Code</u>: </b></font>
<font face=verdana size=3>thecode</b></font><br><br>
</td>
</tr>
</table>

With repeating the html within the <table> tags. So, that the Mysql can create as many 2 column tables needed for all of the mysql tables information.

HERE IS THE PHP CODE I AM TRYING THAT IS INSERTED AFTER MYSQL LOGIN INFO...

$columns = 2; //you can change this to 3, 4, 5 etc.

$imagelink = $row["imagelink"];
$link = $row["link"];
$title = $row["title"];
$description = $row["description"];
$date = $row["date"];
$code = $row["code"];

$data = mysql_query ("SELECT * FROM Table");
$num_rows = mysql_num_rows($data);

echo "<table>";

for($i = 0; $i < $num_rows; $i++) {
$row = mysql_fetch_array($data);
if($i % $columns == 0) {

echo "<tr>\n";
eecho "<TD ALIGN=left WIDTH=sizeofcontent bgcolor="#ffffff"></td>\n";
echo "</tr>\n";
}

echo "<tr>\n";
echo "<td width=150 valign=top>\n";

echo "<img src=".$row[0].">\n";
echo "</td>\n";
echo "<td>\n";
echo "<font face=verdana size=4><a href=".$row[1].">".$row[2]."</a></font><br>\n";

echo "<font face=arial size=3>".$row[3]."</font><br>\n";

echo "<font face=verdana size=3><b><u>Date</u>: </b>".$row[4]."</font> &nbsp;&nbsp;&nbsp;&nbsp;\n";

echo "<font face=verdana size=3><b><u>Code</u>: </b></font>\n";
echo "<font face=verdana size=3>".$row[5]."</b></font><br><br>\n";

echo "</td>\n";
echo "</tr>\n";

echo "<tr>\n";

if($row[5]!= "Null")
echo "<td><a href='$UploadAddress/$row[5]'><img src='$ThumbAddress/$row[4]' border='0' alt='$row[0]'></a></td>\n");

if(($i % $columns) == ($columns - 1) ¦¦ ($i + 1) ==
$num_rows) {

}}
echo "</table>\n";
?>

Any help would be appreciated.. Thanks.

deMorte

9:20 am on Mar 7, 2008 (gmt 0)

10+ Year Member



What exactly is the problem with the script?

undream2

9:35 am on Mar 7, 2008 (gmt 0)

10+ Year Member



Its just showing a blank page.. So, its connecting to the DB, but something is wrong within the later scripting. Usually, the server will show error on line etc.. But sometimes a blank page.

dreamcatcher

9:50 am on Mar 7, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I can see two problems with this line:

eecho "<TD ALIGN=left WIDTH=sizeofcontent bgcolor="#ffffff"></td>\n";

eecho?

And you need to escape double quotes.

echo "<TD ALIGN=left WIDTH=sizeofcontent bgcolor=\"#ffffff\"></td>\n";

I would suggest you enable error reporting at the top of your page:

<?php
error_reporting(E_ALL);
?>

That may give you some clues.

dc

[edited by: dreamcatcher at 9:59 am (utc) on Mar. 7, 2008]

deMorte

9:56 am on Mar 7, 2008 (gmt 0)

10+ Year Member



Are you sure your query is producing a result? Try echoing $num_rows before your for-clause. If there are rows, try print_r($row) and you'll see what the array contains. Other than this, I'm not sure what the problem might be.