Re: [PHPLIB] query inside a query From: Nathaniel Price (seoman <email protected>)
Date: 01/31/00

You need to create another instance of the DB_MyThreads class inside the
loop and run the new query through that, i.e:

$db = new DB_MyThreads;
$ndb = new DB_MyThreads; #second instance of DB class
$db->query("some query");
while ($db->next_record()) {
    $ndb->query("some other query");
    #do stuff with this query^
}

Otherwise you make the old instance ($db) forget about the previous query
once you run a new query through it (which you are doing inside the loop).
And since you need the information from the previous query, that can cause
bad things to happen.
______________________________________
Nathaniel Price <seoman <email protected>>
"Who is General Failure and why is he reading my hard disk?"

----- Original Message -----
From: Curtis, Josh <CurtisJ <email protected>>
To: <phplib <email protected>>
Sent: Monday, January 31, 2000 4:39 PM
Subject: [PHPLIB] query inside a query

> I need some help...
>
> I am trying to do a query inside a query and it returns no data. It does
> work without the sub query.
> php 3.0.11
> phplib 7.2
>
> Example:
>
> include( "db_mysql.inc");
> class DB_MyThreads extends DB_Sql {
> var $Host = "localhost";
> var $Database = "sundown";
> var $User = "everyone";
> var $Password = "";
> }
>
> $db = new DB_MyThreads;
> $db->query( "SELECT * FROM category ORDER BY 'title'");
> while ($db->next_record())
> {
>
> $query_new = "SELECT * FROM category WHERE
under='".$db->f(cat)."'
> ORDER BY ttlinks DESC LIMIT 0,2";
> $db->query($query_new);
> while ($db->next_record())
> {
> $links_under .= $db->f(cat) . ":". $db->f(title);
> }
>
> $content .= $db->f(cat) . "|". $db->f(title). "|". $db->f(ttlinks). "|".
> $db->f(info) . "|$links_under";
> }
>
> --
> Joshua Curtis
> Production Systems Administrator
> Cadmus Professional Communications
> Science Press Division
> 300 West Chestnut Street
> Ephrata, PA 17522
> 717-738-9363 - voice
> 717-738-9416 - fax
> curtisj <email protected>
> -
> PHP3 Base Library Mailing List. Send messages to <phplib <email protected>>.
> To unsubscribe, send "unsubscribe" to <phplib-request <email protected>> in
> the body, not the subject, of your message.
>

-
PHP3 Base Library Mailing List. Send messages to <phplib <email protected>>.
To unsubscribe, send "unsubscribe" to <phplib-request <email protected>> in
the body, not the subject, of your message.