Compare two values with php, highlight the highest - php

I'm trying to highlight the winner in a basketball game by comparing the scores of two team, and highlighting the winner (highest score) team, by adding a class "winner" to the HTML element like this:
<ul class="game-result">
<li class="winner"><span>Team 1</span><?php echo $team1_points; ?></li>
<li class=""><span>Team 2</span><?php echo $team2_points; ?></li>
</ul>
I'm using wordpress and php, any help would be appreciated!
Thanks

Like so
<ul class="game-result">
<li <?php echo (($team1_points>$team2_points)?'class="winner"':''); ?>><span>Team 1</span><?php echo $team1_points; ?></li>
<li <?php echo (($team2_points>$team1_points)?'class="winner"':''); ?>><span>Team 2</span><?php echo $team2_points; ?></li>
</ul>

<ul class="game-result">
<li <?=($team1_points > $team2_points ? "class='winner'" : "")?> ><span>Team 1</span><?php echo $team1_points; ?></li>
</ul>

<ul class="game-result">
<li <?php echo (($team1_points>$team2_points)?'class="winner"':'class=""'); ?>><span>Team 1</span><?php echo $team1_points; ?></li>
<li <?php echo (($team2_points>$team1_points)?'class="winner"':'class=""'); ?>><span>Team 2</span><?php echo $team2_points; ?></li>
</ul>
Even though Flyer's answer is correct, this one will make your code look exactly as you posted it in the question description.

Related

How I can make drop down menu from my categories mysql table only show if parent_id is not 0

So hey there as the title said I am looking for away to make my categories with subcategories. I been looking in stackoverflow for what I need but none has help me of the examples..
Here is how my table look like
So I know what I want and what I need but I have no idea how I can do that possible
I have to SELECT * FROM categories ORDER by position ASC
I have to check if parent_id is bigger then 0.
I have to remove the parent_id from my navbar and show them only under the category name where it should be by dropdown menu .
But I have no idea how I could do all of that ..
Here is how I am selecting only my categories and display them
$catsq = mysqli_query($con,"SELECT * FROM categories ORDER by position ASC");
while($catinfo=mysqli_fetch_assoc($catsq)) {
echo '
<li class="nav-item'.(isset($_GET["cat"]) && $_GET["cat"]==$catinfo["id"] ? " active" : "").'">
<a class="nav-link" href="./index.php?cat='.$catinfo["id"].'">'.$catinfo["name"].'</a>
</li>
';
}
and it's look like this
<ul class="nav navbar-nav">
<li class="nav-item">
<a class="nav-link" href="cat=1">TestCat</a>
</li>
<li class="nav-item">
<a class="nav-link" href="cat=2">TestCat2</a>
</li>
<li class="nav-item">
<a class="nav-link" href="cat=3">TestSub</a>
</li>
</ul>
but I want It to look like this
<ul class="nav navbar-nav">
<li class="">TestCat</li>
<li class="dropdown ">
//TestCat2 have to doing nothing always.
TestCat2</i>
<ul class="dropdown-menu">
<li><a class="nav-link" href="cat=3">TestSub</a></li>
</ul>
</li>
</ul>
when the parent_id is more then 0..
If anyone can help me with this would be great..
Thanks to everybody.
There are several approaches you can take:
Build an array
Nested queries
Recursion
Array
This approach builds a data structure that you can iterate through in your view. Working example
<?php
// get db connection...
// create categories array
$stmt = mysqli_query($con, "SELECT * FROM categories ORDER BY position ASC");
while( $row = mysqli_fetch_assoc($stmt)) {
// $category[ $row['parent_id] ][ $row['id'] ] = $row; // use if you need to access other fields in addition to name
$category[ $row['parent_id] ][ $row['id'] ] = $row['name'];
}
// other php stuff...
?>
<html>
... snip ...
<ul class="nav navbar-nav">
<?php foreach($category[0] as $id => $name): ?>
<?php if( isset( $category[$id]) ): ?>
<li class="dropdown ">
<?= $name ?>
<ul class="dropdown-menu">
<?php foreach($category[$id] as $sub_id => $sub_name): ?>
<li><a class="nav-link" href="?cat=<?= $sub_id ?>" ><?= $sub_name ?></a></li>
<?php endforeach; ?>
</ul>
</li>
<?php else: ?>
<li class="">
<?= $name ?>
</li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
Nested Queries
This method is easiest to display using an imaginary class that does all the sql stuff behind the scenes. For the sake of argument, we will assume a class Category that has a method named listByParent($parent_id) which returns a list of rows having the designated parent_id.
<?php
$cat = new Category();
$topLevel = $cat->listByParent(0);
?>
<html>
... snip ...
<ul class="nav navbar-nav">
<?php foreach( $topLevel as $topRow ): ?>
<!-- note, this method is run on every iteration of top level categories -->
<?php $subRows = $cat->listByParent($topRow['id']) ?>
<?php if( count($subRows)): ?>
<li class="dropdown ">
<?= $topRow['name'] ?>
<ul class="dropdown-menu">
<?php foreach($subRows as $row): ?>
<li><a class="nav-link" href="?cat=<?= $row['id'] ?>" ><?= $row['name'] ?></a></li>
<?php endforeach; ?>
</ul>
</li>
<?php else: ?>
<li class="">
<?= $topRow['name'] ?>
</li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
Recursion
Using recursion would allow you to have “unlimited” levels of subcategories. However, it’s a level of complexity that does not seem warranted in this case. But should you want to pursue it, note that the best way to approach it would be to make a template for the html that could be accessed programatically, with $cat->findByParent() being a key player...

Bootstrap multi-level drop down not working

I am working on a PHP website. And for some reasons, I need to add multiple level dropdown in my navigation bar. I tried the bootstrap class="dropdown-submenu" but I don't know why it has not worked.
<ul class="dropdown-menu">
<?php
$alllinks = mysql_query("SELECT `cid`, `cname` FROM `services` WHERE `parentid`=0");
while($reslink = mysql_fetch_assoc($alllinks)){ ?>
<li class="dropdown-submenu">
<a tabindex="-1" href="<?php echo MYWEBSITE;?>services/<?php echo to_prety_url($reslink['cname']).'-'.$reslink['cid'];?>.html">
<?php echo $reslink['cname'];?>
</a>
<ul class="dropdown-menu">
<li>
<a href="<?php echo MYWEBSITE;?>servicedetail/<?php echo to_prety_url($rowsb['cname']).'-'.$rowsb['cid'];?>.html">
<?php echo $rowsb['cname'];?>
</a>
</li><br>
</ul>
</li><br>
<?php } ?>
</li>
</ul>
Throughout your code You haven't enclosed MYWEBSITE in inverted comma's
you have written.
<?php echo MYWEBSITE;?>
whereas you should write
<?php echo "MYWEBSITE";?>
and You are using the old and Deprecated mysql connector it is higly recommended that you switch to PDO or mysqli.

Ordered list numbering not working properly while pagination

I am using ordered list with php and its working fine and showing the numbers 1-10 correctly but in the next page its starting again from 1 for different list. I have tried some solutions found in this site, but not working. Given below is my code so far. Here $startpoint =10;
<ol start="<?php echo $startpoint;?>">
<li>
<?php echo $objA->stringtag($question); ?>
</li>
</ol>
Try to something like this. I think in your File not getting $startpoint value. So, it's start with 1.
<?php $startpoint = 10; ?>
<ol start="<?php echo $startpoint;?>">
<li><?php echo 'teastesest' ?> </li>
<li><?php echo 'teastesest' ?> </li>
<li><?php echo 'teastesest' ?> </li>
<li><?php echo 'teastesest' ?> </li>
</ol>

How to add a new link in admin navigation menu using OpenCart?

Today I am studying OpenCart for my next project. And I am having a trouble with my code. What I want to do is to simply add another link in admin navigation menu under the Catalog list. But whenever I edit the header.tpl it doesn't show my update. Here's what I did.
I add another link named 'mypage'
The file is located at: admin/view/template/common/header.tpl
Here's my update
<div id="menu">
<ul class="left" style="display: none;">
<li id="dashboard"><?php echo $text_dashboard; ?></li>
<li id="catalog"><a class="top"><?php echo $text_catalog; ?></a>
<ul>
<li><?php echo $text_category; ?></li>
<li><?php echo $text_product; ?></li>
<li><?php echo $text_filter; ?></li>
<li><?php echo $text_profile; ?></li>
<li><a class="parent"><?php echo $text_attribute; ?></a>
<ul>
<li><?php echo $text_attribute; ?></li>
<li><?php echo $text_attribute_group; ?></li>
</ul>
</li>
<li><?php echo $text_option; ?></li>
<li><?php echo $text_manufacturer; ?></li>
<li><?php echo $text_download; ?></li>
<li><?php echo $text_review; ?></li>
<li><?php echo $text_information; ?></li>
<li><?php echo $text_mypage; ?></li>
</ul>
</li>
As you can see I added another link below information.
Now the next step I include the language variable in the controller
The file is located at: admin/controller/header.php
I added this line:
$this->data['text_mypage'] = $this->language->get('text_mypage');
Now the last step I did is I include the link in my language file
The file is located at: admin/language/english/common/header.php
I added this line:
$_['text_mypage'] = 'My Page';
Now my problem is it doesn't show my link. I don't know where did I get wrong. Please help me I am new in this framework. I also cleared the cache manually but same effect.
Jerielle,
I think you are missing a point here in this file.
in admin/controller/header.php
you also need to define
$this->data['mypage'] = $this->url->link('your_link', 'token=' .
$this->session->data['token'], 'SSL');
like this.
Check this page carefully you will find this section on this file..

how to generate a serverside menu with 3 levels?

I am trying to generate the bellow menu dynamically using php and mysql
<ul id="prod_nav" class="clearfix">
<!-- top --> <li class="active"><span class="down">Clothes</span>
<ul>
<h1> Men </h1>
<li>Shirt </li>
<li>T-shirt </li>
<li>Polo shirt </li>
<li>Formal shoes </li>
<li>Sport shoes </li>
<li>Suit </li>
<li>Underwear </li>
<li>Socks </li>
<li>Pants </li>
</ul>
<ul>
<h1> Women </h1>
<li>Shirt </li>
<li>T-shirt </li>
<li>Polo shirt </li>
<li>High heel shoes </li>
<li>Sport shoes </li>
<li>Wedding clothes </li>
<li>Underwear </li>
<li>Leather </li>
<li>Socks </li>
<li>Pants </li>
</ul>
</li>
</ul>
but I am not sure which way is the best principals for generating the menu?
should I use while loop and if or Case or for loop?
which way is the best way?
Thanks
You should have an array
$a=array('shirt','t-shirt','polo shirt','formal shoes','sport shoes','suit','underwear','socks','pants');
and use it like this:
<ul>
<h1>MEN</h1>
<?php foreach($a as $val) :?>
<li><?php echo $val; ?></li>
<?php endforeach ;?>
</ul>
<ul>
<h1>womaen</h1>
<?php foreach($a as $val) :?>
<li><?php echo $val; ?></li>
<?php endforeach ;?>
</ul>
$gender = array('men','women');
$productlist = array('shirt','t-shirt','polo shirt','formal shoes','sport shoes','suit','underwear','socks','pants');
foreach($gender as $individual) {
echo "<h2>{$individual}</h2>";
echo "<ul>";
foreach($productlist as $product) {
<li><?php echo $product; ?></li>
}
echo "</ul>";
}
can you please used this:
$gender = array('men','women');
$productlist = array('shirt'=>'shirt_url.php','t-shirt'=>'t-shirt_url.php','polo shirt'=>'polo_shirt.php');
foreach($gender as $individual) {
echo "<h2>{$individual}</h2>";
echo "<ul>";
foreach($productlist as $product_key=>$product_url) {
?>
<li><?php echo $product_key; ?></li>
<?php
}
echo "</ul>";
}

Categories