Page 1 of 2

Making Nice Tables

Posted: Wed Sep 28, 2005 4:06 pm
by icesolid
Take a look at my code below:

Code: Select all

<?php
$img = "specials";
$alt = "Specials";
include("layout.php");
include("connect.php");
?>
<table align="center" width="375" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td><img src="img/middle2_top.gif"></td>
  </tr>
  <tr>
    <td>
    <table width="375" border="0" cellpadding="0" cellspacing="0">
      <tr>
	    <td background="img/middle2_left.gif"><img src="img/middle2_left.gif"></td>
	    <td bgcolor="#FFFFFF" width="100%">
	    <table width="100%" border="0" cellpadding="5" cellspacing="1">
	      <tr>
	        <td align="center" colspan="2">
            <font face="Verdana" size="2">
            <h3>This Months Specials</h3>
            Check back soon for next months specials!
            </font>
            </td>
	      </tr>
          <tr>
            <td colspan="2">&nbsp;</td>
          </tr>
          <?php
          $result = mysql_query("SELECT * FROM specials ORDER BY sortorder ASC");

          while($row = mysql_fetch_array($result)) {
          ?>
	      <tr>
	        <td bgcolor="#E9E9E9" align="center">
            <font face="Verdana" size="2"><b><?php echo $row["item"]; ?>:</b></font>
            <br><br>
            <a href="specials/<?php echo $row["file"]; ?>" target="_blank"><img src="thumbnail.php?dir=specials&file=<?php echo $row["file"]; ?>" alt="<?php echo $row["item"]; ?>" border="1"></a><br>
            <font face="Verdana" size="1">(<a href="specials/<?php echo $row["file"]; ?>" target="_blank">Enlarge Photo</a>)</font>
            <br><br>
            <font face="Verdana" size="2" color="#FF0000"><b>Price:</b> $<?php echo $row["price"]; ?></font>
            </td>
	        <td bgcolor="#E9E9E9" align="center">
            <font face="Verdana" size="2"><b><?php echo $row["item"]; ?>:</b></font>
            <br><br>
            <a href="specials/<?php echo $row["file"]; ?>" target="_blank"><img src="thumbnail.php?dir=specials&file=<?php echo $row["file"]; ?>" alt="<?php echo $row["item"]; ?>" border="1"></a><br>
            <font face="Verdana" size="1">(<a href="specials/<?php echo $row["file"]; ?>" target="_blank">Enlarge Photo</a>)</font>
            <br><br>
            <font face="Verdana" size="2" color="#FF0000"><b>Price:</b> $<?php echo $row["price"]; ?></font>
            </td>
	      </tr>
          <tr>
            <td colspan="2">&nbsp;</td>
          </tr>
          <?php
          }
          ?>
	    </table>
	    </td>
	    <td background="img/middle2_right.gif"><img src="img/middle2_right.gif"></td>
      </tr>
    </table>
    </td>
  </tr>
  <tr>
    <td><img src="img/middle2_bottom.gif"></td>
  </tr>
</table>
<?php
footer();
?>
I want to make all of the records print out in that HTML format.

Posted: Wed Sep 28, 2005 4:40 pm
by Chris Corbyn
I'm confused what you are asking :? Could you give us some more detail please? :)

Reply

Posted: Wed Sep 28, 2005 4:51 pm
by icesolid
I want to print out records like this:

Code: Select all

<table>
  <tr>
    <td>row1</td>
    <td>row2</td>
  </tr>
  <tr>
    <td>row3</td>
    <td>row4</td>
  </tr>
</table>
But I have many rows, like 100!

I know I could use LIMIT to accomplish this im just not quite sure how.

Posted: Wed Sep 28, 2005 7:28 pm
by feyd
viewtopic.php?t=37448 may be of interest

Re: Making Nice Tables

Posted: Thu Sep 29, 2005 4:43 am
by omega-systems
use this :

Code: Select all

//$page, $pagesize
//page - page number; pagesize - number of items at the page
$statement = "SELECT * FROM specials ORDER BY sortorder ASC";
$statement = $statement . " limit ".(($page-1)*$pagesize).", $pagesize";
$result = mysql_query($statement);
instead of your

Code: Select all

$result = mysql_query("SELECT * FROM specials ORDER BY sortorder ASC");
Regards,
Michael.

Project Manager
Omega Systems Ltd
Email: info@omega-systems.biz
ICQ: 264962449
MSN: omega-systems@hotmail.com
AIM: OmegaSys Ltd

Still NO Help

Posted: Thu Sep 29, 2005 2:11 pm
by icesolid
I want to have results from my database print out like this.

Every two rows into one <tr></tr>, then break into another <tr></tr> for the next two rows.

Like this:

Code: Select all

<table> 
  <tr> 
    <td>row1</td> 
    <td>row2</td> 
  </tr> 
  <tr> 
    <td>row3</td> 
    <td>row4</td> 
  </tr> 
</table>

Posted: Thu Sep 29, 2005 5:29 pm
by feyd
did you read my link?

NO Help

Posted: Fri Sep 30, 2005 9:39 am
by icesolid
That link really doesent help me. Anyone else?

Posted: Fri Sep 30, 2005 10:37 am
by feyd
did you read this link from Useful Posts?

viewtopic.php?t=25105

HELP!!!!

Posted: Tue Oct 04, 2005 6:07 pm
by icesolid
I don't want to use a class. It's more than what I need. There has got to be a way to accomplish what I'm trying to do without using a class. Please a code sample would be nice.

I want to have results from my database print out like this.

Every two rows into one <tr></tr>. Example:

Code: Select all

<tr> 
  <td>row1</td> 
  <td>row2</td> 
</tr>
Then break into another <tr></tr> for the next two rows.

Final Print Out Like this:

Code: Select all

<table>
  <tr>
    <td>row1</td>
    <td>row2</td>
  </tr>
  <tr>
    <td>row3</td>
    <td>row4</td>
  </tr>
  <tr>
    <td>etc.</td>
    <td>etc.</td>
  </tr>
</table>

Posted: Tue Oct 04, 2005 6:34 pm
by mickd
something like this should do it (prolly needs tweaking)

Code: Select all

echo '<table>';
$rownum = 1;
while($row = mysql_fetch_assoc($result)) {
   if($rownum == '1') {
   echo '<tr>
            <td>' . $row['name'] . '
            </td>';
   $rownum++;
   } elseif($rownum = 2) {
   echo '
            <td>' . $row['name'] . '
            </td>
        </tr>';
   $rownum = 1;
   }
}
        if((mysql_num_rows($result) % 2) == 1) {
        echo '</tr>';
        }
echo '</table>';

HELP!

Posted: Tue Oct 04, 2005 6:52 pm
by icesolid
The code above is what I am trying to do, but it doesent work fully. I get an error on the mysql_fetch_assoc line. Help please?

Posted: Tue Oct 04, 2005 7:21 pm
by John Cartwright
before that line did you add a connection to your database along with a query?

Code: Select all

$connection = mysql_connect('localhost','user','pass') or die('Connection Failed');
$result = mysql_query('SELECT * FROM `table`') or die(mysql_error());

Posted: Tue Oct 04, 2005 7:38 pm
by feyd
class? what class? the links I posted have nothing to do with a class.. :?

hmhmhm....

Posted: Tue Oct 04, 2005 7:54 pm
by icesolid
feyd....how would this link help me: viewtopic.php?t=25105

answer me that?