mysql - PHP values displayed are determined from dropdown value?

610

I am hiding a table row on document load. I have a foreach running which collects the values from the database that I have specified. Below is an example of the data retrieved from the DB. I would like to load the product data where a customfield value, which each product has, is equal to one of the dropdown options.

I have this piece of code (this table has about 8 columns, but I only chose one to show how the process could work):

<select id="tempdropdown">
<option value="frozen">Frozen</option>
<option value="other">Other</option>
</select>

<td class="page_speed_1364253474"><?php 
// Get a db connection.
$db = JFactory::getDbo();

// Create a new query object.
$query = $db->getQuery(true);

// Select all records from the user profile table where key begins with "custom.".
// Order it by the ordering field.

$query->select($db->quoteName(array('customfield_value', 'virtuemart_product_id')));
$query->from($db->quoteName('jos_virtuemart_product_customfields'));
$query->where($db->quoteName('virtuemart_custom_id') . ' LIKE '. $db->quote('6'). ' AND '. $db->quoteName('virtuemart_product_id') . 'LIKE ' . $db->quote($product->virtuemart_product_id));

// Reset the query using our newly populated query object.
$db->setQuery($query);

// Load the results as a list of stdClass objects (see later for more options on retrieving data).
$results = $db->loadResult();
echo ($results); 
?>
</td>

I need to do something like this(I really do hope it makes sense):

<?php
// Start the Output

foreach ( $this->products as $product ) {

  // Show the horizontal seperator
  if ($iBrowseCol == 1 && $iBrowseProduct > $BrowseProducts_per_row) { ?>
  <div ></div>
  <?php }
?>

<tr >
<!-- All products are loaded in this row. Products are hidden on load. I will show an example of a <td> which retrieves
data from the DB -->

<!-- I LOADED THE DATA USING THE FIRST PIECE OF CODE IN THE POST. THIS LOADS THE FIELDS FOR THE PRODUCTS --> 

<!-- I need to load this data based on the dropdown selection. There is a customfield "Temp Zone". All the products have 
either "Frozen" or "Other" as this customfield value. -->


<td >
 <?php 
 $dropdown = ('#dropdown');

// Get a db connection. 
$db = JFactory::getDbo();
$valueTEMP = ('SELECT customfield_value, virtuemart_product_id, customfield_id FROM jos_virtuemart_product_customfields WHERE customfield_id["21"] == ''Frozen');

// Create a new query object.
$query = $db->getQuery(true);


if($dropdown == "Frozen" && $valueTEMP == True) {

$query->select($db->quoteName(array('customfield_value', 'virtuemart_product_id', 'customfield_id')));
$query->from($db->quoteName('jos_virtuemart_product_customfields'));
$query->where($db->quoteName('virtuemart_custom_id') . ' LIKE '. $db->quote('21'). ' AND '. $db->quoteName('virtuemart_product_id') . 'LIKE ' . $db->quote($product->virtuemart_product_id)); 
}

else {
$query->select($db->quoteName(array('customfield_value', 'virtuemart_product_id', 'customfield_id')));
$query->from($db->quoteName('jos_virtuemart_product_customfields'));
$query->where($db->quoteName('virtuemart_custom_id') . ' LIKE '. $db->quote('21'). ' AND '. $db->quoteName('virtuemart_product_id') . 'LIKE ' . $db->quote($product->virtuemart_product_id)); 
}

// Reset the query using our newly populated query object.
$db->setQuery($query);

// Load the results as a list of stdClass objects (see later for more options on retrieving data).
$results = $db->loadResult();
echo ($results); 
 ?>
 </td>


</tr>
<?php }
} // end of foreach ( $this->products as $product )
?>
</table>

I don't mind having to this at each piece of code, if it can work somehow. Currently, I don't know how to tell the system to retrieve ALL the PRODUCT DATA when a certain condition is met. However, if I have to manually edit each where the code is and place a condition for each one, I do not mind at all.

People are also looking for solutions to the problem: php - Counting the number of times a character occurs in a very large text file

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.