Reputation: 21
This code:
<div class="product">
<img src="images/product-1s.jpg" onclick="JavaScript:newPopup('images/product-1.jpg');">
<span class="tiger" data-name="show" data-price="show" data-text="Buy Now">
1</span>Lorem Ipsum Dolar</div>
works perfectly with everything the way it is, the classes are already coded and mysql_ is used primarily.
All I want to do is stick the id# and the desc in there for every row on the table. I guess it cant be done as simply as I thought. I could manually write all that out and get everything working but obviously that is not ideal.
Is there another method that would allow me to execute this outside of whats already happening?
This function:
class Product{
var $error = '';
var $msg = '';
public function all(){
$result = mysql_query("SELECT * FROM " . PFX . "products WHERE active = 1");
$products = array();
while($rows = mysql_fetch_assoc($result)){
$products[]=$rows;
}
return $products;
}
is already done, can I call this to populate the variables [id] & [description] from the db that I need?
Upvotes: 1
Views: 78
Reputation: 1029
I am not sure if I understood all the requirements, so please correct me if I got them wrong. Anyway, here is one solution. In your PHP file you could write:
<?php
$result = mysql_query("SELECT * FROM " . PFX . "products WHERE active = 1");
$products = array();
$numberOfRows = 0;
while($rows = mysql_fetch_assoc($result)){
$products[]=$rows;
$numberOfRows++;
}
for($i = 0; $i< $numberOfRows; $i++){
?>
<div class="product" id="<?php echo $products[0];?>" > <!-- assuming 0 is the position of id -->
<img src="images/product-1s.jpg" onclick="JavaScript:newPopup('images/product-1.jpg');">
<span class="tiger" data-name="show" data-price="show" data-text="Buy Now">1</span> <?php echo $products[1]; ?></div> // assuming 1 is position of description
<?php
} // closing bracket of the 'for' loop
?>
Upvotes: 1