Problem with If statement ...

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
npereira
Forum Newbie
Posts: 10
Joined: Wed Sep 04, 2002 12:15 pm

Problem with If statement ...

Post by npereira »

Hi,

Here is what i want to do. See code bellow.

if $n1 == 0 , i want it to echo "this message"

if $n1 >= 1 , i want it to echo "something else"
while inserting the record as a link to it.

Let me know if you can help!

Here is the code;

Code: Select all

tTbl("Annonces classées", "left");
$q1 = mysql_query("SELECT *, DATE_FORMAT(date, '$site_date_jh') AS dateh FROM annonce ORDER BY date DESC LIMIT ".$max_annonce);
if ($n1 == 0) {
	echo "<p align="center">Voici les dernières annonces classées. Cliquez sur le titre pour y accéder.</p>\n"; &#125;
while ($r1 = mysql_fetch_array($q1)) &#123;
	echo "<p><a href="/annonce.php" class="mma"><span class="mma">".htmlentities($r1&#1111;"titre"])."</span></a></p><br>\n";&#125;
User avatar
haagen
Forum Commoner
Posts: 79
Joined: Thu Jul 11, 2002 3:57 pm
Location: Sweden, Lund

Post by haagen »

Code: Select all

if($n1 == 0)&#123;
  echo "this message";
&#125; else if($n1 > 0)&#123;
  echo "something else";
  while ($r1 = mysql_fetch_array($q1)) &#123; 
    echo "<p><a href="/annonce.php" class="mma">";
    echo "<span class="mma">".htmlentities($r1&#1111;"titre"]);
    echo "</span></a></p><br>\n";
  &#125; 
&#125;
But I'm not sure I understand your problem. Maybe you have forgotten to assign $n1:

Code: Select all

$n1 = mysql_num_rows($q1)
npereira
Forum Newbie
Posts: 10
Joined: Wed Sep 04, 2002 12:15 pm

Post by npereira »

Here is what the code looks like now.

Code: Select all

tTbl("Annonces classées", "left");
$q1 = mysql_query("SELECT *, DATE_FORMAT(date, '$site_date_jh') AS dateh FROM annonce ORDER BY date DESC LIMIT ".$max_annonce);
if($n1 == 0)&#123; 
  echo "<p align="center">Aucune annonce classée.</p>\n"; 
&#125; else if($n1 > 0)&#123; 
  echo "<p align="center">Voici les dernières annonces classées. Cliquez sur le titre pour y accéder.</p>\n"; 
  while ($r1 = mysql_fetch_array($q1)) &#123; 
    echo "<p><a href="/annonce.php" class="mma">"; 
    echo "<span class="mma">".htmlentities($r1&#1111;"titre"]); 
    echo "</span></a></p><br>\n"; 
  &#125; 
&#125;
Although, when $n1 > 0 , the record does not show up.

Something is missing but I cannot figure out what.
npereira
Forum Newbie
Posts: 10
Joined: Wed Sep 04, 2002 12:15 pm

Post by npereira »

Finaly got it working good and the way I wanted. here is what is looks like.

Code: Select all

tTbl("Les Annonces Classées", "left");
$q1 = mysql_query("SELECT idx, titre FROM annonce ORDER BY date DESC LIMIT 5");
$n1 = mysql_num_rows($q1);
if($n1 == 0)&#123; 
  echo "<p align="center">Aucune annonce classée inscrite. Pour inscrire une annonce, <a href="/annonce.php">Cliquer ICI</a></p>\n"; 
&#125; else if($n1 > 0)&#123; 
  echo "<p align="center">Voici les dernières annonces classées. Cliquez sur le titre pour y accéder.</p>\n"; 
  while ($r1 = mysql_fetch_array($q1)) &#123; 
    echo "<p class="mm">&#8226; <a href="/annonce.php" class="mma">"; 
    echo "<span class="mma">".htmlentities($r1&#1111;"titre"]); 
    echo "</span></a></p><br>\n"; 
  &#125; 
&#125;
Thanks Haagen
Post Reply