Jump to content

Recommended Posts

Ok i have a slight problem.

 

is it possible to do soemthing like this?

 

        $query="SELECT * FROM category";
        $category_result=mysql_query($query,$connection);
        
        while($category=mysql_fetch_array($category_result){
            //do some stuff
              $query="SELECT * FROM sub_category WHERE sub_category_id = {$category['id']}";
              $sub_category_result=mysql_query($query,$connection);
              
        while($category=mysql_fetch_array($sub_category_result)){
            //do some stuff
            
            mysql_data_seek($category_result,0);
            
        while($category=mysql_fetch_array($category_result){
            // do some stuff like echo <option> $category['name']<option>
        }
            
        }
    }    

i tried the above but doesn't seem to work

Link to comment
https://forums.phpfreaks.com/topic/161824-looping-within-a-loop/
Share on other sites

In your code I see the following two queries

query 1

SELECT * FROM category

query 2

SELECT * FROM sub_category WHERE sub_category_id = {$category['id']}

 

Aren't sub_category and category both the same? I think you might be better of using 1 category table instead of 2. then you can simply use 1 query instead

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.