Topic: Query Loops

Does a query in a while loop count as one query or several?

Example:

$sql=$db->query("SELECT blah FROM blah WHERE blah='blah' DESC LIMIT 10");

while ($db->query($sql)){
//do something
}

echo $db->get_num_queries();

Would that return 10, or 1?

I don't HAVE a signature, ok?

Re: Query Loops

it must be 10, but why would you ever want to do that?

3

Re: Query Loops

Doesn't make sense to me.
The result of

$sql=$db->query("SELECT blah FROM blah WHERE blah='blah' DESC LIMIT 10");

will be an array called $sql holding another array with single values like
0=>'banana',1=>'apple',2=>'peach',3=>'dogshit'

It will not output an array with proper sql statements to use in your while ($db->query($sql)) loop.
And if it does shouldn't the result of
$db->get_num_queries()  be 11 ? wink

The German PunBB Site:
PunBB-forum.de

Re: Query Loops

Connorhd wrote:

it must be 10, but why would you ever want to do that?

PunBB does that to spit out the posts in viewtopic, silly! tongue

The query was not a functional one but rather an example.

I don't HAVE a signature, ok?

Re: Query Loops

it most certainly does not

Re: Query Loops

I think you've mistaken $db->fetch_XXX() for $db->query(). They are very, very different.

"Programming is like sex: one mistake and you have to support it for the rest of your life."

Re: Query Loops

I meant to say fetch_assoc. Sorry about that.

I don't HAVE a signature, ok?