Jump to content

No data showing .. ?? Why ..??


spacepoet

Recommended Posts

Hi:

 

Can someone tell me why the code below is not displaying any data.

It's suppose to write the calendar dates and event info, but nothing is showing up.

No errors, either .. ??

<td width="50" <?=hiLightEvt($month,$i,$year);?>>
<?php
if(isset($_GET['full'])){
    $result = mysql_query($sql);
    $row = mysql_fetch_assoc($result);
    echo $row['calName'];
}else{
    $sql="select calID, calDate, calName, calDesc from calTbl where calDate = '" . $month . '/' . $day . '/' . $year . "'";
    $result = mysql_query($sql);
    while($row = mysql_fetch_array($result)){
        echo $row['calName'];
        ?>
        <a href="<?=$_SERVER['PHP_SELF'] . '?month='. $month . '&day=' . $i . '&year=' . $year;?>&v=1"><?=$row['calDate'];?></a>
       <?php
  }
}
?>
</td>

 

Help, please ....

Link to comment
Share on other sites

You got an SQL error but your not displaying them ... try

 

$sql="select calID, calDate, calName, calDesc from calTbl where calDate = '" . $month . "/" . $day . "/" . $year . "'";

 

And to see the sql errors in the future use:

$result = mysql_query($sql) or die(mysql_error());

Link to comment
Share on other sites

Hi:

 

Thanks for the tips but they are no working .. it's still just a blank calendar ..

 

This is the full code:

<p>

<div id="legend">
Today is:
<? $today = date("F j, Y, g:i a");
echo " $today "
?>
</div>
<?php
//$todaysDate = date("n/j/Y");
//echo $todaysDate;
// Get values from query string
$day = (isset($_GET["day"])) ? $_GET['day'] : "";
$month = (isset($_GET["month"])) ? $_GET['month'] : "";
$year = (isset($_GET["year"])) ? $_GET['year'] : "";


//comparaters for today's date
//$todaysDate = date("n/j/Y");
//$sel = (isset($_GET["sel"])) ? $_GET['sel'] : "";
//$what = (isset($_GET["what"])) ? $_GET['what'] : "";

//$day = (!isset($day)) ? $day = date("j") : $day = "";





//comparaters for today's date
//$todaysDate = date("n/j/Y");
//$sel = (isset($_GET["sel"])) ? $_GET['sel'] : "";
//$what = (isset($_GET["what"])) ? $_GET['what'] : "";

//$day = (!isset($day)) ? $day = date("j") : $day = "";




if(empty($day)){ $day = date("j"); }

if(empty($month)){ $month = date("n"); }

if(empty($year)){ $year = date("Y"); }
//set up vars for calendar etc
$currentTimeStamp = strtotime("$year-$month-$day");
$monthName = date("F", $currentTimeStamp);
$numDays = date("t", $currentTimeStamp);
$counter = 0;
//$numEventsThisMonth = 0;
//$hasEvent = false;
//$todaysEvents = "";
//run a selec statement to hi-light the days
function hiLightEvt($eMonth,$eDay,$eYear){
//$tDayName = date("l");
$todaysDate = date("n/j/Y");
$dateToCompare = $eMonth . '/' . $eDay . '/' . $eYear;
if($todaysDate == $dateToCompare){
//$aClass = '<span>' . $tDayName . '</span>';
$aClass='class="today"';
}else{
//$dateToCompare = $eMonth . '/' . $eDay . '/' . $eYear;
//echo $todaysDate;
//return;
$sql="select count(calDate) as eCount from calTbl where calDate = '" . $eMonth . '/' . $eDay . '/' . $eYear . "'";
//echo $sql;
//return;
$result = mysql_query($sql);
while($row= mysql_fetch_array($result)){
if($row['eCount'] >=1){
$aClass = 'class="event"';
}elseif($row['eCount'] ==0){
$aClass ='class="normal"';
}
}
}
return $aClass;
}
?>
<table width="900" cellpadding="0" cellspacing="0">
<tr>
<td width="50" colspan="1">
<input type="button" value=" < " onClick="goLastMonth(<?php echo $month . ", " . $year; ?>);">
</td>
<td width="250" colspan="5">
<span class="eventHeader"><?php echo $monthName . " " . $year; ?></span><br>
</td>
<td width="50" colspan="1" align="right">
<input type="button" value=" > " onClick="goNextMonth(<?php echo $month . ", " . $year; ?>);">
</td>
</tr>
<tr>
<th>S</th>
<th>M</th>
<th>T</th>
<th>W</th>
<th>T</th>
<th>F</th>
<th class="lastOne">S</th>
</tr>
<tr>
<?php
for($i = 1; $i < $numDays+1; $i++, $counter++){
$dateToCompare = $month . '/' . $i . '/' . $year;
$timeStamp = strtotime("$year-$month-$i");
//echo $timeStamp . '<br/>';
if($i == 1){
// Workout when the first day of the month is
$firstDay = date("w", $timeStamp);
for($j = 0; $j < $firstDay; $j++, $counter++){
echo "<td> </td>";
}
}
if($counter % 7 == 0){
?>
</tr><tr>
<?php
}
?>




<td width="50" <?=hiLightEvt($month,$i,$year);?>>
<?php

if(isset($_GET['full'])){
    $result = mysql_query($sql);
    $row = mysql_fetch_assoc($result);
    echo $row['calName'];
}else{
    $sql="select calID, calDate, calName, calDesc from calTbl where calDate = '" . $month . '/' . $day . '/' . $year . "'";
    
    $result = mysql_query($sql);
    while($row = mysql_fetch_array($result)){
        echo $row['calName'];
        ?>
        <a href="<?=$_SERVER['PHP_SELF'] . '?month='. $month . '&day=' . $i . '&year=' . $year;?>&v=1"><?=$row['calDate'];?></a>
       <?php
  }
}
?>
</td>





<?php
}
?>
</table>

<?php
if(isset($_GET['v'])){
$sql="select calID, calDate, calName, calDesc, DATE_FORMAT(calStamp, '%a %b %e %Y') as calStamp from calTbl where calDate = '" . $month . '/' . $day . '/' . $year . "'";
$result = mysql_query($sql);
$numRows = mysql_num_rows($result);
?>


<?php
if($numRows == 0 ){
echo '<h3>No Events</h3>';
}else{





while($row = mysql_fetch_array($result)){
?>
<div class="output">

<?=$row['calDate'];?>
<h5><?=$row['calName'];?></h5>
<?=$row['calDesc'];?>


</div>



<?php
}
}
}
?>

</p>	

 

Do you see a way to revise this??

 

I am REALLY stumped on this one ...

 

:(

Link to comment
Share on other sites

Thanks for the tips but they are no working .. it's still just a blank calendar ..

 

Do you see a way to revise this??

 

Turning error reporting on will help, as Maq suggests

 

Temporarily turn on error reporting.  Put these 2 lines directly following your opening <?php tag:

ini_set ("display_errors", "1");
error_reporting(E_ALL);

Link to comment
Share on other sites

Well ... I did all of this, but still no errors or data .. puzzled ..

<td width="50" <?=hiLightEvt($month,$i,$year);?>>
<?php

ini_set ("display_errors", "1");
error_reporting(E_ALL);


if(isset($_GET['full'])){
    $result = mysql_query($sql);
    $row = mysql_fetch_assoc($result);
    echo $row['calName'];
}else{
    //$sql="select calID, calDate, calName, calDesc from calTbl where calDate = '" . $month . '/' . $day . '/' . $year . "'";
    
    $sql="select calID, calDate, calName, calDesc from calTbl where calDate = '" . $month . "/" . $day . "/" . $year . "'";
    
    
    //$result = mysql_query($sql);
    $result = mysql_query($sql) or die(mysql_error());
    while($row = mysql_fetch_array($result)){
        echo $row['calName'];
        ?>
        <a href="<?=$_SERVER['PHP_SELF'] . '?month='. $month . '&day=' . $i . '&year=' . $year;?>&v=1"><?=$row['calDate'];?></a>
       <?php
  }
}
?>


<? $today = date("F j, Y, g:i a");
echo " $today "
?>


</td>

 

It does write the date into every field using the

<? $today = date("F j, Y, g:i a");
echo " $today "
?>

 

code .. but doesn't fix my issue ...

 

Can this be re-written so an event date is assigned properly to the date on the calendar?

That's all I want to do.

 

This was easy in ASP, but PHP has me stumped ... :)

Link to comment
Share on other sites

OK, this is my DB:

-- 
-- Table structure for table `calTbl`
-- 

CREATE TABLE `calTbl` (
  `calID` int(11) NOT NULL auto_increment,
  `calName` varchar(65) NOT NULL,
  `calDesc` varchar(255) NOT NULL,
  `calDate` varchar(11) NOT NULL,
  `calStamp` datetime NOT NULL,
  PRIMARY KEY  (`calID`)
) ENGINE=MyISAM AUTO_INCREMENT=90 DEFAULT CHARSET=latin1 AUTO_INCREMENT=90 ;

-- 
-- Dumping data for table `calTbl`
-- 


INSERT INTO `calTbl` VALUES (88, 'Open Mic', '<p>Come out and Jam with us!</p>', '4/22/2011', '2011-04-18 13:59:44');

 

The calDate would display as: 4/20/2011

(I am not using the calStamp field)

 

So, what am I missing?

Link to comment
Share on other sites

Using that format for calDate means that only an exact equal comparison will work. If you even put in a leading zero in the $month variable, for example, what you are doing won't work. Where are $month, $day, and $year coming from and what exact values do they have in them?

 

PLEASE use an actual DATE data type to store date information in a database, that is what the DATE data type is for.

Link to comment
Share on other sites

Hi:

 

Yes, agreeded - date and time should be a timedate (like the calStamp field is)

 

So ... should I just change that in the database and it will work??

 

As far as where the current date is coming from, I amnot certain.

 

This is the full code I am using:

<p>

<div id="legend">
Today is:
<? $today = date("F j, Y, g:i a");
echo " $today "
?>
</div>
<?php
//$todaysDate = date("n/j/Y");
//echo $todaysDate;
// Get values from query string
$day = (isset($_GET["day"])) ? $_GET['day'] : "";
$month = (isset($_GET["month"])) ? $_GET['month'] : "";
$year = (isset($_GET["year"])) ? $_GET['year'] : "";


//comparaters for today's date
//$todaysDate = date("n/j/Y");
//$sel = (isset($_GET["sel"])) ? $_GET['sel'] : "";
//$what = (isset($_GET["what"])) ? $_GET['what'] : "";

//$day = (!isset($day)) ? $day = date("j") : $day = "";





//comparaters for today's date
//$todaysDate = date("n/j/Y");
//$sel = (isset($_GET["sel"])) ? $_GET['sel'] : "";
//$what = (isset($_GET["what"])) ? $_GET['what'] : "";

//$day = (!isset($day)) ? $day = date("j") : $day = "";




if(empty($day)){ $day = date("j"); }

if(empty($month)){ $month = date("n"); }

if(empty($year)){ $year = date("Y"); }
//set up vars for calendar etc
$currentTimeStamp = strtotime("$year-$month-$day");
$monthName = date("F", $currentTimeStamp);
$numDays = date("t", $currentTimeStamp);
$counter = 0;
//$numEventsThisMonth = 0;
//$hasEvent = false;
//$todaysEvents = "";
//run a selec statement to hi-light the days
function hiLightEvt($eMonth,$eDay,$eYear){
//$tDayName = date("l");
$todaysDate = date("n/j/Y");
$dateToCompare = $eMonth . '/' . $eDay . '/' . $eYear;
if($todaysDate == $dateToCompare){
//$aClass = '<span>' . $tDayName . '</span>';
$aClass='class="today"';
}else{
//$dateToCompare = $eMonth . '/' . $eDay . '/' . $eYear;
//echo $todaysDate;
//return;
$sql="select count(calDate) as eCount from calTbl where calDate = '" . $eMonth . '/' . $eDay . '/' . $eYear . "'";
//echo $sql;
//return;
$result = mysql_query($sql);
while($row= mysql_fetch_array($result)){
if($row['eCount'] >=1){
$aClass = 'class="event"';
}elseif($row['eCount'] ==0){
$aClass ='class="normal"';
}
}
}
return $aClass;
}
?>
<table width="900" cellpadding="0" cellspacing="0">
<tr>
<td width="50" colspan="1">
<input type="button" value=" < " onClick="goLastMonth(<?php echo $month . ", " . $year; ?>);">
</td>
<td width="250" colspan="5">
<span class="eventHeader"><?php echo $monthName . " " . $year; ?></span><br>
</td>
<td width="50" colspan="1" align="right">
<input type="button" value=" > " onClick="goNextMonth(<?php echo $month . ", " . $year; ?>);">
</td>
</tr>
<tr>
<th>S</th>
<th>M</th>
<th>T</th>
<th>W</th>
<th>T</th>
<th>F</th>
<th class="lastOne">S</th>
</tr>
<tr>
<?php
for($i = 1; $i < $numDays+1; $i++, $counter++){
$dateToCompare = $month . '/' . $i . '/' . $year;
$timeStamp = strtotime("$year-$month-$i");
//echo $timeStamp . '<br/>';
if($i == 1){
// Workout when the first day of the month is
$firstDay = date("w", $timeStamp);
for($j = 0; $j < $firstDay; $j++, $counter++){
echo "<td> </td>";
}
}
if($counter % 7 == 0){
?>
</tr><tr>
<?php
}
?>




<td width="50" <?=hiLightEvt($month,$i,$year);?>>
<?php

if(isset($_GET['full'])){
    $result = mysql_query($sql);
    $row = mysql_fetch_assoc($result);
    echo $row['calName'];
}else{
    $sql="select calID, calDate, calName, calDesc from calTbl where calDate = '" . $month . '/' . $day . '/' . $year . "'";
    
    $result = mysql_query($sql);
    while($row = mysql_fetch_array($result)){
        echo $row['calName'];
        ?>
        <a href="<?=$_SERVER['PHP_SELF'] . '?month='. $month . '&day=' . $i . '&year=' . $year;?>&v=1"><?=$row['calDate'];?></a>
       <?php
  }
}
?>
</td>





<?php
}
?>
</table>

<?php
if(isset($_GET['v'])){
$sql="select calID, calDate, calName, calDesc, DATE_FORMAT(calStamp, '%a %b %e %Y') as calStamp from calTbl where calDate = '" . $month . '/' . $day . '/' . $year . "'";
$result = mysql_query($sql);
$numRows = mysql_num_rows($result);
?>


<?php
if($numRows == 0 ){
echo '<h3>No Events</h3>';
}else{





while($row = mysql_fetch_array($result)){
?>
<div class="output">

<?=$row['calDate'];?>
<h5><?=$row['calName'];?></h5>
<?=$row['calDesc'];?>


</div>



<?php
}
}
}
?>

</p>	

 

Sorry about all these posts - I found this online and it works great, excecpt the original version doesn't display the events in the calendar.

You have to click the date, and events for that date display under that calendar, which seems kinda of odd.

The point of a calendar is to display the events in the calendar so people see them right when they hit that page.

 

Thanks for taking the time to help me.

Link to comment
Share on other sites

A DATE data type has a YYYY-MM-DD format. You need to produce that format when you insert values into a DATE column. You also need to use that format when you perform comparisons with a DATE column.

 

To produce a YYYY-MM-DD format, you can either do it in php code or you can use the mysql STR_TO_DATE() function in your queries. http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_str-to-date

 

When you retrieve a DATE value, you can format it any way you want in your query using the mysql DATE_FORMAT() function. http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_date-format

 

To convert any existing column to a DATE data type -

 

1) Alter your table and add a new column with the DATE data type.

 

2) Run a single UPDATE query (one without a WHERE clause so that it will update all the rows at once) that uses the mysql STR_TO_DATE() function to populate the new DATE column from your existing values.

 

3) Change your queries to use the new DATE column.

 

4) Remove your old non-date column from your table.

Link to comment
Share on other sites

calStamp is "stamping" the time the entry is made into the database, which is why I can't use it for what I need.

 

I added calDate as a timedate field in the DB, but it's getting inserted as "00-00-00 0000" ...

I am gathering that this wasn't set-up properly to do what I need it to do.

 

Maybe I need to look for another calendar ...

 

I just want a simple "wall" calendar to add events in the admin, and display them on the front end...

Link to comment
Share on other sites

I looked more closely at what your code is trying to do. Some advice -

 

A) There are countless existing event calendars that already do this. You don't need to re-invent the wheel.

 

B) If you are going to make your own from an existing calendar script -

 

    1) Execute ONE query to select all the events for the current year/month (you are currently executing a separate query for each day of the month.) Get all the entires for the current year/month into an array. Store them in the array with the yyyy-mm-dd they occur on. I would use the yyyy-mm-dd as the keys for the main array and store each event information as array(s) within each main array for their date.

 

    2) In the calendar script, as you loop though the days of the month, form the current date in a variable (yyyy-mm-dd) and find the entires in the array that match that date.

 

    3) Output the matching event information the way you want.

Link to comment
Share on other sites

Hi:

 

Yes, I know there are other scripts, but the ones I have been finding have too much "stuff" - I liked this one because it was

(at least I thought until this point ..lol..) simple ..

 

I will have to look at the code along with your points.

This is where I'm stuck with it; haven't tried to do anything like this before.

 

Thanks for the time.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.