# Php calendar

**URL:** <https://forum.kirupa.com/t/php-calendar/58983>\
**Category:** Uncategorized\
**Created:** [July 27, 2004, 3:22pm UTC](https://forum.kirupa.com/t/php-calendar/58983 "2004-07-27T15:22:57Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![SlowRoasted](https://avatars.discourse-cdn.com/v4/letter/s/a698b9/32.png) [@SlowRoasted](https://forum.kirupa.com/u/SlowRoasted)\
**Post date:** [July 27, 2004, 3:22pm UTC](https://forum.kirupa.com/t/php-calendar/58983/1 "2004-07-27T15:22:57Z")

</div>

ok this is my first time really working with php, im usually working with coldfusion but im not awesome at that either. Im trying to display some of the fields in a calendar database. There are like 5 fields but i am only displaying 2 of them for this particular page. Could you see what im doing wrong here, im getting this error:

Warning: mysql\_num\_rows(): supplied argument is not a valid MySQL result resource on line 44

Here is my code:

```php

<?php
require_once('mysql_connect.php');
$query = "Select(date, subject)";
$result = @mysql_query($query);
$num = mysql_num_rows($result);

if($num > 0){
echo'<table border="0" cellspacing="0" cellpadding="0">';
while($row = mysql_fetch_array($result, MYSQL_NUM)){
echo'<tr><td><span class="style13">$row[0]</span></td></tr>';
}
echo'</table>';
mysql_free_result($result);
}
else{
echo'<span class="style13">The calendar is experiencing technical difficulties. We apologize for the inconvenience.</span>';
}
mysql_close();
?>

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 27, 2004, 3:29pm UTC](https://forum.kirupa.com/t/php-calendar/58983/2 "2004-07-27T15:29:47Z")

</div>

```php

 #take this part out
 $num = mysql_num_rows($result);
 
 if($num > 0){ 
 

```

```php

 #instead you can do.
 while($row = mysql_fetch_assoc($result)){ 
 if ($row[0] != NULL) {
 echo'<tr><td><span class="style13">$row[0]</span></td></tr>';
 }
 else
 {
echo'<span class="style13">The calendar is experiencing technical difficulties. We apologize for the inconvenience.</span>'; 
 }
 echo'</table>'; 
 

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 27, 2004, 4:01pm UTC](https://forum.kirupa.com/t/php-calendar/58983/3 "2004-07-27T16:01:07Z")

</div>

ok im getting a parse error, here is what i have now

```php

<?php
require_once('mysql_connect.php');
$query = "Select(date, subject)";
$result = @mysql_query($query);

while($row = mysql_fetch_assoc($result)){ 
if ($row[0] != NULL) {
echo'<tr><td><span class="style13">$row[0]</span></td></tr>';
}
else
{
echo'<span class="style13">The calendar is experiencing technical difficulties. We apologize for the inconvenience.</span>'; 
}
echo'</table>'; 
mysql_free_result($result);
mysql_close();
?>

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 27, 2004, 4:09pm UTC](https://forum.kirupa.com/t/php-calendar/58983/4 "2004-07-27T16:09:21Z")

</div>

Altho i might have a clue on the parse error, i would be nice to state where the parse error occurs

```php

   #if i am correct try, my monitor is messes up
  #@ the moment so i cant really see the nice hightlighted colors :(
  $query = "SELECT * FROM --TABLENAME--"; 
  $result = mysql_query($query) or die (mysql_error());
    if ($row['0'] != NULL) {
   echo '<tr><td><span class="style13">"'.$row['0'].'"</span></td></tr>';
   }
   else
   {
 echo'<span class="style13">The calendar is experiencing technical difficulties. We apologize for the inconvenience.</span>';
   }
   

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 27, 2004, 4:13pm UTC](https://forum.kirupa.com/t/php-calendar/58983/5 "2004-07-27T16:13:28Z")

</div>

```php

<html>
<head>
<title>The Edge Homepage</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

</style>
</head>
<body bgcolor="#1F7697" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" bottommargin="0">

<?php
require_once('mysql_connect.php');
$query = "Select(date, subject)";
$result = @mysql_query($query);

while($row = mysql_fetch_assoc($result)){ 
if ($row[0] != NULL) {
echo'<tr><td><span class="style13">"'.$row[0].'"</span></td></tr>';
}
else
{
echo'<span class="style13">The calendar is experiencing technical difficulties. We apologize for the inconvenience.</span>'; 
}
echo'</table>'; 
mysql_free_result($result);
mysql_close();
?>
</body>
</html>

```

The parse error is on line 29- last line

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 27, 2004, 4:14pm UTC](https://forum.kirupa.com/t/php-calendar/58983/6 "2004-07-27T16:14:25Z")

</div>

you forgot an closing bracket } 🙂

the wile has not been closed

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 27, 2004, 4:17pm UTC](https://forum.kirupa.com/t/php-calendar/58983/7 "2004-07-27T16:17:50Z")

</div>

pwahaha, i know it was gonna be something stupid like that:

let me try it out

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 27, 2004, 4:20pm UTC](https://forum.kirupa.com/t/php-calendar/58983/8 "2004-07-27T16:20:30Z")

</div>

argh more problems

```php

<?php
require_once('mysql_connect.php');
$query = "Select(date, subject)";
$result = @mysql_query($query);

while($row = mysql_fetch_assoc($result)){ 
if ($row[0] != NULL) {
echo'<tr><td><span class="style13">"'.$row[0].'"</span></td></tr>';
}
else
{
echo'<span class="style13">The calendar is experiencing technical difficulties. We apologize for the inconvenience.</span>'; 
}
}
echo'</table>'; 
mysql_free_result($result);
mysql_close();
?>

```

Warning: mysql\_fetch\_assoc(): supplied argument is not a valid MySQL result resource in /home/theedgem/public\_html/calendar.php on line 16

Warning: mysql\_free\_result(): supplied argument is not a valid MySQL result resource in /home/theedgem/public\_html/calendar.php on line 26

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 27, 2004, 4:26pm UTC](https://forum.kirupa.com/t/php-calendar/58983/9 "2004-07-27T16:26:02Z")

</div>

```php

$query = "SELECT * FROM --TABLENAME--"; 
$result = mysql_query($query) or die (mysql_error());
# :)

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 27, 2004, 4:32pm UTC](https://forum.kirupa.com/t/php-calendar/58983/10 "2004-07-27T16:32:21Z")

</div>

thanks so much for your help, that worked;)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 27, 2004, 10:38pm UTC](https://forum.kirupa.com/t/php-calendar/58983/11 "2004-07-27T22:38:54Z")

</div>

argh got another problem, my if statement isnt validating so its skipping to the else. Whats going on?

```php

<html>
<head>
<title>The Edge Homepage</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

</style>
</head>
<body bgcolor="#1F7697" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" bottommargin="0">

<?php
require_once('mysql_connect.php');
$query = "SELECT date, subject FROM Calendar"; 
$result = mysql_query($query) or die (mysql_error()); 

while($row = mysql_fetch_assoc($result)){ 
if ($row[0] != NULL) {
echo'<tr><td><span class="style13">"'.$row[0].'"</span></td></tr>';
}
else
{
echo'<span class="style13">The calendar is experiencing technical difficulties. We apologize for the inconvenience.</span>'; 
}
}
echo'</table>'; 
mysql_free_result($result);
mysql_close();
?>
</body>
</html>

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 27, 2004, 10:44pm UTC](https://forum.kirupa.com/t/php-calendar/58983/12 "2004-07-27T22:44:03Z")

</div>

also, whats a better way to set up that if statement because if it doesnt validate then the else statement runs as many times as there are items in the database.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 28, 2004, 3:09am UTC](https://forum.kirupa.com/t/php-calendar/58983/13 "2004-07-28T03:09:54Z")

</div>

_bump_

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 28, 2004, 3:14am UTC](https://forum.kirupa.com/t/php-calendar/58983/14 "2004-07-28T03:14:06Z")

</div>

you could use an elseif(i=0) echo whatever and set i at the beginning and incrament it after the cho 😉

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 28, 2004, 3:27am UTC](https://forum.kirupa.com/t/php-calendar/58983/15 "2004-07-28T03:27:00Z")

</div>

ok i redid the code a little but im getting a parse error on line 26

```php

<html>
<head>
<title>The Edge Homepage</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.style1 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 7pt;
	color: #FFFFFF;
}
</style>
</style>
</head>
<body bgcolor="#1F7697" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" bottommargin="0">

<?php
require_once('mysql_connect.php');
$query = "SELECT date, subject FROM Calendar"; 
$result = mysql_query($query) or die (mysql_error()); 
$num = mysql_num_rows($result);

if($num > 0){
while($row = mysql_fetch_array($result, MYSQL_NUM))(

echo"<tr><td>$row[0]</td><td>$row[1]</td></tr>";
}
}
else
{
echo'<span class="style1">The calendar is experiencing technical difficulties. We apologize for the inconvenience.</span>'; 
}
}
echo'</table>'; 
mysql_free_result($result);
mysql_close();
?>
</body>
</html>

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 28, 2004, 3:49am UTC](https://forum.kirupa.com/t/php-calendar/58983/16 "2004-07-28T03:49:47Z")

</div>

no no no… use the elseif num\>0 function… or something like that

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 28, 2004, 3:52am UTC](https://forum.kirupa.com/t/php-calendar/58983/17 "2004-07-28T03:52:42Z")

</div>

what, im not understanding. there is a parse error at line 26, thats before the else part.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 28, 2004, 3:58am UTC](https://forum.kirupa.com/t/php-calendar/58983/18 "2004-07-28T03:58:57Z")

</div>

Basicly what ure original problem was not executing the else statement measn that youre row is not NULL. in that case it will always return something… ofcourse you can tweak that… lets say if ($row[‘0’] == ‘something’) { do something } else { do something else }

Meaning that if you have specified that tabel field to be NOT NULL if wont do the else statement

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 28, 2004, 4:17am UTC](https://forum.kirupa.com/t/php-calendar/58983/19 "2004-07-28T04:17:25Z")

</div>

i finally got it working, thanks for all the help guys, i just have a few formatting issues on printing out the query and then ill be done with that part.
