Jump to content

Help With Multiple While Functions


jj20051

Recommended Posts

Ok so I'm writing a script and it requires (as far as I know) two while mysql functions to run correctly.

 

TABLE 1: Stores Category Names

TABLE 2: Stores Product Information

 

I'm running a jquery (listed bellow) to list the categories in an <option> tag. The jquery will display whatever is in the <div> tag corresponding to the category id. (aka if box1 is selected it will display the content in the <div id="box1"> tag). The mysql queries are:

 

"SELECT * FROM categories"
$catagory_id = $cat['id'];

"SELECT * FROM products WHERE category_id='$catagory_id'"

 

The major problem is I can't break apart the select or div tags listed bellow thus I can't run it all in two queries because there are multiple entries (hence why I'm using a while() function to pull data). I know this is a bit complicated to understand, but hopefully you know how to fix this problem so that query #2 can get data by the category id without destroying the html code bellow. What I'm really looking for is a way for php to save the category ids, know what each of them are and then execute the second while function with each saved id after the first one is complete.

 

<select id="thechoices">
    <option value="box1">Box 1</option>
    <option value="box2">Box 2</option>
</select>

<div id="boxes">
<div id="box1"><p>Box 1 stuff...</p></div>
<div id="box2"><p>Box 2 stuff...</p></div>
</div>
<script type="text/javascript" src="./includes/jquery.js"></script>
<script type="text/javascript">

$("#thechoices").change(function(){
    $("#" + this.value).show().siblings().hide();
});
$("#thechoices").change();
</script>

Link to comment
https://forums.phpfreaks.com/topic/206571-help-with-multiple-while-functions/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.