coolphpdude Posted April 19, 2008 Share Posted April 19, 2008 hey there, im am trying to output thumbnails in a while loop. Normally what i would do for this is output in a table as below echo "<table cellspacing='1' cellpadding='1' align=center style='border-collapse: collapse'>\n"; echo "<caption><h2><font color=blue></font></h2></caption>\n"; echo "<tr><th colspan='2'>Lsson</th></tr>\n"; while ($lesson_row = mysql_fetch_array($lesson_query)) { echo"<tr>"; echo"<td><font face='arial'><font color='#648CC8'>*</font></td>"; printf("<td>%s</td>\n", $location_row["lesson_assignment"]); echo"</tr>"; } echo "</table>\n"; However, i have a new table for each assignment (there are 3 assignments, therefore 3 assignment tables). the tables consist of these fields... (with the crap taken out) Table 1 (Assignment_1): Lesson_id, assignment_picture Table 2 (Assignment_2): Lesson_id, assignment_picture Table 3 (Assignment_3): Lesson_id, assignment_picture The lesson_id is art and the student can upload as many of their pics as they wish. so just for arguments for assignment_1 they upload 4 pictures (the upload works and a path to the thumbnail is added to the assignment_picture field). For assignment_2 the user uploads 5 pictures and for assignment_3 the user uploads 2 pictures. These ammounts can be completely random but i need to output however many thumbnails the user has uploaded to a table. The table is restricted in width to 3 columns but can hav as many rows as needed. If i cant predict how many pictures any student will upload for any of the assignments how can i get all of these thumbnails to appear in a table seemlessly without any gaps between the tables cells?? If anybody could help i would really appreciate it!!! Link to comment https://forums.phpfreaks.com/topic/101851-outputting-thumbnails-in-a-while-loop/ Share on other sites More sharing options...
delickate Posted April 19, 2008 Share Posted April 19, 2008 hey buddy take this is a complete solution for that <form method="post" action="link.php?products_id=$product_info['products_id']"> <table> <? $queryString = ''; $sql="select * from ".TABLE_PRODUCTS; $product_info_query = tep_db_query($sql); while ($product_info = tep_db_fetch_array($product_info_query)) { ?> <tr > <td align="left" width="400"> <? echo $product_info['products_id']; $pid=$product_info['products_id']; ?> <img src="images/<? echo $product_info['products_image']; ?>" width="100" height="100"/><br> <? echo $product_info['products_model']; ?><br> <? echo $product_info['products_price']; ?> </td> <td align="right" valign="bottom"><input type="submit" value="Add to Cart" name="btnSubmit"></td> <? } ?> </table> </form> Link to comment https://forums.phpfreaks.com/topic/101851-outputting-thumbnails-in-a-while-loop/#findComment-521254 Share on other sites More sharing options...
coolphpdude Posted April 19, 2008 Author Share Posted April 19, 2008 i have to go out but i'll check through that later. Cheers! Link to comment https://forums.phpfreaks.com/topic/101851-outputting-thumbnails-in-a-while-loop/#findComment-521262 Share on other sites More sharing options...
coolphpdude Posted April 21, 2008 Author Share Posted April 21, 2008 Hey, sorry but i dont understand that. Can any1 help?? Link to comment https://forums.phpfreaks.com/topic/101851-outputting-thumbnails-in-a-while-loop/#findComment-522721 Share on other sites More sharing options...
coolphpdude Posted April 21, 2008 Author Share Posted April 21, 2008 is there a way of including more than one search query in an array?? Link to comment https://forums.phpfreaks.com/topic/101851-outputting-thumbnails-in-a-while-loop/#findComment-522732 Share on other sites More sharing options...
craygo Posted April 21, 2008 Share Posted April 21, 2008 Try this http://www.phpfreaks.com/forums/index.php/topic,191541.0.html Ray Link to comment https://forums.phpfreaks.com/topic/101851-outputting-thumbnails-in-a-while-loop/#findComment-522749 Share on other sites More sharing options...
coolphpdude Posted April 21, 2008 Author Share Posted April 21, 2008 hi ray, thanks but ive got the resize all working perfect. ITs actually a problem outputting all of my thumbnails for 1 specific user because the location of the thumbnails are spread over 3 different tables. so where usually i would do it by... $pictures_ass1_result = mysql_query("SELECT * FROM assignment_1 WHERE lesson_id = 'art'"); $pictures_ass2_result = mysql_query("SELECT * FROM assignment_2 WHERE lesson_id = 'art'"); $pictures_ass3_result = mysql_query("SELECT * FROM assignment_3 WHERE lesson_id = 'art'"); echo "<table cellspacing='1' cellpadding='1' align=center style='border-collapse: collapse'>\n"; while ($picture_ass1_row = mysql_fetch_array($picture_ass1_result)) { echo"<tr>"; echo"<td><font face='arial'><font color='#648CC8'>*</font></td>"; printf("<td>%s</td>\n", $picture_ass1_row["assignment_picture"]); echo"</tr>"; } echo "</table>\n"; well i need one table continuesly outputting all thumbnails from over the 3 tables. does this make sense? Link to comment https://forums.phpfreaks.com/topic/101851-outputting-thumbnails-in-a-while-loop/#findComment-522757 Share on other sites More sharing options...
craygo Posted April 21, 2008 Share Posted April 21, 2008 Create a temporary table. <?php $sql = "CREATE TEMPORARY TABLE images (images VARCHAR(50))"; $res = mysql_query($sql) or die(mysql_error()); $pictures_ass1_result = mysql_query("INSERT INTO images (SELECT image FROM assignment_1 WHERE lesson_id = 'art')"); $pictures_ass2_result = mysql_query("INSERT INTO images (SELECT image FROM assignment_2 WHERE lesson_id = 'art')"); $pictures_ass3_result = mysql_query("INSERT INTO images (SELECT image FROM assignment_3 WHERE lesson_id = 'art')"); $pictures_sql = "SELECT * FROM images"; $picture_result = mysql_query($pictures_sql) or die(mysql_error()); echo "<table cellspacing='1' cellpadding='1' align=center style='border-collapse: collapse'>\n"; while ($pictures = mysql_fetch_array($picture_result)) { echo"<tr>"; echo"<td><font face='arial'><font color='#648CC8'>*</font></td>"; printf("<td>%s</td>\n", $pictures["images"]); echo"</tr>"; } echo "</table>\n"; ?> Now all your images will be in one table. Ray Link to comment https://forums.phpfreaks.com/topic/101851-outputting-thumbnails-in-a-while-loop/#findComment-522775 Share on other sites More sharing options...
coolphpdude Posted April 21, 2008 Author Share Posted April 21, 2008 that sounds like exactly what i am after. Does the table delete itself after use? Would it slow down my database if 700 users were viewing it and it had to create a temporary table for every user viewing that page?? Link to comment https://forums.phpfreaks.com/topic/101851-outputting-thumbnails-in-a-while-loop/#findComment-522800 Share on other sites More sharing options...
craygo Posted April 21, 2008 Share Posted April 21, 2008 it shouldn't slow things down, but if you will be having ALOT of traffic then you may want to add something to the name. <?php $user = $_POST['user']; $sql = "CREATE TEMPORARY TABLE images".$user." (images VARCHAR(50))"; $res = mysql_query($sql) or die(mysql_error()); $pictures_ass1_result = mysql_query("INSERT INTO images".$user." (SELECT image FROM assignment_1 WHERE lesson_id = 'art')"); $pictures_ass2_result = mysql_query("INSERT INTO images".$user." (SELECT image FROM assignment_2 WHERE lesson_id = 'art')"); $pictures_ass3_result = mysql_query("INSERT INTO images".$user." (SELECT image FROM assignment_3 WHERE lesson_id = 'art')"); $pictures_sql = "SELECT * FROM images".$user; $picture_result = mysql_query($pictures_sql) or die(mysql_error()); echo "<table cellspacing='1' cellpadding='1' align=center style='border-collapse: collapse'>\n"; while ($pictures = mysql_fetch_array($picture_result)) { echo"<tr>"; echo"<td><font face='arial'><font color='#648CC8'>*</font></td>"; printf("<td>%s</td>\n", $pictures["images"]); echo"</tr>"; } echo "</table>\n"; ?> A temporary table will remain until the connection is closed. So you can add mysql_close() to the bottom to make sure it is gone. Ray Link to comment https://forums.phpfreaks.com/topic/101851-outputting-thumbnails-in-a-while-loop/#findComment-522810 Share on other sites More sharing options...
coolphpdude Posted April 21, 2008 Author Share Posted April 21, 2008 cheers i'll give it ago. thanks again mate Link to comment https://forums.phpfreaks.com/topic/101851-outputting-thumbnails-in-a-while-loop/#findComment-522812 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.