Jump to content

problem querying results from database


svgmx5

Recommended Posts

I've been trying to fix this piece of script so i can query the results from a database.

 

What i want to do is to display the results from the database like below:

 

Product Heading

price

      Subproduct - $price

 

Each item would have a check box next to them. I have managed to display the items but not the prices. I've looked over the code several times but i'm lost on what i should do.

 

Anyway here's the code, i hope someone here can view it and let me know what i'm doing wrong or what i'm not doing.

<?php
       $get_cats = "SELECT * FROM sub_service WHERE industry='$industry'";
       $run_get = mysql_query($get_cats) or die(mysql_error());
       $tmp = array();
       $x=1;
       while($rw = mysql_fetch_assoc($run_get)){
		if (!array_key_exists($rw['service'],$tmp)) {
		         $tmp[$rw['service']] = array();
		}
		$tmp[$rw['service']][] = $rw['sub_service'];
}

foreach ($tmp as $service => $items) {
?>
       <div id="industry_wrapper">
             <h2><?php echo $service ?></h2>
                                        </div>
                                        <div id="select_all_holder">
                                            <div id="select_all_input">
                                                <input type="checkbox" class="toggleElement" name="toggle" onchange="toggleStatus()" />
                                            </div>
                                            <div id="select_all_txt">
                                                <p>Select All Services - $</p>
                                            </div>
                                        </div>
                                        <?php
									echo'
                                        <div class="service_holder">
                                            <table width="650" cellpadding="0" cellspacing="5">
                                        ';
									foreach ($items as $cat) {
										?>
                                                <tr>
                                                    <td width="28" align="center"><input type="checkbox"  /></td>
                                                    <td width="605"><p><?php echo $cat ?> - $<?php echo $tmp['price']; ?></p></td>
                                                </tr>
                                            <?php	
									}
									echo'</table></div>';
								}
							?>

 

Link to comment
Share on other sites

so you are telling i should change the following:

foreach ($tmp as $service => $items) {
         foreach ($items as $cat) {

        }
}

 

To the following:

 


for ($tmp as $service => $items) {
         for ($items as $cat) {

        }
}

??

Link to comment
Share on other sites

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.