Jump to content

Parse error: syntax error, unexpected T_STRING HELP PLEASE


bobby317

Recommended Posts

Ok Still trying to work my way through this event calendar.  I belive I am getting close but I am getting a Parse error: syntax error, unexpected T_STRING on line 46 of the following code I have found no missing ; or "" so I am not sure what I am doing wrong. Any advice?

 

<?php

//CSS style
print '<link href="eventMain.css" rel="stylesheet" type="text/css" />';

//This gets today's date  
$date = time ();  

//This puts the day, month, and year in seperate variables  
$day = date('d', $date);  
$month = date('m', $date);  
$year = date('Y', $date);  

//Here we generate the first day of the month  
$first_day = mktime(0,0,0,$month, 1, $year);   

//This gets us the month name  
$title = date('F', $first_day);

//Here we find out what day of the week the first day of the month falls on 
$day_of_week = date('D', $first_day);   

//Once we know what day of the week it falls on, we know how many blank days occure before it. If the first day of the week is a Sunday then it would be zero 
switch($day_of_week){  
case "Sun": $blank = 0; break;  
case "Mon": $blank = 1; break;  
case "Tue": $blank = 2; break;  
case "Wed": $blank = 3; break;  
case "Thu": $blank = 4; break;  
case "Fri": $blank = 5; break;  
case "Sat": $blank = 6; break;  
}  

//We then determine how many days are in the current month 
$days_in_month = cal_days_in_month(0, $month, $year);

//Database Connection
$dbc = mysql_connect('rwddesign.com:3306', 'rwddesi1_bobby31', 'jessica');
   mysql_select_db('rwddesi1_test');
   
//Create the date variable to retirive info and converts to php timestamp:
$retriveDate = "$day_num $month $year";
$retriveDate = strtotime($retriveDate);

//Put mysql query into variable for retriving info.
$query = 'SELECT * FROM events WHERE date='FROM_UNIXTIME($retriveDate)'';

//Submit query and capture the results
$result = mysql_query($query) or die(mysql_error());

//Here we start building the table heads  
echo "<table>"; 
echo "<tr><th colspan=\"7\" class=\"title\"> $title $year </th></tr>"; 
echo '<tr><td class="dayOfWeek">Sunday</td><td class="dayOfWeek">Monday</td><td class="dayOfWeek">Tuesday</td><td class="dayOfWeek">Wendsday</td><td class="dayOfWeek">Thursday</td><td class="dayOfWeek">Friday</td><td class="dayOfWeek">Saturday</td></tr>';  

//This counts the days in the week, up to 7 
$day_count = 1;  echo "<tr>";

//first we take care of those blank days 
while ( $blank > 0 )  {  
echo "<td> </td>";  
$blank = $blank-1;  
$day_count++; 
}

//sets the first day of the month to 1  
$day_num = 1;  

//count up the days, untill we've done all of them in the month 
while ( $day_num <= $days_in_month && $row = mysql_fetch_assoc($result))  { 

if (date('d') != $day_num) {
	echo "<td>$day_num<br /> $row['eventName'] </td>";  
	$day_num++;  
	$day_count++;
} else {
	echo "<td class=\"today\">$day_num<br /> $row['eventName'] </td>";  
	$day_num++;  
	$day_count++;	
}
  

//Make sure we start a new row every week 
if ($day_count > 7) { 
	echo "</tr><tr>"; 
	$day_count = 1; 
} 
}

//Finaly we finish out the table with some blank details if needed 
while ( $day_count >1 && $day_count <=7 )  {  
echo "<td> </td>";  
$day_count++;  
}  

//Close column and table
echo "</tr></table>";

Link to comment
Share on other sites

Nothing sticks out and I didn't think that'd cause issue really but was a shot in the dark... hmmm.

 

That's usually a syntax issue why I noted just trying that little adjustments incase the php translator was being picky...

 

I don't see anything right away... look through all the code at & above that line though and try to find your typo someplace. Most likely something like misplaced quote mark or ;

Link to comment
Share on other sites

Ok I changed my $query statment to what you said and now I am getting this error on line 74:

 

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING

 

Here is the new code as well.

 

<?php

//CSS style
print '<link href="eventMain.css" rel="stylesheet" type="text/css" />';

//This gets today's date  
$date = time ();  

//This puts the day, month, and year in seperate variables  
$day = date('d', $date);  
$month = date('m', $date);  
$year = date('Y', $date);  

//Here we generate the first day of the month  
$first_day = mktime(0,0,0,$month, 1, $year);   

//This gets us the month name  
$title = date('F', $first_day);

//Here we find out what day of the week the first day of the month falls on 
$day_of_week = date('D', $first_day);   

//Once we know what day of the week it falls on, we know how many blank days occure before it. If the first day of the week is a Sunday then it would be zero 
switch($day_of_week){  
case "Sun": $blank = 0; break;  
case "Mon": $blank = 1; break;  
case "Tue": $blank = 2; break;  
case "Wed": $blank = 3; break;  
case "Thu": $blank = 4; break;  
case "Fri": $blank = 5; break;  
case "Sat": $blank = 6; break;  
}  

//We then determine how many days are in the current month 
$days_in_month = cal_days_in_month(0, $month, $year);

//Database Connection
$dbc = mysql_connect('rwddesign.com:3306', 'rwddesi1_bobby31', 'jessica');
   mysql_select_db('rwddesi1_test');
   
//Create the date variable to retirive info and converts to php timestamp:
$retriveDate = "$day_num $month $year";
$retriveDate = strtotime($retriveDate);

//Put mysql query into variable for retriving info.
$query = "SELECT * FROM events WHERE date=FROM_UNIXTIME($retriveDate)";


//Submit query and capture the results
$result = mysql_query($query) or die(mysql_error());

//Here we start building the table heads  
echo "<table>"; 
echo "<tr><th colspan=\"7\" class=\"title\"> $title $year </th></tr>"; 
echo '<tr><td class="dayOfWeek">Sunday</td><td class="dayOfWeek">Monday</td><td class="dayOfWeek">Tuesday</td><td class="dayOfWeek">Wendsday</td><td class="dayOfWeek">Thursday</td><td class="dayOfWeek">Friday</td><td class="dayOfWeek">Saturday</td></tr>';  

//This counts the days in the week, up to 7 
$day_count = 1;  echo "<tr>";

//first we take care of those blank days 
while ( $blank > 0 )  {  
echo "<td> </td>";  
$blank = $blank-1;  
$day_count++; 
}

//sets the first day of the month to 1  
$day_num = 1;  

//count up the days, untill we've done all of them in the month 
while ( $day_num <= $days_in_month && $row = mysql_fetch_assoc($result))  { 

if (date('d') != $day_num) {
	echo "<td>$day_num<br /> $row['eventName'] </td>";  
	$day_num++;  
	$day_count++;
} else {
	echo "<td class=\"today\">$day_num<br /> $row['eventName'] </td>";  
	$day_num++;  
	$day_count++;	
}
  

//Make sure we start a new row every week 
if ($day_count > 7) { 
	echo "</tr><tr>"; 
	$day_count = 1; 
} 
}

//Finaly we finish out the table with some blank details if needed 
while ( $day_count >1 && $day_count <=7 )  {  
echo "<td> </td>";  
$day_count++;  
}  

//Close column and table
echo "</tr></table>";

 

Thanks again for trying to help me been working on this part of the script for going on two weeks now. But I am learning a lot so I gues its ok.

Link to comment
Share on other sites

You can't reference an array element within double quotes like this

<?php
echo "<td>$day_num<br /> $row['eventName'] </td>";
?>

you either have to use concatenation:

<?php
echo "<td>$day_num<br /> " . $row['eventName'] . " </td>";
?>

or

curly brackets:

<?php
echo "<td>$day_num<br /> {$row['eventName']} </td>";
?>

 

Ken

Link to comment
Share on other sites

hehe I just found that one my self did some readying up on arrays and realized I had that wrong now that I fixed that I get this error:

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1

 

Let me give some background on what I am doing I am storing events on my database and storing the dates using DATE in the mysql table column.  I store the user entered date collected from the form in a varable and the convert it to a php timestamp using this function strtotime(); the in my mysql query I use FROM_UNIXTIME to have mysql convert it into the right format to store in the DATE column on the database.

 

Now I need to call these events by the date and place the event name on the calander.

 

 

Hope you under stand this and thanks again

Link to comment
Share on other sites

Data stored in a DATE typed field in MySQL is a string so it needs to be quoted in your query:

<?php
$query = "SELECT * FROM events WHERE date='FROM_UNIXTIME($retriveDate)'";
?>

You could format the date correctly using PHP:

<?php
$retriveDate = date('Y-m-d',strtotime("$day_num $month $year"));
//Put mysql query into variable for retriving info.
$query = "SELECT * FROM events WHERE date='$retriveDate'";
?>

 

Ken

Link to comment
Share on other sites

Data stored in a DATE typed field in MySQL is a string so it needs to be quoted in your query:

<?php
$query = "SELECT * FROM events WHERE date='FROM_UNIXTIME($retriveDate)'";
?>

 

Not. Now it's literal string saying 'FROM_UNIXTIME(someTimestamp)'

 


mysql> SELECT FROM_UNIXTIME(0), 'FROM_UNIXTIME(0)';
+---------------------+------------------+
| FROM_UNIXTIME(0)    | FROM_UNIXTIME(0) |
+---------------------+------------------+
| 1970-01-01 01:00:00 | FROM_UNIXTIME(0) |
+---------------------+------------------+
1 row in set (0.00 sec)

 

Data in MySQL DATE field is stored as DATE datatype, which is converted to string for displaying.

Link to comment
Share on other sites

BTW: If we have $day_num $month $year variables already, why all fuss with converting them from one format to another?

$query = "SELECT * FROM events WHERE date='$year-$month-$day_num'";

Link to comment
Share on other sites

Ok got past my error thanks.

 

Now it is still not working how I intend. It seems to be stopping at my second while function it will generate the title the weekday names and the first 7 blank days but then nothing and not showing my eventNames that are stored in the database.  Thanks for all the help and please explain so I may learn.

 

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.