Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function calculate_average($arr) {
- $count = count($arr); //total numbers in array
- foreach ($arr as $value) {
- $total = $total + $value; // total value of array numbers
- }
- $average = ($total/$count); // get average value
- return $average;
- }
- function show_review_shortcode($atts) {
- extract(shortcode_atts(array("id" => ''), $atts));
- $user = "root";
- $pass = "";
- $host = "localhost";
- $dbname = "dbname";
- mysql_connect("$host", "$user", "$pass") or die(mysql_error());
- mysql_select_db("$dbname") or die(mysql_error());
- $result = mysql_query("SELECT * FROM `reviews` WHERE `id` = $id");
- if (!$rec = @mysql_fetch_array($result)){
- echo("Invalid Review.<br />");
- }else{
- $brand = $rec['brand'];
- $name = $rec['name'];
- $eff = $rec['eff'];
- $val = $rec['val'];
- $ov = $rec['ov'];
- $pro1 = $rec['pro1'];
- $pro2 = $rec['pro2'];
- $pro3 = $rec['pro3'];
- $con1 = $rec['con1'];
- $con2 = $rec['con2'];
- $con3 = $rec['con3'];
- $review = $rec['review'];
- $reviewer_name = $rec['reviewer_name'];
- $reviewer_email = $rec['email'];
- $site = $rec['site'];
- ?>
- <p><strong><?php echo $brand; ?> <?php echo $name; ?> Review<br /></strong></p>
- <table width="500" border="1" cellspacing="0" cellpadding="0">
- <tbody>
- <tr>
- <td width="50%" height="116"><p><strong>Ratings:</strong><strong> </strong></p>
- <strong>Taste [Rating:2/5]</strong>: [Rating:<?php echo $ov; ?>/5]<br />
- <strong>Effectiveness</strong>: [Rating:<?php echo $eff; ?>/5]<br />
- <strong>Value</strong>: [Rating:<?php echo $val; ?>/5]<br />
- <?php
- $overall_array = array($ov,$eff,$val);
- $overall_value = calculate_average($overall_array);
- $overall_value_formatted = number_format($overall_value, 2, '.', '');
- ?>
- <strong>Overall</strong>: [Rating:<?php echo $overall_value_formatted ?>/5]
- </td>
- <td width="50%"><div align="center"><strong> <a href="http://supplementjudge.net/out.php?id="><img src="http://www.supplementjudge.net/buy.png" width="180" height="71" border="0"></a></strong></div></td>
- </tr>
- </tbody>
- </table>
- <p><strong>Summary</strong></p>
- <table width="500" border="1" cellspacing="0" cellpadding="0">
- <tbody>
- <tr>
- <td width="50%"><strong>Pros</strong></p>
- <ul>
- <li><?php echo $pro1; ?></li>
- <li><?php echo $pro2; ?></li>
- <li><?php echo $pro3; ?></li>
- </ul>
- </td>
- <td width="50%"><strong>Cons</strong></p>
- <ul>
- <li><?php echo $con1; ?></li>
- <li><?php echo $con2; ?></li>
- <li><?php echo $con3; ?></li>
- </ul>
- </td>
- </tr>
- </tbody>
- </table>
- <p><strong>My Review</strong></p>
- <p><?php echo $review; ?></p>
- <p><strong>Nutritional Information</strong></p>
- <p>Bla</p>
- <p><strong>Ingredients</strong></p>
- <p>Bla</p>
- [toggle title="Serving Info"]Bla[/toggle]
- <?php
- if (!empty($reviewer_name)){
- echo "<p>Reviewed by: $reviewer_name</p>";
- }
- }
- }
- add_shortcode('review', 'show_review_shortcode');
- ?>
Advertisement
Add Comment
Please, Sign In to add comment