473,385 Members | 1,707 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Nested WHILE loops?

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 ->

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. $query="SELECT * FROM  extras";
  4. $result=mysql_query($query);
  5. $num=mysql_numrows($result);
  6. $i=0;
  7. $j=0;
  8.  
  9.   while ($i < $num) {
  10.  
  11.     $descr=mysql_result($result,$i,"descr");
  12.     $title=mysql_result($result,$i,"title");
  13.     $fname=mysql_result($result,$i,"fname");                         
  14.     echo '<div class="image" title="'.$title.'">';
  15.     echo '<img src="http://bytes.com/images/work/th/kolie1.jpg" alt="" />';
  16.     echo '<div class="image-label"><span>'.$title.'</span></div>';
  17.     echo '</div>';
  18.     echo '<div class="cycle">';
  19.  
  20. $query2="SELECT * FROM extraphotos WHERE fname = " .$fname;
  21. $result2=mysql_query($query2);
  22. $num2=mysqlnumrows($result2);
  23.  
  24. while ($j < $num2) {
  25.     $picname=mysql_result($result2,$j,"picname");    
  26.     echo '<img src="http://bytes.com/images/work/"'.$picname.'.jpg" width="710px" height="460px" />';
  27.     $j++;
  28. }  
  29.     echo'</div>';
  30.     echo '<div class="info">';
  31.     echo '<div class="title"><h2>'.$title.'.</h2></div> ';
  32.     echo '<div class="descr">'.$descr.'</div>';
  33.     echo '<div class="item_url">'.$fname.'</div>';
  34.     echo '</div>';
  35.     echo '</div>';
  36.     $i++;
  37. }
  38.  
  39. ?>
So basically my first 'while loop' is creating the divs for the thumbnails, and i need a second 'while loop' so it can create the extra photo divs inside the main one.

Any suggestions? I started coding like 2 weeks ago and I thought it would be easier. ^_^

Thanks in advance,
Xenos K.
Jul 28 '11 #1
2 2169
I think you don't need that 2nd while loop. Just use SELECT for your photos table with WHERE condition pointing to proper photo. Try to remove while loop,but leave the code inside it.
Jul 28 '11 #2
Rabbit
12,516 Expert Mod 8TB
If fname is a string, then you need to delimit it as such in your query using single quotes.
Jul 28 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Oleg Leschov | last post by:
Could there be means of exiting nested loops in python? something similar to labelled loops in perl.. I consider it irrating to have to make a flag for sole purpose of checking it after loop if...
0
by: Xah Lee | last post by:
# -*- coding: utf-8 -*- # Python # David Eppstein of the Geometry Junkyard fame gave this elegant # version for returing all possible pairs from a range of n numbers. def combo2(n): return...
46
by: Neptune | last post by:
Hello. I am working my way through Zhang's "Teach yourself C in 24 hrs (2e)" (Sam's series), and for nested loops, he writes (p116) "It's often necessary to create a loop even when you are...
17
by: Peter Olcott | last post by:
http://www.tommti-systems.de/go.html?http://www.tommti-systems.de/main-Dateien/reviews/languages/benchmarks.html Why is C# 500% slower than C++ on Nested Loops ??? Will this problem be solved in...
10
by: Roshawn | last post by:
Hi, I am experimenting with nested For...Next loops. My code looks like this: Dim i as Byte Dim itm as Byte For i = 0 to 9 For itm = 0 to 9 'code omitted
77
by: Peter Olcott | last post by:
http://www.tommti-systems.de/go.html?http://www.tommti-systems.de/main-Dateien/reviews/languages/benchmarks.html The above link shows that C# is 450% slower on something as simple as a nested loop....
3
by: tzuriel | last post by:
Hello all, I think nested loops will do what I want, but I can't seem to get them right. I have two tables, members and casts. I run a query as follows: $sql_query="SELECT DISTINCT...
3
by: Luna Moon | last post by:
My friend has three nested loops, each has 10000, 1000, 100 iterations, respectively. What should be the most efficient way of layout out the three nested loops? for (i=0; i<10000; i++) for...
4
by: toddlahman | last post by:
I am using two while loops that are nested. The first loop (post name) returns the full column of results, but the second (post modified) only returns the first row of the column. Is there another...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.