Jump to content


PHP Nesting?

  • Please log in to reply
1 reply to this topic

#1 jon_we4

  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 28 May 2006 - 05:24 AM

I am not the most fluent with PHP but I am with other languages ...

What I am trying to do is one query and list out the info, but for each listing it needs its own query. I may be going about it the wrong way (well obviously since its not working).

function getlist()
         global $db;
         $list1 = $db->query_read("
                 SELECT          *
                 FROM            top_list
                 ORDER BY       id
          if ($db->num_rows($classlist) == 0) 
                  return NULL; 
        while($list1row = $db->fetch_array($list1)) {
       $list2 = $db->query_read("

                 SELECT          *
                 FROM            top_list_info
                 WHERE listid = $list1row[id]
                 ORDER BY        id

  $retStr .= "
<td class=\"tcat\" colspan=\"6\"><b>$classrow[class_name]</b></td>
<td class=\"alt1\" colspan=\"6\">$classrow[class_desc]</td>
<td class=\"alt2\" width=\"10%\"><div class=\"smallfont\"><b>Username</b></div></td><td class=\"alt2\"><div class=\"smallfont\"><b>option1</b></div></td><td class=\"alt2\"><div class=\"smallfont\"><b>option2</b></div></td><td class=\"alt2\"><div class=\"smallfont\"><b>option3</b></div></td><td class=\"alt2\" ><div class=\"smallfont\"><b>option4</b></div></td><td class=\"alt2\" width=\"45%\"><div class=\"smallfont\"><b>Notes</b></div></td>



         return "$retStr";
$timelist = getlist();

This functions fine, but I wanted to add another "while" loop thru the second query but it doesnt like nesting it.

Can anyone get me a step into the right direction?

#2 trq

  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 28 May 2006 - 06:15 AM

Surely this is a job for an sql JOIN? Recursive database queries are VERY inificient.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users