dark k58 Posted March 24, 2012 Share Posted March 24, 2012 ok I made it so that in my index page it would list 10 items from my gallery database but the items are on top of each other e.g.: item1 item 2 item3 etc... I want to be able to orgnise it so it would be like: item 1 item 2 item 3 item 4 item 5 item 6 item 7 etc... this is my index page where all my data will show(index.php): <?php error_reporting(E_ALL); ini_set('display_errors', '0'); ?> <?php // Run a select query to get my letest 6 items // Connect to the MySQL database include "script/connect_to_mysql.php"; $dynamicList = ""; $sql = mysql_query("SELECT * FROM gallery ORDER BY id DESC LIMIT 10"); $imageCount = mysql_num_rows($sql); // count the output amount if ($imageCount > 0) { while($row = mysql_fetch_array($sql)){ $id = $row["id"]; $dynamicList .= '<table width="1050px" border="0" cellspacing="0" cellpadding="6" bgcolor="#FFFF99" cellpadding="150"> <tr> <td width="17%" valign="top"><a href="gallery.php?id=' . $id . '"><img style="border:#666 1px solid;" src="gallery_images/' . $id . '.jpg" alt="' . image_name . '" width="77" height="102" border="1" /></a></td> </tr> </table>'; } } else { $dynamicList = "We have no images listed in our store yet"; } mysql_close(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Store Home Page</title> <link rel="stylesheet" href="style/style.css" type="text/css" media="screen" /> </head> <body> <div align="center" id="mainWrapper"> <?php include_once("template_header.php");?> <div id="pageContent"> <p><?php echo $dynamicList; ?> </div> <?php include_once("template_footer.php");?> </div> </body> </html> and this is the page where my data is viewwed i think (gallery.php): <?php // This file is www.developphp.com curriculum material // Written by Adam Khoury January 01, 2011 // http://www.youtube.com/view_play_list?p=442E340A42191003 // Script Error Reporting error_reporting(E_ALL); ini_set('display_errors', '1'); ?> <?php // Check to see the URL variable is set and that it exists in the database if (isset($_GET['id'])) { // Connect to the MySQL database include "script/connect_to_mysql.php"; $id = preg_replace('#[^0-9]#i', '', $_GET['id']); // Use this var to check to see if this ID exists, if yes then get the product // details, if no then exit this script and give message why $sql = mysql_query("SELECT * FROM gallery WHERE id='$id' LIMIT 1"); $imageCount = mysql_num_rows($sql); // count the output amount if ($imageCount > 0) { // get all the product details while($row = mysql_fetch_array($sql)){ $image_name = $row["image_name"]; $date_added = strftime("%b %d, %Y", strtotime($row["date_added"])); } } else { echo "That item does not exist."; exit(); } } else { echo "Data to render this page is missing."; exit(); } mysql_close(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title><?php echo $image_name; ?></title> <link rel="stylesheet" href="style/style.css" type="text/css" media="screen" /> </head> <body> <div align="center" id="wrapper"> <?php include_once("template_header.php");?> <div id="content"> <table width="100%" border="0" cellspacing="0" cellpadding="15"> <tr> <td width="30%" valign="top"><h3><?php echo $image_name; ?></h3><hr> </tr></table> <table width="100%" border="0" cellspacing="0" cellpadding="15"> <td width="80%" height="50%" valign="top"><img src="gallery_images/<?php echo $id; ?>.jpg" width="800" height="500" align="left" alt="<?php echo $image_name; ?>" /><br /> </td> <br /> </tr> </table></br> <table> <td> <a href="gallery_images/<?php echo $id; ?>.jpg">View Full Size Image</a> </td> </table> </div> <?php include_once("template_footer.php");?> </div> </body> </html> I did some research and I know I'm suppose to use a code like this to make it work but I'm still a beginner and I don't really know how to implement it so please help: $x = 0; echo "<table><tr>"; $result=mysql_query("SELECT * TABLE"); while ( $row=mysql_fetch_assoc($result) ) { echo "<td>" . $row['field']. "</td>"; $x++; $y = $x / 4; if(is_float($y)){ echo "</tr><tr>"; } } echo "</tr></table>"; thankyou Quote Link to comment https://forums.phpfreaks.com/topic/259593-php-url-help/ Share on other sites More sharing options...
teng84 Posted March 24, 2012 Share Posted March 24, 2012 use ul and li instead the float it to the left Quote Link to comment https://forums.phpfreaks.com/topic/259593-php-url-help/#findComment-1330632 Share on other sites More sharing options...
dragon_sa Posted March 24, 2012 Share Posted March 24, 2012 You can also do this with css, just put the results in div's with set width, put those div's in another div container with a fixed width of 4 or 5 result div's or however many you want to display across and it will automatically wrap them to the next line each time you reach the end of the containing div eg container div 500 wide multiple result div's 100 wide end container div This will give you rows of 5, these can be centered, for incomplete last row that may have less, what ever suits you purpose, and you dont need to use tables. Quote Link to comment https://forums.phpfreaks.com/topic/259593-php-url-help/#findComment-1330639 Share on other sites More sharing options...
dark k58 Posted March 24, 2012 Author Share Posted March 24, 2012 You can also do this with css, just put the results in div's with set width, put those div's in another div container with a fixed width of 4 or 5 result div's or however many you want to display across and it will automatically wrap them to the next line each time you reach the end of the containing div eg container div 500 wide multiple result div's 100 wide end container div This will give you rows of 5, these can be centered, for incomplete last row that may have less, what ever suits you purpose, and you dont need to use tables. I need to do it on php, that code calls 10 items from database and images from my file and makes a url using .php?id="id" I was told to use this code : $x = 0; echo "<table><tr>"; $result=mysql_query("SELECT * TABLE"); while ( $row=mysql_fetch_assoc($result) ) { echo "<td>" . $row['field']. "</td>"; $x++; $y = $x / 4; if(is_float($y)){ echo "</tr><tr>"; } } echo "</tr></table>"; but I don't know how/where to add it to my code, so can some one help me with that thanks Quote Link to comment https://forums.phpfreaks.com/topic/259593-php-url-help/#findComment-1330758 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.