View previous topic :: View next topic |
Author |
Message |
Tim1681 -
Joined: 17 Jan 2005 Posts: 160 Location: Bristol, CT, USA
|
Posted: Sun Jul 24, 2005 2:35 am Post subject: If Rows Returned = 0 (MySQL) |
|
|
Kind of a newbie question but i havent tried this yet. I have a part in a website im making where it displays Events that are happening on the Current Date, how would i tell it when the Rows Returned are = 0 to echo "No Events Today? I've Tried
Code: | if($row['name'] == "") |
but that apparently wont work. Heres the full code that i tried.
Code: | $query = "SELECT * FROM upcoming_shows WHERE date = CURDATE() ORDER BY name";
$result = mysql_query($query)
or die("Query Failed: ".mysql_error());
while ($row = mysql_fetch_array($result))
{
if($row['name'] == "")
{
echo "<tr><td>No Events Today</td></tr>";
}
else
{
echo "<tr><td valign='center' style='border-bottom: solid 1px #ff0000;'><a href='../events.php?e=", $row['name'], "' target='_parent'>", $row['name'], "</a></td><td align='right' style='border-bottom: solid 1px #ff0000;'>", $row['date_read'], "</td></tr>";
}
} |
|
|
Back to top |
|
 |
k1ll3rdr4g0n -
Joined: 04 Jul 2004 Posts: 609
|
Posted: Sun Jul 24, 2005 5:08 am Post subject: |
|
|
Try this:
Code: | if(mysql_affected_rows()==0){
print 'nothing today';
} |
_________________
 |
|
Back to top |
|
 |
Tim1681 -
Joined: 17 Jan 2005 Posts: 160 Location: Bristol, CT, USA
|
Posted: Sun Jul 24, 2005 3:06 pm Post subject: |
|
|
Still isn't working. What makes me mad is that when there is actually an event it shows the text for the event thats happaning, but when there is no event for that day it doesnt show the "No Events" that i tell it to. I even moved the script around to see if it was a different problem but it still worked fine except for the "No Events".
Code: | while ($row = mysql_fetch_array($result))
{
if(mysql_affected_rows() !== 0)
{
echo "<tr><td>EVENT</td></tr>";
}
else
{
echo "<tr><td>No Events Today</td></tr>";
}
} |
|
|
Back to top |
|
 |
MonkeyNation -
Joined: 05 Feb 2005 Posts: 921 Location: Cardiff
|
Posted: Sun Jul 24, 2005 3:58 pm Post subject: |
|
|
Code: | if (mysql_num_rows($sql_query_variable) > 0) {
//Events
} else {
echo "No events.";
} |
Im back after my lan went boom =S _________________

Last edited by MonkeyNation on Sun Jul 24, 2005 3:59 pm; edited 1 time in total |
|
Back to top |
 |
 |
p3 -
Joined: 17 Jun 2005 Posts: 615
|
Posted: Sun Jul 24, 2005 3:59 pm Post subject: |
|
|
MonkeyNation wrote: | Code: | if (mysql_num_rows > 0) {
//Events
} else {
echo "No events.";
} |
Im back after my lan went boom =S |
Good to see you back, MonkeyNation. |
|
Back to top |
|
 |
MonkeyNation -
Joined: 05 Feb 2005 Posts: 921 Location: Cardiff
|
Posted: Sun Jul 24, 2005 4:00 pm Post subject: |
|
|
p3 wrote: | MonkeyNation wrote: | Code: | if (mysql_num_rows($sql_query_variable) > 0) {
//Events
} else {
echo "No events.";
} |
Im back after my lan went boom =S |
Good to see you back, MonkeyNation. |
10 seconds after my first post I get welcomed back =) _________________
 |
|
Back to top |
 |
 |
k1ll3rdr4g0n -
Joined: 04 Jul 2004 Posts: 609
|
Posted: Sun Jul 24, 2005 4:00 pm Post subject: |
|
|
Hmm...it works in my script (for a login script) try...
Code: | $query = "SELECT * FROM upcoming_shows WHERE date = CURDATE() ORDER BY name";
$result = mysql_query($query) or die("Query Failed: ".mysql_error());
if(mysql_affected_rows()==0){
echo 'oh nothing today';
} else { while ($row = mysql_fetch_array($result))
{
echo "<tr><td valign='center' style='border-bottom: solid 1px #ff0000;'><a href='../events.php?e=", $row['name'], "' target='_parent'>", $row['name'], "</a></td><td align='right' style='border-bottom: solid 1px #ff0000;'>", $row['date_read'], "</td></tr>";
}
} |
That should work..If not you wanna send over a sample of your mysql table. :). _________________
 |
|
Back to top |
|
 |
p3 -
Joined: 17 Jun 2005 Posts: 615
|
Posted: Sun Jul 24, 2005 4:01 pm Post subject: |
|
|
MonkeyNation wrote: | p3 wrote: | MonkeyNation wrote: | Code: | if (mysql_num_rows($sql_query_variable) > 0) {
//Events
} else {
echo "No events.";
} |
Im back after my lan went boom =S |
Good to see you back, MonkeyNation. |
10 seconds after my first post I get welcomed back =) |
:) |
|
Back to top |
|
 |
Tim1681 -
Joined: 17 Jan 2005 Posts: 160 Location: Bristol, CT, USA
|
Posted: Sun Jul 24, 2005 4:04 pm Post subject: |
|
|
Thnx k1ll3rdr4g0n works like a charm =) |
|
Back to top |
|
 |
k1ll3rdr4g0n -
Joined: 04 Jul 2004 Posts: 609
|
Posted: Sun Jul 24, 2005 4:15 pm Post subject: |
|
|
Tim1681 wrote: | Thnx k1ll3rdr4g0n works like a charm =) |
:D, your welcome. _________________
 |
|
Back to top |
|
 |
Tim1681 -
Joined: 17 Jan 2005 Posts: 160 Location: Bristol, CT, USA
|
Posted: Wed Jul 27, 2005 3:23 am Post subject: |
|
|
Another Question..
I have a Marquee on my Index page of this site, and the MySQL Select Query is:
Code: | $query = "SELECT * FROM upcoming_shows WHERE date = CURDATE() ORDER BY name"; |
This only selects the entries where the date is equal to the server's CURDATE(). Now the question, there is an Event where it runs for 2 dates, 2005-08-06 and 2005-08-07 .. If i entered:
Code: | 2005-08-06, 2005-08-07 |
into the MySQL table under the Date category, would it still be read by PHP for both dates? Or is there some other Syntax i should be using which does the same as what i'm trying to achieve? |
|
Back to top |
|
 |
k1ll3rdr4g0n -
Joined: 04 Jul 2004 Posts: 609
|
Posted: Wed Jul 27, 2005 5:15 am Post subject: |
|
|
try...
Code: | $query = "SELECT * FROM upcoming_shows WHERE date = 2005-08-06, 2005-08-07 ORDER BY name"; |
_________________
 |
|
Back to top |
|
 |
Tim1681 -
Joined: 17 Jan 2005 Posts: 160 Location: Bristol, CT, USA
|
Posted: Wed Jul 27, 2005 12:28 pm Post subject: |
|
|
Well the problem is that it isnt just THAT event, theres a whole list of them. I set it up so there is a Marquee which displays wether there is an event that day ( WHERE date = CURDATE() ), and below it is a table with all the Upcoming Events ( WHERE date > CURDATE() ). Thats why im having the problem.
I was hoping that if I used the "," that PHP would Read each date seperately and it would be placed in the Marquee on both dates. I havent tried it yet but I will today, but before I do, do u have any other ideas that u believe might work? :D |
|
Back to top |
|
 |
MonkeyNation -
Joined: 05 Feb 2005 Posts: 921 Location: Cardiff
|
Posted: Wed Jul 27, 2005 6:18 pm Post subject: |
|
|
Make 2 rows; 1 for each date.
It will undoubtably appear in upcoming events too, but you could easily put an
Code: | if ($row['date'] !== "1/2/3") { //Show mysql result } |
as a temporary solution.
Or if you plan to do this more often youll have to add another column called 'extended' or something, and if its a multidate marquee then make 'extended' 1 or something and make a check that $row['extended'] isnt 1 before it shows upcoming events. _________________
 |
|
Back to top |
 |
 |
Tim1681 -
Joined: 17 Jan 2005 Posts: 160 Location: Bristol, CT, USA
|
Posted: Wed Jul 27, 2005 8:32 pm Post subject: |
|
|
Yea, I will probably just make 2 Rows in the table. Thnx for all the help. |
|
Back to top |
|
 |
|