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
https://forums.phpfreaks.com/topic/216803-problem-querying-results-from-database/
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) {

        }
}

??

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.