Page 1 of 1

Extracting data in pre made html tables {HELP NEWBIE}

Posted: Tue Jan 17, 2006 9:02 am
by joe_thomas
Please help i'm still a newbie at PHP

Details

I want to extract the last 4 entries into these premade 4 boxes as shown below. This will be shown on a page so whenever i upload a new item it will automatically update the last 4 entires into these boxes.

What i need is to extract the image which will be shown in the top half of the box and bottom will be the title and these will be hyperlinked to the a specific page.

The Problem

I haven't started with the image extraction but the title to start off with and im guessing once i have the title working correctly the image will follow the
same route.

Well i have managed to display the last uploaded item to display but it repeats the same title in the extra three boxes which instead it should display the next 3 entry titles.

The problem picture

Image

I undertand my PHP isnt written correctly but a helping hand is all i need as i find this all very difficult especially writing it all up and understanding.

Coulde anyone help?


PHP Script

Code: Select all

<?php
include('db_connect.inc')
?>
<?php
mysql_select_db("Shop");

$query = "SELECT * FROM Shop " .
		 "ORDER BY POSTDATE DESC " ;
$results = mysql_query($query)
  or die(mysql_error());
$row = mysql_fetch_array($results);
extract($row);
?>
<table width="360" align="center">
                <tr>
                  <td><table width="360" cellspacing="0" cellpadding="0">
                      
                      <tr>
                        <td><img src="images/latest.gif" width="360" height="30"></td>
                      </tr>
                      <tr>
                        <td><img src="images/contentspacer.gif" width="2" height="14"></td>
                      </tr>
                      <tr>
                        <td><table width="174" cellpadding="0" cellspacing="0">
                          <tr>
                            <td width="46%" valign="top" bgcolor="eaeaea"><table width="100%" cellspacing="4">
                              <tr id="latest01">
                                <td height="165" valign="top"><img src="images/shirt.jpg" width="163" height="165"></td>
                              </tr>
                              <tr>
                                <td bgcolor="a9a9a9"><table width="100%" cellspacing="0" cellpadding="4">
                                  <tr>
                                    <td><?php echo $row[3] ?></td>
                                  </tr>
                                </table></td>
                              </tr>
                            </table></td>
                            <td width="8%"><img src="images/contentspacer.gif" width="7" height="14"></td>
                            <td width="46%" bgcolor="eaeaea"><table width="100%" cellspacing="4">
                              <tr>
                                <td><img src="images/shirt.jpg" width="163" height="165"></td>
                              </tr>
                              <tr>
                                <td bgcolor="a9a9a9"><table width="100%" cellspacing="0" cellpadding="4">
                                  <tr>
                                    <td><?php echo $row[3]; ?></td>
                                  </tr>
                                </table></td>
                              </tr>
                            </table></td>
                          </tr>
                        </table></td>
                      </tr>
                  </table></td>
                </tr>
                <tr>
                  <td><img src="images/contentspacer.gif" width="2" height="14"></td>
                </tr>
                <tr>
                  <td><table width="174" cellpadding="0" cellspacing="0">
                    <tr>
                      <td width="46%" bgcolor="eaeaea"><table width="174" cellspacing="4">
                          <tr>
                            <td><img src="images/shirt.jpg" width="163" height="165"></td>
                          </tr>
                          <tr>
                            <td bgcolor="a9a9a9"><table width="100%" cellspacing="0" cellpadding="4">
                              <tr>
                                <td><?php echo $row[3]; ?></td>
                              </tr>
                            </table></td>
                          </tr>
                      </table></td>
                      <td width="8%"><img src="images/contentspacer.gif" width="7" height="14"></td>
                      <td width="46%" bgcolor="eaeaea"><table width="100%" cellspacing="4">
                          <tr>
                            <td><img src="images/shirt.jpg" width="163" height="165"></td>
                          </tr>
                          <tr>
                            <td bgcolor="a9a9a9"><table width="100%" cellspacing="0" cellpadding="4">
                              <tr>
                                <td><?php echo $row[3]; ?></td>
                              </tr>
                            </table></td>
                          </tr>
                      </table></td>
                    </tr>
                  </table></td>
                </tr>
                <tr>
                  <td>&nbsp;</td>
                </tr>
                <tr>
                  <td><img src="images/contentspacer.gif" width="2" height="14"></td>
                </tr>
              </table>

Posted: Tue Jan 17, 2006 11:15 am
by Chris Corbyn

Code: Select all

<?php
include('db_connect.inc')
?>
<?php
mysql_select_db("Shop");

$query = "SELECT * FROM Shop " .
         "ORDER BY POSTDATE DESC " ;
$results = mysql_query($query)
  or die(mysql_error());

$titles = array();

while ($row = mysql_fetch_array($results))
{
   $titles[] = $row[3];
}

?>
<table width="360" align="center">
                <tr>
                  <td><table width="360" cellspacing="0" cellpadding="0">
                      
                      <tr>
                        <td><img src="images/latest.gif" width="360" height="30"></td>
                      </tr>
                      <tr>
                        <td><img src="images/contentspacer.gif" width="2" height="14"></td>
                      </tr>
                      <tr>
                        <td><table width="174" cellpadding="0" cellspacing="0">
                          <tr>
                            <td width="46%" valign="top" bgcolor="eaeaea"><table width="100%" cellspacing="4">
                              <tr id="latest01">
                                <td height="165" valign="top"><img src="images/shirt.jpg" width="163" height="165"></td>
                              </tr>
                              <tr>
                                <td bgcolor="a9a9a9"><table width="100%" cellspacing="0" cellpadding="4">
                                  <tr>
                                    <td><?php echo $titles[0] ?></td>
                                  </tr>
                                </table></td>
                              </tr>
                            </table></td>
                            <td width="8%"><img src="images/contentspacer.gif" width="7" height="14"></td>
                            <td width="46%" bgcolor="eaeaea"><table width="100%" cellspacing="4">
                              <tr>
                                <td><img src="images/shirt.jpg" width="163" height="165"></td>
                              </tr>
                              <tr>
                                <td bgcolor="a9a9a9"><table width="100%" cellspacing="0" cellpadding="4">
                                  <tr>
                                    <td><?php echo $titles[1]; ?></td>
                                  </tr>
                                </table></td>
                              </tr>
                            </table></td>
                          </tr>
                        </table></td>
                      </tr>
                  </table></td>
                </tr>
                <tr>
                  <td><img src="images/contentspacer.gif" width="2" height="14"></td>
                </tr>
                <tr>
                  <td><table width="174" cellpadding="0" cellspacing="0">
                    <tr>
                      <td width="46%" bgcolor="eaeaea"><table width="174" cellspacing="4">
                          <tr>
                            <td><img src="images/shirt.jpg" width="163" height="165"></td>
                          </tr>
                          <tr>
                            <td bgcolor="a9a9a9"><table width="100%" cellspacing="0" cellpadding="4">
                              <tr>
                                <td><?php echo $titles[2]; ?></td>
                              </tr>
                            </table></td>
                          </tr>
                      </table></td>
                      <td width="8%"><img src="images/contentspacer.gif" width="7" height="14"></td>
                      <td width="46%" bgcolor="eaeaea"><table width="100%" cellspacing="4">
                          <tr>
                            <td><img src="images/shirt.jpg" width="163" height="165"></td>
                          </tr>
                          <tr>
                            <td bgcolor="a9a9a9"><table width="100%" cellspacing="0" cellpadding="4">
                              <tr>
                                <td><?php echo $titles[3]; ?></td>
                              </tr>
                            </table></td>
                          </tr>
                      </table></td>
                    </tr>
                  </table></td>
                </tr>
                <tr>
                  <td>&nbsp;</td>
                </tr>
                <tr>
                  <td><img src="images/contentspacer.gif" width="2" height="14"></td>
                </tr>
              </table>
Side note: That's a lot of tabling you have there :) You may want to look into using CSS and DIV elements to cut that right down ;)

Posted: Tue Jan 17, 2006 12:16 pm
by joe_thomas
thank you soooo much

its works great :D :D :D

just what i wanted

and i will take css into consideration, just trying to get the nitty grity bits out first

thanks again

Posted: Tue Jan 17, 2006 12:39 pm
by Chris Corbyn
You should possibly see a pattern in your table strcuture by the way. So much so that you can build the table itself inside the while(){} loop :)