I have following code to get all the reviews. It works but the problem is it's also printing the pending reviews. It should only print the ones that are approved.
$review = Mage::getModel('review/review');
$collection = $review->getProductCollection();
$collection
->addAttributeToSelect('*')
->getSelect()
->limit($limitertest)
->order('RAND()');
$review->appendSummary($collection);
echo '<ul class="testimony_slider">';
foreach($collection as $product) {
echo '<li>';
echo '<div class="testi_left">';
echo '<img src='.Mage::helper('catalog/image')->init($product, 'small_image')->resize(100).'>';
echo '</div>';
echo '<div class="testi_right">';
echo '<p class="testti_summery">"'.$product->getTitle().'"</p>';
echo '<p class="testti_nickname">'.$product->getNickname().'</p>';
echo '</div>';
echo '<div class="clear_both"></div>';
echo '</li>';
}
echo '</ul>';
You may need to refactor your code to get the reviews collection, then filter by the approved status. Something like this:
$reviews = Mage::getModel('review/review')->getResourceCollection();
$reviews->addStatusFilter(Mage_Review_Model_Review::STATUS_APPROVED);
Related
I am currently coding a page based on a json query.
Here is a snippet of the code, I don't want to give the top half as that is grabbing the remote json with id's and passwords, but here is the main snippet:
$content_size = 'one_half';
foreach ( $json_decoded['fixtures-results']['matches'] as $match ){
display_match($match);
}
function display_match($match){
global $content_size;
if (strtotime($match['date']) < time()) { goto skip; }
$home_team_name = strtolower($match['home-team']['name']);
$home_team_name = preg_replace('/\s+/', '_',$home_team_name);
$away_team_name = strtolower($match['away-team']['name']);
$away_team_name = preg_replace('/\s+/', '_',$away_team_name);
$match_date = date("M jS, Y", strtotime($match['date']));
echo '<div class="'.$content_size.'">';
echo '<div class="latest_results" style="background:#ffffff">';
echo '<h6>'.$match_date.', '.$match['status']['full'].'</h6>';
echo '<div class="latest_results_col"><img src="/team_logos/'.$home_team_name.'.png"><span>'.$match['home-team']['name'].'</span></div>';
echo '<div class="latest_results_col goalscore2">vs</div>';
echo '<div class="latest_results_col"><img src="/team_logos/'.$away_team_name.'.png"><span>'.$match['away-team']['name'].'</span></div>';
echo '<div class="clear">';
echo '<span>Location:'.$match['venue'].'</span>';
echo '</div>';
echo '</div>';
echo '</div>';
if ($content_size == "one_half") { $content_size = "one_half_last"; goto skip; }else{ $content_size = "one_half"; goto skip; }
skip:
}
What i want is the first div class to be one_half then the next one as one_half_last then back to one_half and so on.
The result is the first div has the class one_half but the second has no class, then the third has one_half and so on, so you see it seems to be working, except its missing the second, fourth, sixth ect class.
Any help would be greatly received.
Kind Regards,
Adam
I am not sure what happened, and why it corrected itself, but here is the code i ended up using.
$content_size = 'one_half';
foreach ( $json_decoded['fixtures-results']['matches'] as $match ){
display_match($match);
}
function display_match($match){
global $content_size;
if(!$content_size){ $content_size = "one_half"; }
if (strtotime($match['date']) < time()) { goto skip; }
$home_team_name = strtolower($match['home-team']['name']);
$home_team_name = preg_replace('/\s+/', '_',$home_team_name);
$away_team_name = strtolower($match['away-team']['name']);
$away_team_name = preg_replace('/\s+/', '_',$away_team_name);
$match_date = date("M jS, Y", strtotime($match['date']));
$home_team_name_2 = team_name_2($match['home-team']['name']);
$away_team_name_2 = team_name_2($match['away-team']['name']);
echo '<div class="'.$content_size.'">';
echo '<div class="latest_results" style="background:#ffffff">';
echo '<h6>'.$match_date.', '.$match['status']['full'].'</h6>';
echo '<div class="latest_results_col"><img src="/team_logos/'.$home_team_name.'.png"><span>'.$home_team_name_2.'</span></div>';
echo '<div class="latest_results_col goalscore2">vs</div>';
echo '<div class="latest_results_col"><img src="/team_logos/'.$away_team_name.'.png"><span>'.$away_team_name_2.'</span></div>';
echo '<div class="clear">';
echo '<span>Location:'.$match['venue'].'</span>';
echo '</div>';
echo '</div>';
echo '</div>';
if ($content_size == "one_half") { $content_size = "one_half last_column"; goto skip; }else{ $content_size = "one_half"; goto skip; }
skip:
}
If anyone has any idea what I did differently I am happy to hear as I am not sure what i did.
I have this JOIN, that gets me more than on result:
at.tipo AS atividade,
at.data AS datacadastro,
at.user AS usercadastro,
LEFT JOIN atividades at
ON (at.produto = '$produto')
AND (at.tipo = 'cadastra' OR at.tipo = 'revisado')
And I have: if string = 'cadastra' shows something, if string = 'revisado' shows something else.
<?php
if ($row['atividade'] == 'cadastra') {
echo '<div id="user-img">';
echo '<img src="http://'.$row['imguser'].'"/></div>';
echo '<div id="user-cadastro" class="greytxt">';
echo 'Cadastrado por <br>' .$row['usercadastro']. '<br>em ';
echo $row['datacadastro']. '</div>';
}
?>
<?php
if ($row['atividade'] == 'revisado') {
echo '<div id="user-img">';
echo '<img src="http://'.$row['imguser'].'"/></div>';
echo '<div id="user-cadastro" class="greytxt">';
echo 'Cadastrado por <br>' .$row['usercadastro']. '<br>em ';
echo $row['datacadastro']. '</div>';
}
?>
The problem is, it's showing just the first result, and not all.
How can I display all results?
EDIT:
I have this JOIN inside a big query, that give me other important rows.
But I just want one result for this principal query (WHERE = $produto), and want more results from my JOIN table.
$rows = $result->num_rows;
for ($j = 0; $j < $rows; ++$j) {
$result -> data_seek($j);
$row = $result->fetch_array (MYSQLI_ASSOC);
?>
My result should be this, but JOIN shows just row 'cadastra'.
Use $result->fetch_array (MYSQLI_ASSOC) inside a while loop
while ($row = $result->fetch_array (MYSQLI_ASSOC)) {
if ($row['atividade'] == 'cadastra')
{
echo '<div id="user-img">';
echo '<img src="http://'.$row['imguser'].'"/></div>';
echo '<div id="user-cadastro" class="greytxt">';
echo 'Cadastrado por <br>' .$row['usercadastro']. '<br>em ';
echo $row['datacadastro']. '</div>';
} ?>
<?php if ($row['atividade'] == 'revisado')
{
echo '<div id="user-img">';
echo '<img src="http://'.$row['imguser'].'"/></div>';
echo '<div id="user-cadastro" class="greytxt">';
echo 'Cadastrado por <br>' .$row['usercadastro']. '<br>em ';
echo $row['datacadastro']. '</div>';
}
}
Long story short a couple months ago i made a plugin for WordPress with the Bigcommerce API to fetch products in the Widget Area.
Now I have updated the Single File "Bigcommerce.php" and now the Function getProductImages () is none existent. And I cant seem to find the new function to get the Product Images. Maybe its just to late and Im tired or just plain Blind.
Please let me know how to fetch now the image for a specific product.
See below for the old code used i reverted back to the Old "Bigcommerce.php" and it works again but would ratehr use the new way.
Bigcommerce::configure(array(
'store_url' => $store_url,
'username' => $username,
'api_key' => $api_key
));
Bigcommerce::setCipher('RC4-SHA');
Bigcommerce::verifyPeer(false);
$countProducts = 0;
$products = Bigcommerce::getProducts();
shuffle($products);
echo '<div class="BCStoreWidget">';
if (!$products) {
echo '<div class="BCerror">';
$error = Bigcommerce::getLastError();
echo $error->code;
echo $error->message;
echo '</div>';
} else {
foreach ($products as $product) {
$productImages = Bigcommerce::getProductImages($product->id);
echo '<h4>' . $product->name . '</h4>';
if ($productImages->image_file){
echo '<div class="pimage">';
echo '<img src="' . $store_url . '/product_images/' . $productImages->image_file . '">';
echo '</div>';
}
// echo '<p>' . substr($product->description,0,100) . ' ...</p>';
echo '<p>' . number_format($product->price, 2, '.', '') . ' USD</p>';
echo '<p> Buy Now </p>';
$countProducts++;
if ($countProducts == $max_show)
break;
}
}
echo '</div>';
Thank you all in Advance
You can get product images just by getting the "images" attribute of the product object. So, all you have to do is:
$productImages = $product->images;
You can also access images directly using the getCollection function:
Bigcommerce::getCollection('/products/'.$product_id.'/images/');
This is the function im using to show results in the index.php with the style.css correctly done with the li´s and the div´s all that i just want to show in every li the price or the service i want. EXAMPLE: ($_GET_ROW['ID'] = '1', $_GET_ROW['ID'] = '2').
function products() { $get = mysql_query('SELECT id, servico, preco FROM loja');
if (mysql_num_rows($get)==0) {
echo "Não existem produtos a serem mostrados!";
} else {
while ($get_row = mysql_fetch_assoc($get)) {
echo '<li class="l1 i1 column1">';
echo '<h2>'.**$get_row["servico"]**. '</h2>';
echo '<div class="basket">Adicionar</p></div>';
echo '<div class="preco"><em>Preco:</em><strong>'.number_format($get_row['preco'], 2).'</strong><span>EUR</span>';
echo '</div>';
echo '<li class="l2 i0 column0">';
echo '<h2>'**.$get_row["servico"].**'</h2>';
echo '<div class="basket">Adicionar</p></div>';
echo '<div class="preco"><em>Preco:</em><strong>'.number_format($get_row['preco'], 2).'</strong><span>EUR</span>';
echo '</div>';
My database:
-----------------------------------
id servico preco
-----------------------------------
1 Servico Normal 29.5
-----------------------------------
2 Servico Rapido 32.5
-----------------------------------
It seems like you need a while loop to iterate through the rows like so:
if (mysql_num_rows($get)==0) {
echo "Não existem produtos a serem mostrados!";
} else {
while($get_row = mysql_fetch_assoc($get)) {
**echo '<li class="l1 i1 column1">';
echo '<h2>'.$get_row["servico_normal"].'</h2>';
echo '<div class="basket">Adicionar</p></div>';
echo '<div class="preco"><em>Preco:</em <strong>'.number_format($get_row['preco'], 2).'</strong><span>EUR</span>';
echo '</div>';**
}
}
However, you should immediately stop using mysql_ functions as they are being deprecated and vulnerable to SQL injection; and use mysqli_ or PDO instead.
Update 1
mysql_ functions are officially deprecated.
The principle of my initial answer still remains. You have two rows in your database and you want to iterate through them.
while ($get_row = mysql_fetch_assoc($get)) {
$liClass = 'l' . $get_row[id];
echo '<li class="' . $liClass . ' i1 column1">';
echo '<h2>' . $get_row[servico] . '</h2>';
echo '<div class="basket"><p>Adicionar</p></div>';
echo '<div class="preco"><em>Preco:</em><strong>' . number_format($get_row['preco'], 2) . '</strong><span>EUR</span>';
echo '</div>';
}
For the first row, the output would be:
<li class="l1 i1 column1">
<h2>Servico Normal</h2>
<div class="basket"><p>Adicionar</p></div>
<div class="preco"><em>Preco:</em><strong>29.50</strong><span>EUR</span></div>
I'm trying to list diary events in PHP from a MySQL database, but grouped by days. I'll explain.
This is a screenshot of what I have so far:
As you can see there are two diary events for the 23rd October 2012 and is showing two calendar icons/representations/whatever's. I actually want it to show one calendar icon on the left but list all of that days events on the right, until the next day - as seen in my a̶r̶t̶i̶s̶t̶s̶ idiots impression below:
This is the code I have just written, could somebody please point me in the right direction:
$SQL = "SELECT entry_id, entry_title, entry_body, entry_date, entry_day, entry_month, entry_year ";
$SQL .= "FROM pages_diary WHERE entry_month = :this_month AND entry_year = :this_year ";
$SQL .= "ORDER BY entry_date DESC;";
// PDO stuff
if ($STH->rowCount() > 0) {
while($row = $STH->fetch()):
$this_db_month_word = mktime(0, 0, 0, $row['entry_month']);
$this_db_month_word = strftime("%b", $this_db_month_word);
echo '<div class="diary_events_item" id="diary_events_item_'.$row['entry_id'].'">';
echo '<div class="diary_events_item_left">';
echo '<div class="calendar_wrap">';
echo '<div class="calendar_wrap_top">';
echo $this_db_month_word;
echo '</div>';
echo '<div class="calendar_wrap_bottom">';
echo str_pad($row['entry_day'],2,'0',STR_PAD_LEFT);;
echo '</div>';
echo '</div>';
echo '</div>';
echo '<div class="diary_events_item_right">';
echo '<strong>'.htmlspecialchars($row['entry_title']).'</strong><br>';
echo '<p>'.htmlspecialchars($row['entry_body']).'</p>';
echo '</div>';
echo '<div class="clear"></div>';
echo '</div>';
endwhile;
} else {
echo '<p>There are no diary entries logged for <strong>'.$this_month_word.' '.$this_year.'</strong>.</p>';
}
Not looking for exact code (although that would be spiffing), just an explanation would do, I'm sure I can work it out from that.
THE FIX
At the end of the WHILE loop, I added:
$last_db_day = $row['entry_day'];
And then wrapped the calendar item in:
if ($last_db_day != $row['entry_day']) {
echo '<div class="calendar_wrap_top">';
echo $this_db_month_word;
echo '</div>';
echo '<div class="calendar_wrap_bottom">';
echo str_pad($row['entry_day'],2,'0',STR_PAD_LEFT);;
echo '</div>';
}
As you loop over your resultset from the database, keep track of the last entry_date that you've seen and only output a new calendar icon if the current record is for a different date.
I usually do this as follows:
if ($STH->execute()) {
// output headers
$row = $STH->fetch();
while ($row) {
$current_date = $row['entry_date'];
// output $current_date initialisation
do {
// output event $row
} while ($row = $STH->fetch() and $row['entry_date'] == $current_date);
// output $current_date termination
}
// output footers
}
Although I would go the other way around and embed the PHP within the HTML rather then the other way around, here is what I would do using your code:
$SQL = "SELECT entry_id, entry_title, entry_body, entry_date, entry_day, entry_month, entry_year ";
$SQL .= "FROM pages_diary WHERE entry_month = :this_month AND entry_year = :this_year ";
$SQL .= "ORDER BY entry_date DESC;";
// PDO stuff
if ($STH->rowCount() > 0) {
$loopDay = '';
while($row = $STH->fetch()):
if ($row['entry_day'] != $loopDay) {
$loopDay = $row['entry_day'];
$changed = true;
}
$this_db_month_word = mktime(0, 0, 0, $row['entry_month']);
$this_db_month_word = strftime("%b", $this_db_month_word);
echo '<div class="diary_events_item" id="diary_events_item_'.$row['entry_id'].'">';
echo '<div class="diary_events_item_left">';
if ($changed) {
echo '<div class="calendar_wrap">';
echo '<div class="calendar_wrap_top">';
echo $this_db_month_word;
echo '</div>';
echo '<div class="calendar_wrap_bottom">';
echo str_pad($row['entry_day'],2,'0',STR_PAD_LEFT);;
echo '</div>';
echo '</div>';
} else {
echo ' ';
}
echo '</div>';
echo '<div class="diary_events_item_right">';
echo '<strong>'.htmlspecialchars($row['entry_title']).'</strong><br>';
echo '<p>'.htmlspecialchars($row['entry_body']).'</p>';
echo '</div>';
echo '<div class="clear"></div>';
echo '</div>';
$changed = false;
endwhile;
} else {
echo '<p>There are no diary entries logged for <strong>'.$this_month_word.' '.$this_year.'</strong>.</p>';
}