Php calendar

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
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();
?>


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

 #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>'; 
 

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


<?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();
?>

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


   #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>';
   }
   

<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

you forgot an closing bracket } :slight_smile:

the wile has not been closed

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

let me try it out

argh more problems


<?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


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

thanks so much for your help, that worked;)

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


<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>

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.

bump

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

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


<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>

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

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

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

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.