Jump to content

Only Variables should be Passed by Reference


HoTDaWg

Recommended Posts

hi there,

 

when i run calendar.php, its function ShowCalendar works fine as i echo its returned variable. However, when i require_once the file(calendar.php) and echo the function from another file it gives me the error:Only Variables Should be passed by Reference. It says the error is on line 25:

<?php
//here is the area around line 25
$dateformatted = $today['month'] . ' ' . $today['year'];

$days = array();   
    $query = "SELECT post_id,post_date FROM blog_posts";
    $result = mysqli_query($connection1,$query);
    while($row = mysqli_fetch_array($result)){
	if (settype(date('F Y',$row['post_date']),"string") == settype($dateformatted,"string")){#is the problem how I formatted this?
		array_push($days,date('j',$row['post_date']));
	}
}
?>

 

here is the full calendar.php:

<?php

/**
* @author PHPtoys.com administrator
* @modified HoTDaWg
* @copyright 2009
*/
error_reporting(E_ALL);
//calendar taken from http://www.phptoys.com/e107_plugins/content/content.php?content.33.1
//the script was merely changed to create a link that shows up everytime a post was created 
//on a certain day.
function ShowCalendar(){
    //dont worry, this isnt my actual db username/pass hahaha
   //this is also NOT how i call upon my $connection variable, i just set it like this for testing purposes
    $connection1 = mysqli_connect('localhost','root','','blog'); 
    // Get key day informations. 
    // We need the first and last day of the month and the actual day
    $today    = getdate();
    $firstDay = getdate(mktime(0,0,0,$today['mon'],1,$today['year']));
    $lastDay  = getdate(mktime(0,0,0,$today['mon']+1,0,$today['year']));
$dateformatted = $today['month'] . ' ' . $today['year'];

$days = array();   
    $query = "SELECT post_id,post_date FROM blog_posts";
    $result = mysqli_query($connection1,$query);
    while($row = mysqli_fetch_array($result)){
	if (settype(date('F Y',$row['post_date']),"string") == settype($dateformatted,"string")){ #is the problem how I formatted this?
		array_push($days,date('j',$row['post_date']));
	}
}
    $fullstring = '';
    // Create a table with the necessary header informations
    $fullstring .= '<table>';
    $fullstring .= '  <tr><th colspan="7">'.$today['month']." - ".$today['year']."</th></tr>";
    $fullstring .= '<tr class="days">';
    $fullstring .= '  <td>Mo</td><td>Tu</td><td>We</td><td>Th</td>';
    $fullstring .= '  <td>Fr</td><td>Sa</td><td>Su</td></tr>';
    
    
    // Display the first calendar row with correct positioning
    $fullstring .= '<tr>';
    for($i=1;$i<$firstDay['wday'];$i++){
        $fullstring .= '<td> </td>';
    }
    $actday = 0;
    for($i=$firstDay['wday'];$i<=7;$i++){
        $actday++;
        if ($actday == $today['mday']) {
            $class = ' class="actday"';
        } else {
            $class = '';
        }
        if(in_array($actday,$days)){
		$fullstring .= "<td$class><a href='viewentries.php?year=month=day='>$actday</a></td>";
	}else{
		$fullstring .= "<td$class>$actday</td>";
	}
    }
    $fullstring .= '</tr>';
    
    //Get how many complete weeks are in the actual month
    $fullWeeks = floor(($lastDay['mday']-$actday)/7);
    
    for ($i=0;$i<$fullWeeks;$i++){
        $fullstring .= '<tr>';
        for ($j=0;$j<7;$j++){
            $actday++;
            if ($actday == $today['mday']) {
                $class = ' class="actday"';
            } else {
                $class = '';
            }
        if(in_array($actday,$days)){
			$fullstring .= "<td$class><a href='viewentries.php?year=month=day='>$actday</a></td>";
		}else{
			$fullstring .= "<td$class>$actday</td>";
		}
        }
       $fullstring .= '</tr>';
    }
    
    //Now display the rest of the month
    if ($actday < $lastDay['mday']){
       $fullstring .= '<tr>';
        
        for ($i=0; $i<7;$i++){
            $actday++;
            if ($actday == $today['mday']) {
                $class = ' class="actday"';
            } else {
                $class = '';
            }
            
            if ($actday <= $lastDay['mday']){
	        if(in_array($actday,$days)){
				$fullstring .= "<td$class><a href='viewentries.php?year=month=day='>$actday</a></td>";
			}else{
				$fullstring .= "<td$class>$actday</td>";
			}
            }
            else {
                $fullstring .= '<td> </td>';
            }
        }
        
        
        $fullstring .= '</tr>';
    }
    
    $fullstring .= '</table>';
return $fullstring;
}
?>

the area around line 25 basically finds all the posts in my database where the Month and Year are equal to the current month and year. It stores the days of such posts into an array and later on when the calendar is being created, it finds the appropriate days and puts a link around them.

 

again, the problem is the function does not work when im using it from another file.

 

any help would be greatly appreciated,

thanks,

 

HotDaWg

Link to comment
Share on other sites

change

    while($row = mysqli_fetch_array($result)){
      if (settype(date('F Y',$row['post_date']),"string") == settype($dateformatted,"string")){#is the problem how I formatted this?
         array_push($days,date('j',$row['post_date']));
      }

to

    while($row = mysqli_fetch_array($result)){
      $xxx = date('F Y',$row['post_date']);
      if (settype($xxx,"string") == settype($dateformatted,"string")){#is the problem how I formatted this?
         array_push($days,date('j',$row['post_date']));
      }

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.