How to display rate value using stars - php

i tried. but it not success full.. please give me solution..
php code
<?php
function getReviews($con){
$sql = "SELECT * FROM review";
$result = mysql_query($sql,$con);
while ($row = mysql_fetch_array($result)) {
echo "<div class=' col-md-12 comment-box'>";
echo "<div class='left-comm col-md-2'>";
echo "<img class='img-responsive' src='images/article/avatar3.png'>";
echo "</div>";
echo "<div class='right-comm col-md-6'>";
echo "<p class='user-name'>".$row['email']."</p>";
echo for ($i=0; $i <$row['rating'] ; $i++) {
echo "*";
}"<br>";
echo $row['review']."<br>";
echo "</div>";
echo "</div><br>";
?>
i want to display rate value using stars.in this function.

Change:
echo for ($i=0; $i <$row['rating'] ; $i++) {
echo "*";
}"<br>";
to:
for ($i=0; $i <$row['rating'] ; $i++) {
echo "*";
}
echo "<br />";

Related

Why I can't echo div?

I have code for list values from database but when I add them to echo "<div>" it stops working
My code:
$sql = "SELECT name, size, type, username FROM Files";
$result = $conn->query($sql);
if ($result->num_rows > 0)
{
while($row = $result->fetch_assoc())
{
echo "<div class='filediv'>";
echo "<a href='uploads/$row['name']' download>$row['name']</a>";
echo "<p>Size: $row['size']KB</p>";
echo "<p>Type: $row['type']</p>";
echo "<p>Creator: $row['username']</p>";
echo "</div>";
echo "<hr>";
}
}
you have a syntax error
echo "<div class='filediv'>";
echo "<a href='uploads/".$row['name']."' download>".$row['name']."</a>";
echo "<p>Size:". $row['size']."KB</p>";
echo "<p>Type: ".$row['type']."</p>";
echo "<p>Creator: ".$row['username']."</p>";
echo "</div>";
echo "<hr>";
You can use {} for print php variables in html.
echo "<div class='filediv'>";
echo "<a href='uploads/{$row['name']}' download>{$row['name']}</a>";
echo "<p>Size: {$row['size']}KB</p>";
echo "<p>Type: {$row['type']}</p>";
echo "<p>Creator: {$row['username']}</p>";
echo "</div>";
echo "<hr>";

How to get the highest value from a database row?

I have a problem. I have a one page website and if there is posted a message a posts shows up and below the post there needs to be an image, but on the last on the index page I don't want an image to show up. So it's like if the id from the database is the highest that post doesn't get a image below it.
Here is the code:
<?php
include 'functions/image/functions.php';
$countQuery = $db->prepare("SELECT paginaNummer AS max FROM pages ;");
$countRow = $countQuery->fetch();
$maxId = $countRow['max'];
$query = $db->prepare("SELECT * FROM pages");
$query->execute();
$num_cols = 1;
$i = 0;
$imgList = getImagesFromDir($root . $path);
$img = getRandomFromArray($imgList);
while($row = $query->fetch()) {
if(isset($row)) {
echo "<section data-stellar-background-ratio='0.5'>";
echo "<div class='panelContainer'>";
echo "<div class='panel2'>";
echo "<div class='symbol3'></div>";
echo "</div>";
echo "</div>";
echo "</div>";
echo "</section>";
echo "<section class='wrapper'>";
echo "<div class='box'>";
echo "<div class='content'>";
echo $i++ % $num_cols == 0 ? '' : '';
echo "<div id='message'><h2> ", $row['berichtNaam'], "</h2>";
echo $row['paginaContent'], "<br />";
if (isset($_SESSION['login']['5']) && $_SESSION['login']['5'] == 2) {
echo " <a class='edit' href='functions/admin/edit.php?id=" . $pageNumber . " '>Edit</a>";
echo " <a class='delete' href='functions/admin/deletePost.php?id=" . $pageNumber . " '>Delete</a>";
} elseif (isset($_SESSION['login']['5']) && $_SESSION['login']['5'] == 1) {
echo " <a class='edit' href='functions/admin/edit.php?id=" . $pageNumber . " '>Edit</a>";
} else {
}
echo "</div>";
echo "</div>";
echo "</section>";
echo max($row);
if (count($row['paginaNummer']) == max($row)){
} else {
echo "<a href='/'><img src='<?php echo $path . $img ?>'alt=''/></a>";
}
echo "</section>";
}
}
echo "</div></div>";
?>
I won't get any further with this part I hope you can help me with this problem
It's hard to understand what you need. But try this query:
$countQuery = $db->prepare("SELECT paginaNummer AS max
FROM pages ORDER BY paginaNummer DESC LIMIT 1");
Or may be this:
$countQuery = $db->prepare("SELECT paginaNummer AS max
FROM pages ORDER BY id DESC LIMIT 1");
Update: this code changes instead of top:
<?php
include 'functions/image/functions.php';
$query = $db->prepare("SELECT * FROM pages");
$query->execute();
$maxrow = $query->rowCount();
$num_cols = 1;
$i = 0;
$imgList = getImagesFromDir($root . $path);
$img = getRandomFromArray($imgList);
$n = 0;
while($row = $query->fetch()) {
if(isset($row)) {
$n++;
echo "<section data-stellar-background-ratio='0.5'>";
echo "<div class='panelContainer'>";
echo "<div class='panel2'>";
echo "<div class='symbol3'></div>";
echo "</div>";
echo "</div>";
echo "</div>";
echo "</section>";
echo "<section class='wrapper'>";
echo "<div class='box'>";
echo "<div class='content'>";
echo $i++ % $num_cols == 0 ? '' : '';
echo "<div id='message'><h2> ", $row['berichtNaam'], "</h2>";
echo $row['paginaContent'], "<br />";
if (isset($_SESSION['login']['5']) && $_SESSION['login']['5'] == 2) {
echo " <a class='edit' href='functions/admin/edit.php?id=" . $pageNumber . " '>Edit</a>";
echo " <a class='delete' href='functions/admin/deletePost.php?id=" . $pageNumber . " '>Delete</a>";
} elseif (isset($_SESSION['login']['5']) && $_SESSION['login']['5'] == 1) {
echo " <a class='edit' href='functions/admin/edit.php?id=" . $pageNumber . " '>Edit</a>";
} else {
}
echo "</div>";
echo "</div>";
echo "</section>";
echo max($row);
if ($n == $maxrow){
} else {
echo "<a href='/'><img src='<?php echo $path . $img ?>'alt=''/></a>";
}
echo "</section>";
}
}
echo "</div></div>";
?>

PHP Counting With Related Articles

my goal is to display related articles below a post (check if available, then loop through the ones that are there). It works fine if I have 3 or 6 setup but if I have only 5, it displays automatically the original post as the sixth related article.
echo "<div class='related-posts'>";
$related_articles = get_field('related_articles', false, false);
$id = $related_articles[0];
if($id) {
echo "<h5 class='related-posts_h'>Ähnliche Artikel, die du lesen musst</h5>";
echo "<ul class='related-posts_list clearfix'>";
for ($i=1; $i <= 6; $i++) {
$id = $related_articles[$i-1];
if ( has_post_thumbnail($id) ) {
echo "<li class='related-posts_item'>";
echo "<figure class='featured-thumbnail thumbnail large'>";
echo "<div class='hider-page'></div>";
echo "<a href='".get_permalink($id)." title='".get_the_title($id)."'>";
echo get_the_post_thumbnail( $id, 'medium-thumb' );
echo "<span class='zoom-icon'></span>";
echo "</a>";
echo "</figure>";
} else {
"<figure class='thumbnail featured-thumbnail'>";
echo "<div class='hider-page'></div>";
echo "<a href='".get_permalink($id)."' title='".get_the_title($id)."'>";
echo "<img src='".get_template_directory_uri()."/images/empty_thumb.gif' alt='".get_the_title($id)."' />";
echo "</a>";
echo "</figure>";
}
echo "<h6><a href='".get_permalink($id)."'>";
echo get_the_title($id);
echo "</a>";
echo "</h6>";
echo "</li>";
}
echo "</ul>";
echo "</div><!-- .related-posts -->";
Try this.. check after the for loop whether the related Post ID is not equals to the original post ID then only display the related Posts
that is
$id = $related_articles[$i-1];
if(get_the_ID() != $id){
//then do the stuff
}
I Hope you are in the details or single.php page so you will get the ID of original post by get_the_ID()
echo "<div class='related-posts'>";
$related_articles = get_field('related_articles', false, false);
$id = $related_articles[0];
if($id) {
echo "<h5 class='related-posts_h'>Ähnliche Artikel, die du lesen musst</h5>";
echo "<ul class='related-posts_list clearfix'>";
for ($i=1; $i <= 6; $i++) {
$id = $related_articles[$i-1];
if(get_the_ID() != $id){
if ( has_post_thumbnail($id) ) {
echo "<li class='related-posts_item'>";
echo "<figure class='featured-thumbnail thumbnail large'>";
echo "<div class='hider-page'></div>";
echo "<a href='".get_permalink($id)." title='".get_the_title($id)."'>";
echo get_the_post_thumbnail( $id, 'medium-thumb' );
echo "<span class='zoom-icon'></span>";
echo "</a>";
echo "</figure>";
} else {
"<figure class='thumbnail featured-thumbnail'>";
echo "<div class='hider-page'></div>";
echo "<a href='".get_permalink($id)."' title='".get_the_title($id)."'>";
echo "<img src='".get_template_directory_uri()."/images/empty_thumb.gif' alt='".get_the_title($id)."' />";
echo "</a>";
echo "</figure>";
}
echo "<h6><a href='".get_permalink($id)."'>";
echo get_the_title($id);
echo "</a>";
echo "</h6>";
echo "</li>";
}
}
echo "</ul>";
echo "</div><!-- .related-posts -->";

XML link into a PHP array

I'm having trouble getting this page (http://ventrilostatus.net/xml/V98.DARKSTARLLC.COM:3789/) to array into php. I'm not very good with xml and I currently can only get it to display:
Server
Channel
Channel
Channel
(etc)
Could anyone help me get it to show the channel name and the users?
if there are not clients when you look at it it will be:
<client admin="1" cid="994" phan="0" ping="186" sec="56935" name="WHERE USER'S NAME HIS HERE" comm=""/>
U can use the simple_xml functions of PHP to load the xml file into a class.
http://php.net/manual/de/book.simplexml.php
Edit with an example:
// XML example
$xmlContent = '<server name="GuiltyofDestruction" phonetic="God" comment="http://guiltyofdestruction.com" auth="1" maxclients="25" uptime="137600" platform="Linux-i386" version="3.0.6" channelcount="36" clientcount="1" voicecodec="GSM 6.10" voiceformat="44 KHz, 16 bit"><channel cid="0" pid="-1" prot="0" name="Lobby" comm="">
<channel cid="1033" pid="0" prot="1" name="Admin" comm=""/>
<channel cid="1030" pid="0" prot="0" name="AFK Channel" comm="AFK">
<client admin="1" cid="1030" phan="0" ping="182" sec="67575" name="US_ChairForce" comm=""/>
</channel>
</channel>
</server>';
// Loading XML information as object
//$xml = simplexml_load_file('http://ventrilostatus.net/xml/V98.DARKSTARLLC.COM:3789/'); // for files
$xml = simplexml_load_string($xmlContent); // for strings
foreach($xml->channel->channel as $channel) {
if($channel->client)
echo $channel->client->attributes()->name; // returns "US_ChairForce"
}
I think it's clear now. You have to iterate through every channel and look for clients.
sorry this is the code I updated:
<?PHP
echo "<table width=\"209\" bgcolor=\"#0d0d0d\">";
$xml = simplexml_load_file('http://ventrilostatus.net/xml/V98.DARKSTARLLC.COM:3789/'); // for files
//$xml = simplexml_load_string($xmlContent); // for strings
foreach($xml->channel as $lobby) {
echo "<tr><td>";
echo "<img src='http://view.light-speed.com//images/s_vent2/server_icon.gif' />";
echo "<font color=\"#FFFFFF\">";
echo $lobby->attributes()->name;
echo "</font>";
echo "</td></tr>";
}
foreach($xml->channel->channel as $channel) {
if($channel->attributes()->prot == "0"){
echo "<tr><td> ";
echo "<img src='http://view.light-speed.com//images/s_vent2/channel_0_empty.gif' />";
echo "<font color=\"#ffffff\">";
echo $channel->attributes()->name;
echo "</font>";
echo "</td></tr>";
}else{
echo "<tr><td> ";
echo "<img src='http://view.light-speed.com//images/s_vent2/channel_1_empty.gif' />";
echo "<font color=\"#ffffff\">";
echo $channel->attributes()->name;
echo "</font>";
echo "</td></tr>";
}
if($channel->client){
for ( $i = 0; $i < count($channel->client); $i++ ){
$client = $channel->client[ $i ];
if ( $client->attributes()->cid != $client->attributes()->cid )
continue;
echo "<tr><td> ";
echo "<img src='http://view.light-speed.com//images/s_vent2/player.gif' /><font color=\"#009e1a\">";
if($client->attributes()->admin == "1"){
echo $client->attributes()->name;
echo " <font color=\"#ff0000\">(Admin)</font>";
}else{
echo $client->attributes()->name;
}
echo "</td></tr>";
}
}
foreach($channel->channel as $subchannel) {
if($subchannel->attributes()->prot == "0"){
echo "<tr><td> ";
echo "<img src='http://view.light-speed.com//images/s_vent2/channel_0_empty.gif' />";
echo "<font color=\"#ffffff\">";
echo $subchannel->attributes()->name;
echo "</font>";
echo "</td></tr>";
}else{
echo "<tr><td> ";
echo "<img src='http://view.light-speed.com//images/s_vent2/channel_1_empty.gif' />";
echo "<font color=\"#ffffff\">";
echo $subchannel->attributes()->name;
echo "</font>";
echo "</td></tr>";
}
if($subchannel->client){
for ( $i = 0; $i < count($subchannel->client); $i++ ){
$client = $subchannel->client[ $i ];
if ( $client->attributes()->cid != $client->attributes()->cid )
continue;
echo "<tr><td> ";
echo "<img src='http://view.light-speed.com//images/s_vent2/player.gif' /><font color=\"#009e1a\">";
if($client->attributes()->admin == "1"){
echo $client->attributes()->name;
echo " <font color=\"#ff0000\">(Admin)</font>";
}else{
echo $client->attributes()->name;
}
echo "</td></tr>";
}
}
foreach($subchannel->channel as $subchannel2) {
if($subchannel2->attributes()->prot == "0"){
echo "<tr><td> ";
echo "<img src='http://view.light-speed.com//images/s_vent2/channel_0_empty.gif' />";
echo "<font color=\"#ffffff\">";
echo $subchannel2->attributes()->name;
echo "</font>";
echo "</td></tr>";
}else{
echo "<tr><td> ";
echo "<img src='http://view.light-speed.com//images/s_vent2/channel_1_empty.gif' />";
echo "<font color=\"#ffffff\">";
echo $subchannel2->attributes()->name;
echo "</font>";
echo "</td></tr>";
}
if($subchannel2->client){
for ( $i = 0; $i < count($subchannel2->client); $i++ ){
$client = $subchannel2->client[ $i ];
if ( $client->attributes()->cid != $client->attributes()->cid )
continue;
echo "<tr><td> ";
echo "<img src='http://view.light-speed.com//images/s_vent2/player.gif' /><font color=\"#009e1a\">";
if($client->attributes()->admin == "1"){
echo $client->attributes()->name;
echo " <font color=\"#ff0000\">(Admin)</font>";
}else{
echo $client->attributes()->name;
}
echo "</td></tr>";
}
}
foreach($subchannel2->channel as $subchannel3) {
if($subchannel3->attributes()->prot == "0"){
echo "<tr><td> ";
echo "<img src='http://view.light-speed.com//images/s_vent2/channel_0_empty.gif' />";
echo "<font color=\"#ffffff\">";
echo $subchannel3->attributes()->name;
echo "</font>";
echo "</td></tr>";
}else{
echo "<tr><td> ";
echo "<img src='http://view.light-speed.com//images/s_vent2/channel_1_empty.gif' />";
echo "<font color=\"#ffffff\">";
echo $subchannel3->attributes()->name;
echo "</font>";
echo "</td></tr>";
}
if($subchannel3->client){
for ( $i = 0; $i < count($subchannel3->client); $i++ ){
$client = $subchannel3->client[ $i ];
if ( $client->attributes()->cid != $client->attributes()->cid )
continue;
echo "<tr><td> ";
echo "<img src='http://view.light-speed.com//images/s_vent2/player.gif' /><font color=\"#009e1a\">";
if($client->attributes()->admin == "1"){
echo $client->attributes()->name;
echo " <font color=\"#ff0000\">(Admin)</font>";
}else{
echo $client->attributes()->name;
}
echo "</td></tr>";
}
}
}
}
}
}
echo "</table>";
?>
which shows
lobby
channel
subchannel
subchannel

How to display 2 variables in a single cell Mysql

I would like to display two picture variables in a single cell
http://i.imgur.com/9ZuRhnD.gif
$result = mysqli_query($query)
or die(mysql_error());
if (mysqli_num_rows($result) > 0) {
echo "<table border='0' style='border-collapse: collapse;border-color: white;'>";
$i = 0;
while($row = mysqli_fetch_array($result)){
$Limg = $row['Limg'];
$Limgt = $row['Limgt'];
if ($i==0) {
echo "<tr>\n";
}
echo "<td align='center' width='140'>" . "<img src=\"{$row['Limgt']}\">" ."</td>";
echo "<td align='center' width='40'>" . "<img src=\"{$row['Limg']}\">" ."</td>";
$i++;
if ($i == $items) {
echo "</tr>\n";
$i = 0;
}
}
echo '</table>';
}else {
echo 'no records found';
}
?>
What am I missing
You're putting them each in their own cell () - try this:
$result = mysqli_query($query)
or die(mysql_error());
if (mysqli_num_rows($result) > 0) {
echo "<table border='0' style='border-collapse: collapse;border-color: white;'>";
$i = 0;
while($row = mysqli_fetch_array($result)){
$Limg = $row['Limg'];
$Limgt = $row['Limgt'];
if ($i==0) {
echo "<tr>\n<td>";
}
echo "<img src=\"{$row['Limgt']}\">";
echo "<img src=\"{$row['Limg']}\">";
$i++;
if ($i == $items) {
echo "</td></tr>\n";
$i = 0;
}
}
echo '</table>';
}else {
echo 'no records found';
}
?>
you are making them in two TDs so you have to make them in one TD like that
echo "<td align='center' width='140'>
<img src=\"{$row['Limgt']}\">
<img src=\"{$row['Limg']}\">
</td>";

Categories