Assign the result of $db->query($query) to a variable ???

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

I'm creating tabs using PHP/MySQL and jQuery. I've created the easiest
model for testing purposes:

<div class="tab">

<div class="tab-nav">
   <li><a href="#1" />1</li>
   <li><a href="#2" />2</li>
   <li><a href="#3" />3</li>

<div id="1" class="tab-div">...</div>
<div id="2" class="tab-div">...</div>
<div id="3" class="tab-div">...</div>


I've created a static model above in PHP, did some test and works ok.
So far so good....

Now, i'm trying to create the model dynamically using PHP/MySQL data.

But, i'm stuck on how to create the div "tab-nav" in the middle of all
the div's 'tab-div'

I thought that by assigning the result of the query to another
variable, i would have to arrays therefore use one array to create my
menu (div tab-nav) and use the other array to create the div's (tab-

But for some reason, it seems that php doesn't see it that way. It
doesn't look like it is making the distinction that there are two

This a sample of the code:

$query ="SELECT .... ";

//2 arrays, one for menu and other for divs
$result = $db->query($query);
$result_nav = $result;

$num_results = $result->num_rows;

if($num_results == 0){
        echo 'Nothing to show.';

} else {

        $nav = true;

        <div class="tab">

        while($row = $result->fetch_assoc()){

             //create the tab-nav

                while($row_nav = $result_nav->fetch_assoc()){

             $nav = false;

        //create all the tab-div

        }//end while

        </div> //close the

Maybe doing the following is not a good idea after all:

$result = $db->query($query);
$result_nav = $result;

I should have two identical arrays, right?

Thanks in advance for the advice

Site Timeline