PHP help [message #53845] |
Tue, 04 November 2003 12:22 |
|
General Havoc
Messages: 1564 Registered: February 2003 Location: Birmingham, England, Unit...
Karma: 0
|
General (1 Star) |
|
|
I know this may be OT for Renegade but I know some of you are good with PHP and I was wondering if you could help me solve a problem.
I have page that pulls data from a MySQL database into a table on the page. The problem is that I want to pull two different entries into the same rows on the table. Take a look at the code, you can see what it is doing at the moment.
<?PHP
$products = "SELECT * FROM Products ORDER BY id DESC";
$result = mysql_query($products) or die ("Query Failed");
echo "<table width=\"100%\" border=\"1\">";
echo "<TR>";
while ($row = mysql_fetch_object($result)){
echo "<td colspan=\"2\"><font face=\"arial\" size=\"2\">$row->title</font></td>";
echo "</TR><TR>";
echo "<td><font face=\"arial\" size=\"2\">$row->description</font></td>";
echo "<td><IMG SRC=\"upload/$row->image\" width=\"50\" height=\"50\"></td>";
}
echo "</TR>";
echo "</table>";
?>
As you can see it pulls the data into two rows of a table. I need it to pull in title of entry one, then title of entry 2 next to it in the same row. The same for the row underneath, I need it to pull in the data for the second entry in the database.
There is probably a better way of doing it than I am, like using two table rather than messing around with table rows. It looks like it can be done but maybe somone who knows PHP better can help?
Visit my website at http://renhelp.laeubi-soft.de powered by laeubi.de
"SHUT UP AND MOD" - Dante
"ACK is the Simon Cowell of modding" - Ultron10
Scripts.dll Debugger, Map Scripter and Tutorial writer
Computer Science Bsc
Aston University in Birmingham, UK
|
|
|
|
PHP help [message #53863] |
Tue, 04 November 2003 14:59 |
|
Crimson
Messages: 7429 Registered: February 2003 Location: Phoenix, AZ
Karma: 0
|
General (5 Stars) ADMINISTRATOR |
|
|
<?PHP
$products = "SELECT * FROM Products ORDER BY id DESC";
$result = mysql_query($products) or die ("Query Failed");
echo "<table width=\"100%\" border=\"1\">";
echo "<TR>";
$i=1;
while ($row = mysql_fetch_object($result)){
echo "<td colspan=\"2\"><font face=\"arial\" size=\"2\">$row->title</font></td>";
if ($i%2 == 0) {
echo "</TR><TR>";
}
echo "<td><font face=\"arial\" size=\"2\">$row->description</font></td>";
echo "<td><IMG SRC=\"upload/$row->image\" width=\"50\" height=\"50\"></td>";
$i++;
}
echo "</TR>";
echo "</table>";
?>
I didn't test it, but that should work
I'm the bawss.
|
|
|
PHP help [message #53866] |
Tue, 04 November 2003 15:25 |
|
General Havoc
Messages: 1564 Registered: February 2003 Location: Birmingham, England, Unit...
Karma: 0
|
General (1 Star) |
|
|
I tried the code but it produces the same results as the one I tried earlier, which was similar to the code you posted.
It is not ending the row (</TR>) after the title cell has been inserted so the next 2 bits of information remain on the one row. Basically I need to insert the title of the first item on row 1 cell 1 (spans 2 cols) then the title of the second item in row 1 cell 2 (also spans 2 cols).
Visit my website at http://renhelp.laeubi-soft.de powered by laeubi.de
"SHUT UP AND MOD" - Dante
"ACK is the Simon Cowell of modding" - Ultron10
Scripts.dll Debugger, Map Scripter and Tutorial writer
Computer Science Bsc
Aston University in Birmingham, UK
|
|
|
|
PHP help [message #53869] |
Tue, 04 November 2003 15:43 |
|
Crimson
Messages: 7429 Registered: February 2003 Location: Phoenix, AZ
Karma: 0
|
General (5 Stars) ADMINISTRATOR |
|
|
<?PHP
$products = "SELECT * FROM Products ORDER BY id DESC";
$result = mysql_query($products) or die ("Query Failed");
$items_to_list = mysql_num_rows($result);
$i = 0;
echo "<table width=\"100%\" border=\"1\">";
echo "<TR>";
while($i < $items_to_list) {
$left = mysql_fetch_object($result);
$right = mysql_fetch_object($result);
echo "<td colspan=\"2\"><font face=\"arial\" size=\"2\">$left->title</font></td>";
if ($right) {
echo "<td colspan=\"2\"><font face=\"arial\" size=\"2\">$right->title</font></td>";
}
echo "</TR><TR>";
echo "<td><font face=\"arial\" size=\"2\">$left->description</font></td>";
echo "<td><IMG SRC=\"upload/$left->image\" width=\"50\" height=\"50\"></td>";
if ($right) {
echo "<td><font face=\"arial\" size=\"2\">$right->description</font></td>";
echo "<td><IMG SRC=\"upload/$right->image\" width=\"50\" height=\"50\"></td>";
}
echo "</TR><TR>";
$i = $i + 2;
}
echo "</TR>";
echo "</table>";
?>
Once again, I didn't test this, but I didn't notice the colspan 2 cell.
I'm the bawss.
|
|
|
|
|
|