Jump to content

MySQL catalog arrangement with tables


JCS1988

Recommended Posts

I am working on a project for class and can't figure out how to get these photos to fill up the row and then move to the next line. They are just staying in the same column, leaving a huge blank space. The catalog is setup to display all the product entries in the database. Here is a link to the page http://jcs5325.aisites.com/landscape.php

 

Here is the small bit I have inside the div to display all of the entries. As you can see from the web page it displays all of them no problem, I would just like them to tile horizontally first, then continue onto another row.

 

<table>      
<?php
$query="Select * FROM catalog";
$result=mysql_db_query($DBname, $query, $link);
while ($row=mysql_fetch_array($result)) {
  print ("<tr><td><a href=makeorder.php");
  print ("?p_id=");
  print($row['id']);
  print(">");
  print($row['p_name']);
  print("</a></td></tr>");
  print("<tr><td><img src=\"");
  print($row['picture']);
  print("\"class=\"thumb\"></td></tr>");
}
print ("</table>");
mysql_close($link);
?>

Link to comment
Share on other sites

I figured it had something to do with that, but I wasn't sure how to have the images go horizontal, and then once they are out of room jump down to the next line. Right now they just keep going.

 

http://jcs5325.aisites.com/landscape.php

 

<table>      
<?php
$query="Select * FROM catalog";
$result=mysql_db_query($DBname, $query, $link);
while ($row=mysql_fetch_array($result)) {
  print ("<a href=makeorder.php");
  print ("?p_id=");
  print($row['id']);
  print(">");
  print($row['p_name']);
  print("</a>");
  print("<td><img src=\"");
  print($row['picture']);
  print("\"class=\"thumb\">");
}
print ("</table>");
mysql_close($link);
?>

Link to comment
Share on other sites

As I can see it didn't 100% fix it, but it did get it all onto one row.

IF you were to put a class on the table (or just style it) and put a width down of however big the box is, it should fix it.

 

http://www.storyoftherealms.com/2008testsite/Dev2Net/test.html

I updated it to show what I mean. With a width on the table it makes it go down automatically.

 

Link to comment
Share on other sites

Try this

<table style="width:650px;"><tr><td> 
<?php
$query="Select * FROM catalog";
$result=mysql_db_query($DBname, $query, $link);
while ($row=mysql_fetch_array($result)) {
  print ("<a href=makeorder.php");
  print ("?p_id=");
  print($row['id']);
  print(">");
  print($row['p_name']);
  print("</a>");
  print("<img src=\"");
  print($row['picture']);
  print("\"class=\"thumb\">");
}
mysql_close($link);
?>
</td></tr></table> 

Not sure why the </table> was being printed by PHP? So I moved it out.

Link to comment
Share on other sites

They are going the right way now, but I just noticed that since everything is in the same row the text sits next to the image. It's pretty confusing, since that small php script just repeats itself for every database entry I can't imagine how to get the text and image in the perfect spot. http://jcs5325.aisites.com/landscape.php

Link to comment
Share on other sites

<? 
<table style="width:650px;"> 
<?php
$query="Select * FROM catalog";
$result=mysql_db_query($DBname, $query, $link);
for ($i=0; $i<=5; $i++){
<tr>
while ($row=mysql_fetch_array($result)) {
	echo "<td><img src=\"".$row['picture']."\"class=\"thumb\"><br/><center><a href=makeorder.php"."?p_id=".$row['id'].">".$row['p_name']."</a></center></td>";
}
</tr>
}
mysql_close($link);
?>

 

Try that code? Not sure at all what it's gona do. Notice I put everything on one line and echoed it instead. No clue if this is gona work. Also the <td>'s are back in to make the text be under the image as well as the image comes first instead of the text now.

Link to comment
Share on other sites

The <tr> in the middle cause a syntax error, unexpected '<' it said. Thanks for all the help and fast replies but I give up on this code, I didn't like it from the start. It's out of one of our text books, which are usually outdated anyway. I'll probably search the web for something more flexible, know of anything? Basically I am pulling data entries out of the products table, and having it automatically list all of them for me and provide

"add to cart" links for each listing.

Link to comment
Share on other sites

Hmmm okay cool. Good php codes for pulling things out of a hat. Well what you have their IS good, except its being done oddly. I have the same code on my website except its only going one way (vertical). Though I am using dividers instead of tables. If you used the same code and used dividers with a float:left; then it may work, but not sure. Mines all vertical. If you were to redesign the layout to have the items in a vertical view and had more info on the left or something, you could do it like that as well. So many choices. Fun stuff PHP is. Though I'm EXTREMELY new to it. Just have a person who helps me with it. But I'm out for the night so addios!

Link to comment
Share on other sites

So I used Dreamweaver this time to create a very simple record set to display that data, but I have the same problem still. At least this time there isn't as much confusing code to look at, once I get the arrangement right I can add the rest. I would like to have 4 entries per row, and have the 5th automatically start a new row. The code is set to repeat for each entry in the database. I tried to remove the <tr> tags, the <td> tags, and even set a width for the table but nothing seems to get them in the right place.

 

http://jcs5325.aisites.com/landscape.php

 

          <table border="0" align="center">
            <?php do { ?>
              <tr>
                <td height="50" align="center"><?php echo $row_catalogSet['p_name']; ?> $<?php echo $row_catalogSet['cost']; ?>.00<br />
                <?php echo $row_catalogSet['picture']; ?></td>
              </tr>
              <?php } while ($row_catalogSet = mysql_fetch_assoc($catalogSet)); ?>
          </table>

 

 

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.