Jump to content

If number is larger than...


Hrvoje

Recommended Posts

Hello,

 

need some help.

 

 

I have this code to see if there is any 0 number in field.

<?PHP
$boja1="divclass1";
$boja2="divclass2";

$provjera="SELECT kolicina FROM stanje_lijekova WHERE kolicina= 0";

if (!$q=mysql_query($provjera))
{
echo "Error" . mysql_query();
die();
}

if (mysql_num_rows($q)>0)
    {
        $boja1;
    }
    else
    {
        $boja2;
    }
?>

How can I make this code to echo one of two variables with div class. If row have number 0 in field than my class need divclass1 if any other number than is divclass2.

<div class='here i need that echo'>some code</div>

And my dba:

 

34fy9f7.jpg

 

This is classic mouse hover css:

 

o06mpe.jpg

Edited by Hrvoje
Link to comment
Share on other sites

Then your code doesn't match up with your screenshot?

 

Easiest way: do the query to get the data you want, like normal. Maybe

SELECT naziv_lijeka, sifra, jedmjera, kolicina FROM stanje_lijekova WHERE some condition
Then do another query that looks similar but gets a count of how many rows have kolicina=0.

SELECT COUNT(1) FROM stanje_lijekova WHERE some condition AND kolicina = 0
The first value in the first row will tell you how many there are. So don't use mysql_num_rows() for it.
Link to comment
Share on other sites

This is code that show that records:

<?PHP
include("config.php");
$sql="SELECT * FROM stanje_lijekova ORDER BY naziv_lijeka ASC";
if (!$q=mysql_query($sql))
{
echo "Error" . mysql_query();
die();
}

if (mysql_num_rows($q)==0)
{
echo "No data!";
} else {

while ($redak=mysql_fetch_array($q))
{

echo "
<div class='podatak'>
<div class='naziv_lijeka_p'><p class='polje_tekst'> ".$redak['naziv_lijeka']."</p></div>
<div class='sifra_p'><p class='polje_tekst'> ".$redak['sifra']."</p></div>
<div class='jed_mjera_p'><p class='polje_tekst'> ".$redak['mjera']."</p></div>
<div class='kolicina_p'><p class='polje_tekst'> ".$redak['kolicina']."</p></div>
<div class='ostalo_p'><p class='polje_tekst'></p></div>
</div>";
}};
?>

I apologise for wrong code upper.

Link to comment
Share on other sites

Alright so we're back to my original interpretation of your question.

 

$redak['kolicina'] is the value. If the value is 0 then output one class, otherwise output another class. And as you already know the HTML markup will look like

So put the right class name in there.
Link to comment
Share on other sites

Okay. So.

echo "
<div class='podatak'>
That's where the class needs to go. You already have

$boja1="divclass1";
$boja2="divclass2";
but I don't know which is the normal class and which is the highlight class so I'm just going to guess.

 

Use an if to decide which class you should use.

if ($redak['kolicina'] == 0) {
	$boja = $boja1;
} else {
	$boja = $boja2;
}
Now put that variable into the HTML.

echo "
<div class='podatak {$boja}'>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.