php url help

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)

[code]<?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 .= '
' . image_name . '
'; } } else { $dynamicList = "We have no images listed in our store yet"; } mysql_close(); ?> Store Home Page
<?php include_once("template_header.php");?>
  <p><?php echo $dynamicList; ?>
<?php include_once("template_footer.php");?>

[/code]

and this is the page where my data is viewwed i think (gallery.php):

[code]<?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(); ?> <?php echo $image_name; ?>
<?php include_once("template_header.php");?>

<?php echo $image_name; ?>



</tr>
<?php echo $image_name; ?>
View Full Size Image
<?php include_once("template_footer.php");?>
[/code]

check the id number if they are odd or even,
google: php is odd or even :slight_smile:

odd or even would not work for what he is trying to accomplish, look at how he wants the rows"

1234
5678

Here is an example of how to do what you need to do
[php]
$x = 0;
echo “

”;
$result=mysql_query(“SELECT * TABLE”);
while ( $row=mysql_fetch_assoc($result) ) {
echo “”;
$x++;
if ($x>4) {
echo “”;
}
}
echo “
” . $row[‘field’]. “
”;
[/php]

Hope that helps :wink:

yeah you’re right but if he has more then 2 TR then he could use odd or even with your example :smiley:

ahhh…
[php]if ($x>4) {
echo “

”;
}[/php]

that wold mean by the 5th 6th … row he would become an

somenting like:

item 1 item 2 item 3 item 4
item5
item6
item7

[php]$x = 0;
echo “

”;
$result=mysql_query(“SELECT * TABLE”);
while ( $row=mysql_fetch_assoc($result) ) {
echo “”;
$x++;
$y = $x / 4;
if(is_float($y)){
echo “”;
}
}
echo “
” . $row[‘field’]. “
”; [/php]

so this would work, try it :slight_smile:

Good eye on that I was not thinking right then so he needs to zero out the $x variable after it hits 4 :wink:
[php]
$x = 0;
echo “

”;
$result=mysql_query(“SELECT * TABLE”);
while ( $row=mysql_fetch_assoc($result) ) {
echo “”;
$x++;
if ($x>4) {
echo “”;
$x=0;
}
}
echo “
” . $row[‘field’]. “
”;
[/php]

I tried that But I didn’t know how to input it to the code

can anyone help

this is the page and you can see what i want when you see the first page

don’t use a table for that, use CSS stick the images inside a list

  • then appy some css styling like this:

    [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) { $dynamicList .="
      "; while($row = mysql_fetch_array($sql)){ $id = $row["id"]; $dynamicList .= '
    • ' . image_name . '
    • '; } $dynamicList .="<\ul>"; } else { $dynamicList = "We have no images listed in our store yet"; } mysql_close(); ?> Store Home Page <!-- li{ list-style-type:none; margin-right:10px; margin-bottom:10px; float:left; }

      –>

      <?php include_once("template_header.php");?>
        <?php echo $dynamicList; ?>
      
      <?php include_once("template_footer.php");?>
      [/php]

      You can see a demo of this at http://phphelptutorials.com/demos/galleryfromfolder/ this example there all loaded from a folder automatically not really what you need but the styling and positing suitable for what you need. There’s a tutorial just in case its useful http://www.phphelptutorials.com/tutorials/creating-an-image-gallery-from-a-folder-of-images-automatically/

  • Sponsor our Newsletter | Privacy Policy | Terms of Service