chanfuterboy Posted August 9, 2009 Share Posted August 9, 2009 hi, i try and try dont come with it, need to let picture display in a row of 3. help me plz $cols = 3; // creating table inorder to use it for columns. echo "<table width=100% border ='1' bordercolor='#3399FF' cellpadding='10' cellspacing='6'> <tr>"; //open the dir where files were uploaded inside. // create a loop and define a variable called ($file) // to hold the value of file name located in the directory . $i =1; //define a variable to hold everthing that will be printed in table's columns. $all_stuff = "File name:<b> $location1</b> <hr size=1> <img src=\"images/$location\" border=\"0\" width=\"150\"></a> <br>article name: $location1 <br>Article color: $location2"; //divide the loop ($i) and ($cols) if the result is integer //then print column number 1. if (is_int($i / $cols)){ echo "<td align='center' valign='top' bgcolor='#F2F2F2'>$all_stuff</td></tr><tr>"; }else{ //else then print column number 2 etc for the next loop. echo "<td align='center' valign='top' bgcolor='#F2F2F2'>$all_stuff</td>"; } //add only 1 for the loop ($i). $i++; }//end while loop closedir($opendir); clearstatcache(); // print the rest of table. echo "</tr> </table>"; Quote Link to comment https://forums.phpfreaks.com/topic/169423-make-picture-display-in-a-row/ Share on other sites More sharing options...
MadTechie Posted August 9, 2009 Share Posted August 9, 2009 #1 use code tags #2 what's the problem ? Quote Link to comment https://forums.phpfreaks.com/topic/169423-make-picture-display-in-a-row/#findComment-893896 Share on other sites More sharing options...
chanfuterboy Posted August 9, 2009 Author Share Posted August 9, 2009 hi It display the pictures in a column and i want it to show in a row. 3 aside then next column 3 aside like that. Quote Link to comment https://forums.phpfreaks.com/topic/169423-make-picture-display-in-a-row/#findComment-893897 Share on other sites More sharing options...
chanfuterboy Posted August 9, 2009 Author Share Posted August 9, 2009 let me explain in details. the page now print the latest 6 uploaded pictures . the pictures should display in 2 rows with 3 columns. But i get now 6 picture in 1 column. i know somewhere in the scripts i need to edit but i dont know where. someone can help me if (is_int($i / $cols)){ echo "<td align='center' valign='top' bgcolor='#F2F2F2'>$all_stuff</td></tr><tr>"; }else{ //else then print column number 2 etc for the next loop. echo " <td align='center' valign='top' bgcolor='#F2F2F2'>$all_stuff</td>"; } //add only 1 for the loop ($i). $i++; Quote Link to comment https://forums.phpfreaks.com/topic/169423-make-picture-display-in-a-row/#findComment-893905 Share on other sites More sharing options...
The Little Guy Posted August 9, 2009 Share Posted August 9, 2009 take a peek at this code: http://beta.phpsnips.com/snippet.php?id=53 It looks like it is something you want... Change line 4 to the number of columns you want, currently it is set to 4 columns. Quote Link to comment https://forums.phpfreaks.com/topic/169423-make-picture-display-in-a-row/#findComment-893919 Share on other sites More sharing options...
chanfuterboy Posted August 9, 2009 Author Share Posted August 9, 2009 hi, THe site help me put them in 1 row instead as previous in 1 column. Now help me with: when i have 6 picture to display ( limit 0,6) it display 2 row with 3 picture in each row. this is the new code. $tblWidth = 4; $col= 2; // Make your query $sql = mysql_query("SELECT * FROM members Limit 1,3"); $i = 1; echo "<br><br><br><br><table width=100% border ='1' bordercolor='#3399FF' cellpadding='10' cellspacing='16'> <tr>"; // Check to see if any results were returned if(mysql_num_rows($sql) > 0){ echo ''; // Loop through the results while($row = mysql_fetch_array($sql)){ $location = $row['picture']; $location1 = $row['articlename']; $location2 = $row['articlecolor']; $all_stuff = "<b>File name</b>:<b><font face='Tahoma' size='2'>$location1</font></b> <hr size=1> <img src='images/$location' width='100' height='100'></a> <br>article name: $location1 <br>Article color: $location2"; if($i == $tblWidth && $i / $col){ echo "<td align='center' valign='top' bgcolor='#F2F2F2'>$all_stuff</td>"; }else{ //else then print column number 2 etc for the next loop. echo "<td align='center' valign='top' bgcolor='#F2F2F2'>$all_stuff</td>"; } //add only 1 for the loop ($i). $i++; Quote Link to comment https://forums.phpfreaks.com/topic/169423-make-picture-display-in-a-row/#findComment-894124 Share on other sites More sharing options...
chanfuterboy Posted August 9, 2009 Author Share Posted August 9, 2009 hi, THe site help me put them in 1 row instead as previous in 1 column. Now help me with: when i have 6 picture to display ( limit 0,6) it display 2 row with 3 picture in each row. this is the new code. $tblWidth = 4; $col= 2; // Make your query $sql = mysql_query("SELECT * FROM members Limit 0.6"); $i = 1; echo "<br><br><br><br><table width=100% border ='1' bordercolor='#3399FF' cellpadding='10' cellspacing='16'> <tr>"; // Check to see if any results were returned if(mysql_num_rows($sql) > 0){ echo ''; // Loop through the results while($row = mysql_fetch_array($sql)){ $location = $row['picture']; $location1 = $row['articlename']; $location2 = $row['articlecolor']; $all_stuff = "<b>File name</b>:<b><font face='Tahoma' size='2'>$location1</font></b> <hr size=1> <img src='images/$location' width='100' height='100'></a> <br>article name: $location1 <br>Article color: $location2"; if($i == $tblWidth && $i / $col){ echo "<td align='center' valign='top' bgcolor='#F2F2F2'>$all_stuff</td>"; }else{ //else then print column number 2 etc for the next loop. echo "<td align='center' valign='top' bgcolor='#F2F2F2'>$all_stuff</td>"; } //add only 1 for the loop ($i). $i++; Quote Link to comment https://forums.phpfreaks.com/topic/169423-make-picture-display-in-a-row/#findComment-894127 Share on other sites More sharing options...
chanfuterboy Posted August 9, 2009 Author Share Posted August 9, 2009 Here is a picture of what i mean. need help Quote Link to comment https://forums.phpfreaks.com/topic/169423-make-picture-display-in-a-row/#findComment-894136 Share on other sites More sharing options...
MadTechie Posted August 9, 2009 Share Posted August 9, 2009 #1 use code tags and what's your latest code Quote Link to comment https://forums.phpfreaks.com/topic/169423-make-picture-display-in-a-row/#findComment-894229 Share on other sites More sharing options...
tjhilder Posted August 9, 2009 Share Posted August 9, 2009 there's an easier way, but it means not using tables (Horrah!) if you style a page based on CSS you can use the CSS to display them how you want. example HTML: <div id="gallery"> <h6>img</h6> <h6>img</h6> <h6>img</h6> <h6>img</h6> <h6>img</h6> <h6>img</h6> <h6>img</h6> <h6>img</h6> <h6>img</h6> </div> then the CSS #gallery { padding : 0; width : 600px; height : auto; display : block; float : left; } #gallery h6 { width : 200px; height : 200px; margin : 0; display : block; float : left; } that will display them 3 in a row, for two rows (obviously change your CSS width/height to suite your needs. means you don't need to do anything special with your php code. Quote Link to comment https://forums.phpfreaks.com/topic/169423-make-picture-display-in-a-row/#findComment-894366 Share on other sites More sharing options...
play_ Posted August 9, 2009 Share Posted August 9, 2009 Try this echo '<table border="1"> <tr>'; for( $i = 0; $i < 6; $i++ ) { if( ($i % 3) == 0 ) { echo '</tr><tr>'; } echo '<td><img width="100" height="100" src="http://bit.ly/ZSu4K" /></td>'; } echo '</table>';[/code[ it gives Quote Link to comment https://forums.phpfreaks.com/topic/169423-make-picture-display-in-a-row/#findComment-894381 Share on other sites More sharing options...
Gamerz Posted August 12, 2009 Share Posted August 12, 2009 Ok, my code's now: <?php $path = "uploads"; // Open the folder $dir_handle = @opendir($path) or die("Unable to open $path"); // Loop through the files while ($file = readdir($dir_handle)) { echo '<table border="1"> <tr>'; for( $i = 0; $i < 3; $i++ ) { if( ($i % 3) == 0 ) { echo '</tr><tr>'; } if($file == "." || $file == ".." || $file == "jhey.js" || $file == "uploaded.php" || $file == "index.php" ) continue; echo "<td><center><img src =\"$file\" width=\"96\" height=\"96\"><br /><br></td>"; } echo '</table>'; } // Close closedir($dir_handle); ?> </center> When I execute that code, it displays the same images in one row, then another image in the second row...and so on.. For a screenshot: Quote Link to comment https://forums.phpfreaks.com/topic/169423-make-picture-display-in-a-row/#findComment-896778 Share on other sites More sharing options...
play_ Posted August 12, 2009 Share Posted August 12, 2009 Not supposed to use the while loop with the for loop. here's a code that will work <?php $path = "./uploads"; // Open the folder $dir_handle = @opendir($path) or die("Unable to open $path"); $i = 0; // extensions allowed $allowed = array('jpg', 'png', 'gif', 'bmp'); echo '<table border="1"> <tr>'; // Loop through the files while ($file = readdir($dir_handle)) { $ext = end(explode('.', $file)); // if $file is not a dir and has an allowed extension, show. if( !is_dir($file) && in_array($ext, $allowed) ) { // needed to display 3 images pew row echo ( ($i % 3) == 0 ) ? '</tr><tr>' : null; // output image echo "<td><center><img src =\"$path/$file\" width=\"96\" height=\"96\"><br /><br></td>"; $i++; } } echo '</table>'; // Close handle closedir($dir_handle); ?> Quote Link to comment https://forums.phpfreaks.com/topic/169423-make-picture-display-in-a-row/#findComment-896827 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.