Jump to content

[SOLVED] quick layout problem


jacko_162

Recommended Posts

i have the following code;

 

<?
// Query to pull information from the "products" Database
$result = mysql_query("select * from $table1 order by id DESC LIMIT 0 , 8");
while ($row = mysql_fetch_object($result)) {
?>
                        <table width="100%" height="75" border="0" cellspacing="1" cellpadding="3">
                          <tr>
                            <td width="113" height="78" valign="top">
                              <div align="center"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><a href="../product.php?ID=<? echo $row->id; ?>"><img src="../images/products/<? echo $row->id; ?>thumb.jpg" border="0" style="border: 1px solid #35830C" width="113" height="75"></a></font></div></td>
                            <td valign="top"><div align="left"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><a href="../product.php?ID=<? echo $row->id; ?>"><? echo $row->name; ?><br />
                                </a>Product code: <? echo $row->id; ?></font><strong><br />
                                <br />
                                <br />
£<? echo $row->price; ?></strong></div></td>
                          </tr>
                        </table>
                        <br />
                        <? } ?>

 

it pulls products from my database but lists them going down the page?!

 

how can i make it into a grid like view but limit the products to a maximum of 3 products per row and a total of 12 products?

 

any help would be appreciated.?!

Link to comment
Share on other sites

i fond a chunk of code to use;

 

<title>Control Panel - Home</title>
<? include("includes/header.php") ?>
<table width=300 border=0 align=center>
<?php

//set 3 to 4 of you want 4 columns. Set it to 5 if you want 5, etc
$numcols = 5; // how many columns to display
$numcolsprinted = 0; // no of columns so far

// get the results to be displayed
$query = "SELECT * FROM $table1 ORDER BY id";
$mysql_result = mysql_query($query);

// get each row
while($myrow = mysql_fetch_assoc($mysql_result))
{

// set rows you want to view here
$id = $myrow['id'];

if ($numcolsprinted == $numcols) {
print "</tr>\n<tr>\n";
$numcolsprinted = 0;
}

// output row from database
echo "<td>$id</td>\n";

// bump up row counter
$numcolsprinted++;

} // end while loop

$colstobalance = $numcols - $numcolsprinted;
for ($i=1; $i<=$colstobalance; $i++) {

}
print "<TD></TD>\n";
?>
</table>

 

 

can i edit;

// output row from database
echo "<td>$id</td>\n";

 

to ouput it like this;

 

<?
// Query to pull information from the "products" Database
$result = mysql_query("select * from $table1 order by id DESC LIMIT 0 , 8");
while ($row = mysql_fetch_object($result)) {
?><table width="100%" height="75" border="0" cellspacing="1" cellpadding="3">
                    <tr> 
                      <td width="113" height="78" valign="top"> 
                        <div align="center"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><a href="../product.php?ID=<? echo $row->id; ?>"><img src="../images/products/<? echo $row->id; ?>thumb.jpg" border="0" style="border: 1px solid #35830C" width="113" height="75"></a></font></div>                        </td>
                      <td valign="top"><div align="left"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><a href="../product.php?ID=<? echo $row->id; ?>"><? echo $row->name; ?><br />
                        </a>Product code: <? echo $row->id; ?></font><strong><br />
                          <br />
                          <br />
  £<? echo $row->price; ?></strong></div></td>
                    </tr>
                  </table>
                    <br />
                  <? } ?>

Link to comment
Share on other sites

why not do it manualy

 

<?php
$word=array("one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","therteen");

    echo"<table border='4'><tr><td>$word[0]<br>$word[1]<br>$word[2]<td></tr></table>   <br><br>";
echo"<table border='4'><tr><td>$word[3]<br>$word[4]<br>$word[5]<td></tr></table>   <br><br>";
    echo"<table border='4'><tr><td>$word[6]<br>$word[7]<br>$word[8]<td></tr></table>   <br><br>";
echo"<table border='4'><tr><td>$word[9]<br>$word[10]<br>$word[11]<td></tr></table> <br><br>";
?>

Link to comment
Share on other sites

i have limit set to 8 at moment cause it lists the ID desending and cause it goes from top to bottom in a list, if i can arrange it in rows then i can display more.

 

im new to php so forgive me if i dont fully understand yet..

 

this image shows what i need it to do;

 

screen1.JPG

 

i have them listed on the right already, but i need them like they are in the middle of the image...

Link to comment
Share on other sites

Something like this?

 

<table width="100%" height="75" border="0" cellspacing="1" cellpadding="3"><tr>
<?php
// Query to pull information from the "products" Database
$result = mysql_query("select * from $table1 order by id DESC LIMIT 0 , 8");
/* edited below: added 2 lines */
$row_number = 4;
$counter = 0;
while ($row = mysql_fetch_object($result)) {
if ($counter%$row_number==0&&$counter!=0) echo "</tr><tr>";
?>
                      <td width="113" height="78" valign="top"> 
                        <div align="center"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><a href="../product.php?ID=<?php echo $row->id; ?>"><img src="../images/products/<?php echo $row->id; ?>thumb.jpg" border="0" style="border: 1px solid #35830C" width="113" height="75"></a></font></div>                        </td>
                      <td valign="top"><div align="left"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><a href="../product.php?ID=<?php echo $row->id; ?>"><?php echo $row->name; ?><br />
                        </a>Product code: <?php echo $row->id; ?></font><strong><br />
                          <br />
                          <br />
  £<?php echo $row->price; ?></strong></div></td>
                  <?php } ?>
</tr>
</table>
<br />

Link to comment
Share on other sites

Something like this?

 

<table width="100%" height="75" border="0" cellspacing="1" cellpadding="3"><tr>
<?php
// Query to pull information from the "products" Database
$result = mysql_query("select * from $table1 order by id DESC LIMIT 0 , 8");
/* edited below: added 2 lines */
$row_number = 4;
$counter = 0;
while ($row = mysql_fetch_object($result)) {
if ($counter%$row_number==0&&$counter!=0) echo "</tr><tr>";
?>
                      <td width="113" height="78" valign="top"> 
                        <div align="center"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><a href="../product.php?ID=<?php echo $row->id; ?>"><img src="../images/products/<?php echo $row->id; ?>thumb.jpg" border="0" style="border: 1px solid #35830C" width="113" height="75"></a></font></div>                        </td>
                      <td valign="top"><div align="left"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><a href="../product.php?ID=<?php echo $row->id; ?>"><?php echo $row->name; ?><br />
                        </a>Product code: <?php echo $row->id; ?></font><strong><br />
                          <br />
                          <br />
  £<?php echo $row->price; ?></strong></div></td>
                  <?php } ?>
</tr>
</table>
<br />

 

that works great, how can i change this to show only 3 columns, and 4 rows???

Link to comment
Share on other sites

I'm so sorry. This was my fault. Forgot one thing. Thanks for letting me know.

 

Please try:

<table width="100%" height="75" border="0" cellspacing="1" cellpadding="3"><tr>
<?php
// Query to pull information from the "products" Database
$result = mysql_query("select * from $table1 order by id DESC LIMIT 0 , 8");
/* edited below: added 2 lines */
$row_number = 4;
$counter = 0;
while ($row = mysql_fetch_object($result)) {
if ($counter%$row_number==0&&$counter!=0) echo "</tr><tr>";
?>
                      <td width="113" height="78" valign="top"> 
                        <div align="center"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><a href="../product.php?ID=<?php echo $row->id; ?>"><img src="../images/products/<?php echo $row->id; ?>thumb.jpg" border="0" style="border: 1px solid #35830C" width="113" height="75"></a></font></div>                        </td>
                      <td valign="top"><div align="left"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><a href="../product.php?ID=<?php echo $row->id; ?>"><?php echo $row->name; ?><br />
                        </a>Product code: <?php echo $row->id; ?></font><strong><br />
                          <br />
                          <br />
  £<?php echo $row->price; ?></strong></div></td>
                  <?php $counter++; } ?>
</tr>
</table>
<br />

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.