Page 1 of 1
if No Records show me!
Posted: Mon Sep 02, 2002 4:53 pm
by jbdphp
Hello having trouble with a simple script. I can get the data out perfect but I need it to display "No Records" if there are no records in the query. Here is my code, I am sorry if it's sloppy! Thanks in advance!
Code: Select all
<?php
//******* this is part of a script so assume I already connected to my db
$showzsql = mysql_query("SELECT * FROM shows WHERE bandaide_band = '$bname' ORDER BY sdfdb ASC");
//******************* here is my problem!!!!!
$row = mysql_fetch_row($showzsql);
if($row = 0) {
echo "no records!";
} else {
//*********************************************************
while($x=mysql_fetch_array($showzsql)) {
$sid = $xї"sid"];
$show_date = $xї"show_date"];
$venue = $xї"venue"];
echo "<tr align="center"><td>$show_date</td><td>$venue</td><td><a href="index.php?location=showz&sid=$sid">MORE INFO</a></tr>";
}
?>
<? } ?>
Posted: Mon Sep 02, 2002 5:30 pm
by hob_goblin
Code: Select all
<?
$showzsql = mysql_query("SELECT * FROM shows WHERE bandaide_band = '$bname' ORDER BY sdfdb ASC");
$row = mysql_num_rows($showzsql);
if($row = 0) {
echo "no records!";
} else {
while($x= mysql_fetch_array($showzsql)) {
$sid = $xї"sid"];
$show_date = $xї"show_date"];
$venue = $xї"venue"];
echo "<tr align="center"><td>$show_date</td><td>$venue</td><td><a href="index.php?location=showz&sid=$sid">MORE INFO</a></tr>";
}
}
?>
close but...
Posted: Mon Sep 02, 2002 5:42 pm
by jbdphp
It still doesn't print "no records!" Any other suggestions?
Posted: Mon Sep 02, 2002 7:40 pm
by volka
use hob_goblin's code but change
to
your code will skip the first record
Posted: Mon Sep 02, 2002 7:44 pm
by volka
merde, I was too slow altering my post

Posted: Mon Sep 02, 2002 7:46 pm
by gotDNS
make:
Code: Select all
<?php
//******* this is part of a script so assume I already connected to my db
$showzsql = mysql_query("SELECT * FROM shows WHERE bandaide_band = '$bname' ORDER BY sdfdb ASC");
//******************* here is my problem!!!!!
$row = mysql_fetch_row($showzsql);
$rowcount = mysql_num_rows($row);
if($rowcount == '0') {
echo "no records!";
} else {
//*********************************************************
while($x=mysql_fetch_array($showzsql)) {
$sid = $xї"sid"];
$show_date = $xї"show_date"];
$venue = $xї"venue"];
echo "<tr align="center"><td>$show_date</td><td>$venue</td><td><a href="index.php?location=showz&sid=$sid">MORE INFO</a></tr>";
}
?>
<? } ?>
this:
Code: Select all
<?php
<?php
//******* this is part of a script so assume I already connected to my db
$showzsql = mysql_query("SELECT * FROM shows WHERE bandaide_band = '$bname' ORDER BY sdfdb ASC");
//******************* here is my problem!!!!!
$row = mysql_fetch_row($showzsql);
if($row = 0) {
echo "no records!";
} else {
//*********************************************************
while($x=mysql_fetch_array($showzsql)) {
$sid = $xї"sid"];
$show_date = $xї"show_date"];
$venue = $xї"venue"];
echo "<tr align="center"><td>$show_date</td><td>$venue</td><td><a href="index.php?location=showz&sid=$sid">MORE INFO</a></tr>";
}
}
?>
?>
later on, -Brian
Posted: Mon Sep 02, 2002 7:53 pm
by volka
almost

Posted: Mon Sep 02, 2002 8:47 pm
by gotDNS
SCRATH that last post...messed it up...THIS:
make this:
Code: Select all
<?php
//******* this is part of a script so assume I already connected to my db
$showzsql = mysql_query("SELECT * FROM shows WHERE bandaide_band = '$bname' ORDER BY sdfdb ASC");
//******************* here is my problem!!!!!
$row = mysql_fetch_row($showzsql);
if($row = 0) {
echo "no records!";
} else {
//*********************************************************
while($x=mysql_fetch_array($showzsql)) {
$sid = $xї"sid"];
$show_date = $xї"show_date"];
$venue = $xї"venue"];
echo "<tr align="center"><td>$show_date</td><td>$venue</td><td><a href="index.php?location=showz&sid=$sid">MORE INFO</a></tr>";
}
?>
<? } ?>
this:
Code: Select all
<?php
//******* this is part of a script so assume I already connected to my db
$showzsql = mysql_query("SELECT * FROM shows WHERE bandaide_band = '$bname' ORDER BY sdfdb ASC");
//******************* here is my problem!!!!!
$row = mysql_fetch_row($showzsql);
$rowcount = mysql_num_rows($row);
if($rowcount == '0') {
echo "no records!";
} else {
//*********************************************************
while($x=mysql_fetch_array($showzsql)) {
$sid = $xї"sid"];
$show_date = $xї"show_date"];
$venue = $xї"venue"];
echo "<tr align="center"><td>$show_date</td><td>$venue</td><td><a href="index.php?location=showz&sid=$sid">MORE INFO</a></tr>";
}
}
?>
later on, -Brian
Posted: Mon Sep 02, 2002 9:22 pm
by volka
h3h3, I know this and when it happens to me I try to be fast enough changing it before someone notices - unfortunately that doesn't work often

Posted: Mon Sep 02, 2002 9:58 pm
by gotDNS
Hush, Volka.

I figure, if i think i have it right, move on to another post...don't lniger...and as soon as i saw ur post, I changed it...but sadly it'll take someone else relentlest torrent to make me see it...or an "Almost"
later on, -Brian
Posted: Tue Sep 03, 2002 3:11 am
by mikeq
jbdphp, it is better to not use things like $x in your code make it more meaningful, something like $ShowsRecord would better describe what you have returned from the database.
Posted: Tue Sep 03, 2002 5:50 pm
by jbdphp
mikeq wrote:jbdphp, it is better to not use things like $x in your code make it more meaningful, something like $ShowsRecord would better describe what you have returned from the database.
Thank you Mike I will keep that in mind.