xkonidis Posted July 28, 2011 Share Posted July 28, 2011 Hello guys, I'll try and explain in full. I have 2 tables in my database ( extras, extraphotos ). Table extras is holding the title, descr and extraphotos is holding the picname. Both of the have an extra row with the name of fname so i can bind these two together. What I'm trying to do is to read from my DB the Title, Description and all the picname for a gallery that i'm trying to create. Basically it is set up with the Cycle js plugin so I have 1 thumbnail that has extra photos ( picname ). I'm struggling to get arround on this -> <?php $query="SELECT * FROM extras"; $result=mysql_query($query); $num=mysql_numrows($result); $i=0; $j=0; while ($i < $num) { $descr=mysql_result($result,$i,"descr"); $title=mysql_result($result,$i,"title"); $fname=mysql_result($result,$i,"fname"); echo '<div class="image" title="'.$title.'">'; echo '<img src="images/work/th/kolie1.jpg" alt="" />'; echo '<div class="image-label"><span>'.$title.'</span></div>'; echo '</div>'; echo '<div class="cycle">'; $query2="SELECT * FROM extraphotos WHERE fname = " .$fname; $result2=mysql_query($query2); $num2=mysqlnumrows($result2); while ($j < $num2) { $picname=mysql_result($result2,$j,"picname"); echo '<img src="images/work/"'.$picname.'.jpg" width="710px" height="460px" />'; $j++; } echo'</div>'; echo '<div class="info">'; echo '<div class="title"><h2>'.$title.'.</h2></div> '; echo '<div class="descr">'.$descr.'</div>'; echo '<div class="item_url">'.$fname.'</div>'; echo '</div>'; echo '</div>'; $i++; } ?> So basically my first 'while loop' is creating the divs for the thumbnails and it also adds the 'fname' in the item_url div that is needed for onClick function to show the extra images, and i need a second loop so it can create the <img /> tags inside the thumbnails div which is inside the main one. Any suggestions? I was trying to create this with two WHILE loops but no success and no idea how can I do it. Thanks in advance, Xenos K. Quote Link to comment Share on other sites More sharing options...
WebStyles Posted July 28, 2011 Share Posted July 28, 2011 mysqlnumrows() should be mysql_num_rows(). AND mysql_numrows() should be mysql_num_rows(). Quote Link to comment Share on other sites More sharing options...
xkonidis Posted July 28, 2011 Author Share Posted July 28, 2011 Thanks for the reply WebStyles, tired eyes always make mistakes i guess . Again though my my second while loop for the picname returns nothing to me :S. ------------------- Edit 1: I had to edit the second query as well from $query2="SELECT * FROM extraphotos WHERE fname = " .$fname; to $query2="SELECT * FROM extraphotos WHERE fname = '" .$fname."'"; Everything works now for 1 entry, hopefully it will work for more. Thanks again WebStyles, minor mistake, major disaster i guess Kind regards, Xenos K. Quote Link to comment Share on other sites More sharing options...
WebStyles Posted July 28, 2011 Share Posted July 28, 2011 try something like this (untested code, but hopefully will do the same) $query="SELECT * FROM extras"; // title, descr, fname $list = array(); while($result=mysql_query($query){ $list[] = $result; } foreach($list as $l){ echo '<div class="image" title="'.$l['title'].'">'; echo '<img src="images/work/th/kolie1.jpg" alt="" />'; echo '<div class="image-label"><span>'.$l['title'].'</span></div>'; echo '</div>'; echo '<div class="cycle">'; // second query $fname = $l['fname']; $query2="SELECT * FROM extraphotos WHERE fname = '$fname'"; while($result2=mysql_query($query2)){ echo '<img src="images/work/"'.$result2['picname'].'.jpg" width="710px" height="460px" />'; } // close divs echo'</div>'; echo '<div class="info">'; echo '<div class="title"><h2>'.$title.'.</h2></div> '; echo '<div class="descr">'.$descr.'</div>'; echo '<div class="item_url">'.$fname.'</div>'; echo '</div>'; echo '</div>'; } p.s. it's still not a 'brilliant' way to do it... I don't like mysql queries inside of loops like that. Quote Link to comment Share on other sites More sharing options...
WebStyles Posted July 28, 2011 Share Posted July 28, 2011 sorry, just added $fname = $l['fname']; to the code above (forgot about that part) Quote Link to comment Share on other sites More sharing options...
xkonidis Posted July 28, 2011 Author Share Posted July 28, 2011 Thanks for your quick code edit, I copy/pasted it but i'm getting a blank page, tried to work arround it a bit with no luck though. On the other hand with my code, the 1st thumbnail shows correctly with its nested pictures, but after that all other images have no nests, so basically it is like the second while loop works only 1 time ( for the first thumbnail ). Quote Link to comment Share on other sites More sharing options...
xkonidis Posted July 28, 2011 Author Share Posted July 28, 2011 while($result=mysql_query($query){ $list[] = $result; } changed to: while($result=mysql_query($query)){ $list[] = $result; } missing a ")" there but again, no output at all, the rest of the page loads properly but the $list echoes give nothing Quote Link to comment Share on other sites More sharing options...
phpSensei Posted July 28, 2011 Share Posted July 28, 2011 theres no point of making the array...Put it inside the while loop, print mysql_num_rows on $query and tel us the outpu Quote Link to comment Share on other sites More sharing options...
xkonidis Posted July 28, 2011 Author Share Posted July 28, 2011 theres no point of making the array...Put it inside the while loop, print mysql_num_rows on $query and tel us the outpu I didn't understood what you want me to do exactly :S (i started coding like 2 weeks ago and some stuff still seem like mountains, bare with me if you please) kind regards, xenos k. Quote Link to comment Share on other sites More sharing options...
xkonidis Posted July 28, 2011 Author Share Posted July 28, 2011 Problem Solved, I just had to re-clarify that $j=0; after my second loop so it would re-loop when the new thumbnail is added. Thanks for your help guys, really appreciate it. Best regards, Xenos K. Quote Link to comment 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.