Renegade Public Forums
C&C: Renegade --> Dying since 2003™, resurrected in 2024!
Home » General Discussions » General Discussion » PHP help
PHP help [message #53845] Tue, 04 November 2003 12:22 Go to next message
General Havoc is currently offline  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 #53846] Tue, 04 November 2003 12:38 Go to previous messageGo to next message
General Havoc is currently offline  General Havoc
Messages: 1564
Registered: February 2003
Location: Birmingham, England, Unit...
Karma: 0
General (1 Star)
This image may help you understand what I am trying to do,

http://www.n00bstories.com/image.fetch.php?id=1317374836


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 Go to previous messageGo to next message
Crimson is currently offline  Crimson
Messages: 7430
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 Go to previous messageGo to next message
General Havoc is currently offline  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 #53867] Tue, 04 November 2003 15:35 Go to previous messageGo to next message
General Havoc is currently offline  General Havoc
Messages: 1564
Registered: February 2003
Location: Birmingham, England, Unit...
Karma: 0
General (1 Star)
Here is an image of what the script you wrote does. I can see why it does it but I can't think of how to egt around it.

http://www.n00bstories.com/image.fetch.php?id=1232801743


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 Go to previous messageGo to next message
Crimson is currently offline  Crimson
Messages: 7430
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.
PHP help [message #53870] Tue, 04 November 2003 15:50 Go to previous messageGo to next message
General Havoc is currently offline  General Havoc
Messages: 1564
Registered: February 2003
Location: Birmingham, England, Unit...
Karma: 0
General (1 Star)
It works great Smile Thanks for your help, I've just got a little editing to do with the colum and table width percentages but it works properly.

I'm still learning PHP/MySQL but it's great so far.

-Thanks Again


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 #53871] Tue, 04 November 2003 15:52 Go to previous messageGo to next message
Crimson is currently offline  Crimson
Messages: 7430
Registered: February 2003
Location: Phoenix, AZ
Karma: 0
General (5 Stars)
ADMINISTRATOR
Awesome. I'm glad it worked. Smile

I'm the bawss.
PHP help [message #54273] Fri, 07 November 2003 15:40 Go to previous message
jointzzzz is currently offline  jointzzzz
Messages: 12
Registered: October 2003
Karma: 0
Recruit
Crimson

Awesome. I'm glad it worked. Smile


Damn crimson, u married yet ? I dreamt of a coder-girl all my life Wink Haven't met any, except the married ones at my work Razz
Previous Topic: Crimson Server?????????
Next Topic: OT: 12 Years Today.
Goto Forum:
  


Current Time: Sun Dec 29 08:32:24 MST 2024

Total time taken to generate the page: 0.00870 seconds