phpbeginner Posted October 10, 2006 Share Posted October 10, 2006 What I am trying to do is show a row of 4 images across, start a new row, and then end the table when there is no more to display from my DB. Here is a raw example of my code and with no luck ..... [sup]print "<div align=\"center\"> <table width=\"100%\" cellspacing=\"2\" cellpadding=\"5\" bordercolordark=\"#000000\" bordercolorlight=\"#000000\"> <tr bordercolor=\"#FFFFFF\">" ; print" <td width=\"100\"> <div align=\"center\"><font face=\"Arial, Helvetica, sans-serif\" size=\"2\">";if (file_exists("$#############")){print("<img src=\"#################"><br>$a_row[######]</td>");}else{print"</td> </tr> </table>";}print"<br>"; }[/sup] Link to comment https://forums.phpfreaks.com/topic/23571-tables-tables/ Share on other sites More sharing options...
GremlinP1R Posted October 10, 2006 Share Posted October 10, 2006 You lost me there with your coding.Not sure how the pics work but I'm sure its almost the same as info.Try this$Pic = [color=red]pathname[/color];echo"<tr><td>";echo"$pic";echo"</td><td>";echo"$pic2";echo"</td><td>";echo"$pic3";echo"</td><td>";echo"$pic4";echo"</td></tr>";Okay dont need all the echo's Link to comment https://forums.phpfreaks.com/topic/23571-tables-tables/#findComment-107009 Share on other sites More sharing options...
phpbeginner Posted October 10, 2006 Author Share Posted October 10, 2006 Here's how the pics work. When I do add somethign to the database and then upload the pics, it just stores the link to the absolute path of the image for that record. So this part of the code would appear as below: if (file_exists("$abpath/path/to/image/$a_row[id]-1.jpg")) Link to comment https://forums.phpfreaks.com/topic/23571-tables-tables/#findComment-107012 Share on other sites More sharing options...
GremlinP1R Posted October 10, 2006 Share Posted October 10, 2006 Okay well then this sould work.$result= mysql_query("SELECT * FROM [color=red]table[/color]");while ($row = mysql_fecth_array($result)){echo "<tr><td>$row['[color=red]row in tabels name[/color]'</td><td>[color=red]just repeat, when at number 4 close the line[/color]</td></tr>";}Okay that sould work! Link to comment https://forums.phpfreaks.com/topic/23571-tables-tables/#findComment-107019 Share on other sites More sharing options...
phpbeginner Posted October 10, 2006 Author Share Posted October 10, 2006 Ahh, that's what I am doing but thought there was a better way of doing this. What if I have 100 items to display......thats a lot of code ! Link to comment https://forums.phpfreaks.com/topic/23571-tables-tables/#findComment-107020 Share on other sites More sharing options...
GremlinP1R Posted October 10, 2006 Share Posted October 10, 2006 okay well if you tell him <tr><td>$row</td><tr> in side of a table colum it will repeat for all until there are no more. But that will put one on each line Link to comment https://forums.phpfreaks.com/topic/23571-tables-tables/#findComment-107025 Share on other sites More sharing options...
phpbeginner Posted October 10, 2006 Author Share Posted October 10, 2006 Yes, I realize that......I have done this.Does anyone know from the above script how I can create a table with an X # of thumbnails, showing rows of 4 and continuing until there are no more to display ? Thanks in Advance Link to comment https://forums.phpfreaks.com/topic/23571-tables-tables/#findComment-107030 Share on other sites More sharing options...
SharkBait Posted October 10, 2006 Share Posted October 10, 2006 When I use a table to do this with images and I want to break at the end of 4 images I keep a counter and then check the Modulus to make sure there is no remainder and then break on that.[code]<?php// Images in an array or database whatever)$images = aray("pic1", "pic2", "pic3", "pic4", "pic5");echo "<table border=\"1\">";$i = 1;// Loop through the array for imagesforeach($images as $filename) { // If i did this right, then if there is not a remainer then add the TR tags to drop to a new row. if($i % 4 <> 0) echo "</tr><tr>\n"; // Display the image in a table cell echo "<td><img sr=\"{$filename}\" /></td>"; // Increment counter $i++;}?>[/code]Now I might have it a bit wrong, but the idea is there :) Link to comment https://forums.phpfreaks.com/topic/23571-tables-tables/#findComment-107038 Share on other sites More sharing options...
phpbeginner Posted October 10, 2006 Author Share Posted October 10, 2006 That looks like what I am looking for ! Appreciate it ! Link to comment https://forums.phpfreaks.com/topic/23571-tables-tables/#findComment-107041 Share on other sites More sharing options...
phpbeginner Posted October 10, 2006 Author Share Posted October 10, 2006 Sheeet ! I'm sure I erred somewhere.....this is what I ended up with but it displays 1 image per row.[code]{ echo "<div align=\"center\"> <table width=\"100%\" cellspacing=\"2\" cellpadding=\"5\" bordercolordark=\"#000000\" bordercolorlight=\"#000000\">";$i = 1;if($i % 4 <> 0) echo "</tr><tr>\n"; echo" <td width=\"100\"> <div align=\"center\"><font face=\"Arial, Helvetica, sans-serif\" size=\"2\">";if (file_exists("$abpath/path to image/$a_row[id]-top.jpg")){echo("<img src=\"http://$domain/path to image/$a_row[id]-top.jpg\" width=\"100\"><br>$a_row[#####]</td>");$i++;}}[/code] Link to comment https://forums.phpfreaks.com/topic/23571-tables-tables/#findComment-107056 Share on other sites More sharing options...
phpbeginner Posted October 10, 2006 Author Share Posted October 10, 2006 Anyone have any ideas on this ? Thanks In Advance ! Link to comment https://forums.phpfreaks.com/topic/23571-tables-tables/#findComment-107105 Share on other sites More sharing options...
phpbeginner Posted October 10, 2006 Author Share Posted October 10, 2006 anyone ? Link to comment https://forums.phpfreaks.com/topic/23571-tables-tables/#findComment-107163 Share on other sites More sharing options...
Firemankurt Posted October 10, 2006 Share Posted October 10, 2006 <?php// Query above already done echo "<div align=\"center\"> <table width=\"100%\" cellspacing=\"2\" cellpadding=\"5\" bordercolordark=\"#000000\" bordercolorlight=\"#000000\">";$i = 0;echo "<tr>\n";while ($a_row= mysql_fetch_row($Result)){ if($i == 4) { echo "<tr>\n"; $i = 0; }echo"<td width=\"100\"> <div align=\"center\"><font face=\"Arial, Helvetica, sans-serif\" size=\"2\">";if (file_exists("$abpath/path to image/$a_row[id]-top.jpg")){echo("<img src=\"http://$domain/path to image/$a_row[id]-top.jpg\" width=\"100\"><br>$a_row[#####]</td>");$i++;}}echo "</table>";// More php...?> Link to comment https://forums.phpfreaks.com/topic/23571-tables-tables/#findComment-107216 Share on other sites More sharing options...
phpbeginner Posted October 11, 2006 Author Share Posted October 11, 2006 Hmmmm.....really lost now as nothing is displaying and no errors. Link to comment https://forums.phpfreaks.com/topic/23571-tables-tables/#findComment-107235 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.