View Full Version : Need help on one line please
I am getting an error on this line and can't figure it out. Can someone please see what I am missing? Thanks.
echo "<td align=right><a href=\"/php/dayview.php?startdate=<?php echo $startdate['startdate'];?>\" . "\" class=\"dayofmonthyearview\">";
Error Message:
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home2/arakireg/public_html/_calmaui/php/yearview-new.php on line 115
jscheuer1
07-19-2008, 01:41 PM
I don't know much about PHP, but I seriously doubt that you can open a <?php section within an echo statement (which itself should already be in a <?php section). If I get what you are after, this could work:
echo "<td align=right><a href=\"/php/dayview.php?startdate=" . $startdate['startdate'] . "\" class=\"dayofmonthyearview\">";
or maybe even:
echo '<td align="right"><a href="/php/dayview.php?startdate=' . $startdate['startdate'] . '" class="dayofmonthyearview">';
But either way:
$startdate['startdate']
will resolve as the page is served, not when the link is clicked. There is no PHP that will resolve when a link is clicked on a page. All PHP on a page is interpreted by the server just before serving the page.
If you want dayview.php to have the most up to date value for:
$startdate['startdate']
get that value from the server on dayveiw.php, not from its URL.
Dear John: Thank you! That did get rid of the error. However, no matter what day you click on in the calendar, it just lists events for today's date. So I put this in dayview.php but it didn't help:
$today = date ('Y-m-d'); $daydate = date('l, F d, Y');
if(isset($_GET['startdate']) && is_numeric($_GET['startdate'])){
$getdate = $_GET['startdate'];
} else {
$getdate = $today;
}
$query = " SELECT `event_id`,`event_title`, date_format(`startdate`, '%M %D, %Y') as startdate, time_format(`starttime`, '%h:%i %p') as starttime, time_format(`endtime`, '%h:%i %p') as endtime
FROM `event`
WHERE `startdate` = '".$getdate."'
ORDER BY `starttime`, `event_title` ";
$result = @mysql_query($query,$connection) or die("Couldn't execute $query query."); ?>
<div class="h1">EVENTS for <?php echo $daydate; ?></div>
<p><? while($event = mysql_fetch_assoc($result)){ ?>
<div class="day">
<?php echo $event['starttime']; ?> - <?php echo $event['endtime']; ?> <a href="/php/event-detail.php?event_id=<?php echo $event['event_id'];?>"> <?=$event['event_title'];?></a><br>
</div>
<? } ?></p>
I tried to adapt Brady's code from last night for passing variables through the URL, but I'm not sure if it applies to date values (and I may have screwed it up). All I'm trying to do is link dayview.php to yearview.php based on what day you click on. Should be simple, but... Does your php extend that far? Thanks for your help. :)
jscheuer1
07-19-2008, 05:26 PM
I haven't really followed all that code, yet. But it is becoming increasingly obvious to me that you probably want to produce something like:
<a href="/php/dayview.php?startdate=somevalue">somevalue</a>
in some sort of layout within a table. And I get the impression that you probably want that repeated for some kind of range of possible startdates.
If these are stored in an array called $startdate, you should be able to iterate through that array with a PHP for each. That will write out the list of links.
That's about the limit of my PHP knowledge though. Once you have that, if someone clicks one of those links, it will pass the value of startdate from that particular link to dayview in a form that you can use the PHP $_GET to grab it from the URL on dayview, what you do with it on dayview is up to you.
Do I have that about right?
Yes, that is what I have done except in this case it is just for one day, but the day can change. I have dayview.php working already here: http://www.calendarmaui.com/php/dayview.php
Yearview is here: http://www.calendarmaui.com/php/yearview-new.php
What I can't seem to do is link from a day chosen on yearview-new.php to the same day on dayview.php. It always goes to today's date. I don't know what format to pass the date in. What I have tried has not worked. Even if I type dates on the URL of dayview.php the date stays the same. The code is all written, just needs a couple of tweaks. I really appreciate your take on it because it is probably more a logic problem than php. Thanks.
jscheuer1
07-19-2008, 05:49 PM
Seems to work fine on:
http://www.calendarmaui.com/php/yearview.php
where you pass it like so:
http://www.calendarmaui.com/day.php?year=2009&month=02&day=04
Why not make the new version of the year page do it the same way?
The live yearview.php gets its data from the old table that stores the dates as integers (eg. 20080718). I have made a new table that stores dates as dates (2008-07-19).
With some help, I am rewritng the whole application because the code dates back to 2000. You once commented that it was "archaic" and it causes problems everytime the host upgrades the server. So that is the project -- moving to the new table before the calendar events get out of date. That yearview code works on the old dates but not the new. I figured I would have to do something different (and hopefully simpler) for the new dates. Or maybe I'm wrong and I have to do it the same way. I know way less php than you do. :)
Dear John: This is done now so not to worry. Thanks very much. :)
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.