PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 31st, 1999, 12:31 PM
powerrush
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Hello,

I'm looping through a query, and inside the while result output, I am trying to loop through a second query (created from the 1st query's row results).

I have checked that both queries return info.

I can see that the 1st while result output works fine, but when I get to the inner while result output, it never returns any rows (nothing in the while loop evaluates).

So, IS it possible to nest one query's output loop within another, or am I doing something wrong?

I can post the example code, incase my description is confusing.

TIA,
Troy

Reply With Quote
  #2  
Old August 31st, 1999, 02:25 PM
rod k
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
No, it's not confusing, but it's hard to say what might be wrong w/o seeing the code. It is certainly possible to do what you want.

Rod

Reply With Quote
  #3  
Old August 31st, 1999, 03:56 PM
powerrush
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Thanks Rod.

This page is called with the url variable
DivisionID equal to 1 (?DivisionID=1).
When running the script, no SQL or PHP errors occur.

BTW, I wrote this code from memory since I don't have access to the original at this time, so please ignore any obvious syntax errors:

<?php

mysql_connect($host,$user,$password);

$DivisionList = mysql_db_query($database,"select * from division order by sortvalue");

if (isset($DivisionID))
{

$GetDivisionSection = mysql_db_query($database,"select section.ID, section.URL from section, sectionprop where section.id = sectionprop.sectionid and section.divisionid = $DivisionID and sectionprop.mainpage != 1 and section.void = 0");

} else {

$DivisionID = 0;

}


while($row = mysql_fetch_array($DivisionList))
{
echo $row["ID"];
echo $row["Graphic"];

if ($DivisionID == $row["ID"])
{

while($row2 = mysql_fetch_array($GetDivisionSection))
{

echo $row2["ID"];
echo $row2["URL"];

}

}

}


?>


- Troy

Reply With Quote
  #4  
Old September 1st, 1999, 06:14 PM
moderator
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
I only took a quick look at the code, so I'm not sure if it is correct or not. But you may want to put echo mysql_error() after any queries you make to the database to ensure that the queries are correct.....normally PHP won't report MySQL errors.

Reply With Quote
  #5  
Old September 1st, 1999, 07:16 PM
powerrush
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
I have checked for MySQL error codes, and
none are returned (error is null, errno is 0). Thanks for your help.

Reply With Quote
  #6  
Old September 2nd, 1999, 02:48 PM
rod k
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
I'm at a loss. I don't see anything in the code that should be causing a problem. Since you say you wrote it from memory, is it possible there is an error in the original that you don't realize is there? I mean your logic is fine, could be something as simple as a missing bracket.

Rod

Reply With Quote
  #7  
Old September 2nd, 1999, 05:16 PM
powerrush
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
I will post the exact code when I get my hands on it... thanks for all your help!

Reply With Quote
  #8  
Old September 2nd, 1999, 06:55 PM
rod k
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Just noticed something. You need to alias the results returned in the second query.
Try this:

$GetDivisionSection = mysql_db_query($database,"select section.ID as ID, section.URL as URL from section, sectionprop where
section.id = sectionprop.sectionid and section.divisionid = $DivisionID and sectionprop.mainpage != 1 and section.void
= 0");

Reply With Quote
  #9  
Old September 2nd, 1999, 08:24 PM
powerrush
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Well, I tried using the SQL aliases with no luck... here is the exact code I am running:

-----------

<?php

$database = "mydb";

$cn = mysql_connect( "localhost", "root", $password);
$db = mysql_select_db($database);

include "intranet/common/divisionlist.sql";

if (isset($DivisionID))
{

$GetDivisionSections = mysql_query("SELECT section.Name AS Name,
section.ID AS ID, SectionProp.UseWrapper, section.URL AS URL
FROM section, SectionProp
WHERE section.ID = SectionProp.SectionID
AND section.DivisionID = $DivisionID
AND SectionProp.MainPage != 1
AND section.Void = 0");


} else {

$DivisionID = 0;

}

?>

<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>

<BODY MARGINWIDTH=0 MARGINHEIGHT=0 TOPMARGIN=0 LEFTMARGIN=0
BACKGROUND="/intranet/images/leftbg.gif" TEXT="White" LINK="WHITE"
VLINK="WHITE" ALINK="WHITE">

<TABLE BORDER=0 CELLSPACING="0" CELLPADDING="0" WIDTH=145>

<?php

if ($DivisionList)
{

while($row = mysql_fetch_array($DivisionList))
{

echo "<TR><TD><A
HREF='left.php3?DivisionID=" . $row[ "ID"] . "'><IMG
BORDER=0 SRC=/intranet/images/" . $row[ "Graphic"]
. "></A></TD></TR>";

if ($DivisionID == $row[ "ID"])
{

echo "<TR>
<TD><font face='Tahoma, Arial, Helvetica' size='-2'>";

while($row2 = mysql_fetch_array($GetDivisionSections))
{

echo "&nbsp;&nbsp;<A HREF='";

if ($row2[ "UseWrapper"] == 1)
{
echo "wrapper.php3?SectionID=" . $row2[ "ID"] . "'";
} else {
echo $row2[ "URL"] . "'";
}

echo "TARGET='Main'>" . $row2[ "Name"] . "</A><BR>
&nbsp;</FONT></TD>
</TR>";

}


}

}

}

?>

</TABLE>

</BODY>
</HTML>


-------


Thanx,
Troy

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Nesting result loops within result loops possible?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT