Hi Im, making a gallery and I'm done with most of it , but I dont like that when it shows the results it show too many vertical results or too many horizontal results .
Heres the question

Is is possible to insert something so every 5 or 6 results it skips a line ?

here my code:

                 <?

mysql_connect("localhost","imager","somepass"); 

mysql_select_db("pandamanga"); 

$result = mysql_query("SELECT * FROM inventary WHERE DATE_SUB(CURDATE(),INTERVAL 30 DAY) <= create_date LIMIT 10;");

//grab all the content
while($r=mysql_fetch_array($result))
{	
   //the format is $variable = $r["nameofmysqlcolumn"];

   $name=$r["name"];
   $image=$r["image"];


   //display the rows

echo "<img src='$image'>$name";
?>

    Could always just do this:

    $i = 0;
    
    while ( $r = mysql_fetch_array($result) )
    {
       if ( $i % 5 != 0 )
       {
          // do other code here
       }
    
       ++$i;
    }
    

    If you want it to be a different number, change the 5.

      thank you so much for your responce

      I tryed your code but it doesnt seems to skip line :S

      maybe because im using tables or something , im currently trying this using your code:

      
      
       $i = 0; 
      
      while ( $r = mysql_fetch_array($result) ) 
      { 
         if ( $i % 5 != 0 ) 
         { 
         $title=$r["codigo"];
         $message=$r["producto"];
         $price=$r["precio"];
         $imagen=$r["imagen"];
         echo "   <td>
                        <table border='0' cellpadding='0' cellspacing='0' width='1%'>
      
                      <tbody>
                        <tr>
      
                          <td colspan='3'>
                          <p align='center'>
                          <font face='Times New Roman' size='1'>&nbsp;</font></p>
                          </td>
      
                        </tr>
      
                        <tr>
      
                          <td colspan='3'>
                          <p align='center'><font face='Times New Roman' size='1'>
                          <img src='eko/Images/box_03.jpg' alt='' height='3' width='86'></font></p>
                          </td>
      
                        </tr>
      
                        <tr>
      
                          <td>
                          <p align='center'><font face='Times New Roman' size='1'>
                          <img src='eko/Images/box_05.jpg' alt='' height='80' width='3'></font></p>
                          </td>
      
                          <td height='80' width='80'>
                          <p align='center'>
                          <font face='Times New Roman' size='1'>
                          <a href=product.html'>
                          <img src='$imagen' border='0' height='80' width='80'></a></font></p>
                          </td>
      
                          <td>
                          <p align='center'><font face='Times New Roman' size='1'>
                          <img src='eko/Images/box_07.jpg' alt='' height='80' width='3'></font></p>
                          </td>
      
                        </tr>
      
                        <tr>
      
                          <td colspan='3'>
                          <p align='center'><font face='Times New Roman' size='1'>
                          <img src='eko/Images/box_08.jpg' alt='' height='3' width='86'></font></p>
                          </td>
      
                        </tr>
      
                        <tr>
      
                          <td colspan='3'>
                          <p align='center'>
                          <font face='Times New Roman' size='1'>
                          <a href='product.html'>
      $message</a></font></p>
                              </td>
      
                        </tr>
      
                        <tr>
      
                          <td colspan='3'>
                          <p align='center'>
                          <font face='Times New Roman' size='1'>
                          <a href='product.html'>
      $price</a></font></p>
                              </td>
      
                        </tr>
      
                      </tbody>
                    </table></td>";
      
         } 
      
         ++$i; 
      }  
      
      
      

      Thanks again

        Are you talking about line breaks every X lines? then the code is close to right but he left out the line break

         $i = 0; 
        
        while ( $r = mysql_fetch_array($result) ) 
        { 
           if ( $i % 5 != 0 ) 
           {
           echo <br>
           }
           // do other code here 
        
        
           ++$i; 
        }  

          Sorry, I didn't really read through your code before making that post, and I'm not that quick with tables without writing them out and testing them, so I'll explain what this does.

          The whole "i" thing is like a counter. "i" is zero before the loop, and each time you make it to the bottom of the loop, "i" increases by one. If "i" is equal to nx where n is a positive integer and x is the number of lines you want before it skips a line so that if x = 5, nx = 5,10,15,20 etc, then i % 5 == 0. If "i" is not equal to n*x (say i = 6) then i % 5 != 0. So if you have this:

           $i = 0;  
          
          while ( $r = mysql_fetch_array($result) )  
          {
          if ( $i % 5 != 0 )
          { echo <tr></tr>; } // do other code here ++$i;
          }

          Then every 5 times through the loop, php will send "<tr></tr>" to the html for processing, which should create a blank line in your table... but like I said, I'm not that great with tables unless I test it, so replace "<tr></tr>" with whatever would be the best way to make a blank line in your table. Creating a "return" in text just uses <br> or if you want a blank line you can use <br><br> or if a <p> tag is already started, <p></p> would create a blank line without interrupting the rest of your code... If you want to know more about the "%" command, it's generally called "mod" and and "i % 5" divides i by 5 and gives the remainder, so a multiple of 5 has a remainder of zero. I think all that is more correct now, sorry about the confusing response before.

            thank you so much for your response 🙂

            so far, i didnt work , i tryed it but when i try to see the website it doesnt show anything =(

            im not good at tables too, anyone has a good idea how can i show this fields fancy or ordered by 5 in 5 each line ??

              Right, lets try this -one- more time. Only thing you are missing (in theory) is the filler for the <tr> & </tr>:

              $i = 0; 
              
              while ( $r = mysql_fetch_array($result) ) 
              { 
                 if ( $i % 5 != 0 ) 
                 { 
                    echo ( "<tr><td colspan='3'>&nbsp;</td></tr>" );
                 } 
              
                 ++$i; 
              }
              

              That should do it based on the progress that krotkruton made.

                Write a Reply...