Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
npereira
Forum Newbie
Posts: 10 Joined: Wed Sep 04, 2002 12:15 pm
Post
by npereira » Wed Sep 04, 2002 12:15 pm
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"; }
while ($r1 = mysql_fetch_array($q1)) {
echo "<p><a href="/annonce.php" class="mma"><span class="mma">".htmlentities($r1ї"titre"])."</span></a></p><br>\n";}
haagen
Forum Commoner
Posts: 79 Joined: Thu Jul 11, 2002 3:57 pm
Location: Sweden, Lund
Post
by haagen » Wed Sep 04, 2002 1:11 pm
Code: Select all
if($n1 == 0){
echo "this message";
} else if($n1 > 0){
echo "something else";
while ($r1 = mysql_fetch_array($q1)) {
echo "<p><a href="/annonce.php" class="mma">";
echo "<span class="mma">".htmlentities($r1ї"titre"]);
echo "</span></a></p><br>\n";
}
}
But I'm not sure I understand your problem. Maybe you have forgotten to assign $n1:
npereira
Forum Newbie
Posts: 10 Joined: Wed Sep 04, 2002 12:15 pm
Post
by npereira » Wed Sep 04, 2002 1:24 pm
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){
echo "<p align="center">Aucune annonce classée.</p>\n";
} else if($n1 > 0){
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)) {
echo "<p><a href="/annonce.php" class="mma">";
echo "<span class="mma">".htmlentities($r1ї"titre"]);
echo "</span></a></p><br>\n";
}
}
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 » Wed Sep 04, 2002 3:20 pm
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){
echo "<p align="center">Aucune annonce classée inscrite. Pour inscrire une annonce, <a href="/annonce.php">Cliquer ICI</a></p>\n";
} else if($n1 > 0){
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)) {
echo "<p class="mm">• <a href="/annonce.php" class="mma">";
echo "<span class="mma">".htmlentities($r1ї"titre"]);
echo "</span></a></p><br>\n";
}
}
Thanks Haagen