/    Sign up×
Community /Pin to ProfileBookmark

Opening window, need data from a PHP function.

I have the below in a navigation Bar, which works Well. My only concern here is that the function will get called EVERY time a page is loaded. So, My question here is “Does anyone know of a better way of doing this?”. Build the value when the navigation item is clicked?

<?php
$cal_info=calendar();
echo “<li><a href=”javascript:void(0)” onClick=”buildwindow(500,400,’Calendar of Events’,’$cal_info’)”>Calendar</a></li>”;
?>

<?php
function calendar()
{
include(“user_access/include/values_main_page_right_marg.php”);
$r_margin_tot = count($rmargin_value);
for($i = 0; $i < $r_margin_tot; $i++)
{
$calendar = “$calendar&#149;&nbsp;$rmargin_value[$i]<br>”;
}
return $calendar;
}
?>

I know you cannot call a php script from Javascript, so anyone here have any better solutions?

Thought about executing the function when the page is initially loaded and storing the value somewhere (MySql), dont want to use a cookie.

Thanks in advance.

DPK

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@ziffgoneJan 14.2006 — Try using a PHP Session.

<?php

session_start();

if(!$_SESSION['enter']){

$cal_info=calendar();

echo "<li><a href="javascript:void(0)" onClick="buildwindow(500,400,'Calendar of events','$cal_info')">Calendar</a></li>";

$enter="true";

session_register('enter');

}

?>

This way, the function will only be called if the Session "enter" isn't found. If it's not in session, as it wouldn't be on first page enter, the function is called and the Session "enter" is started.

If the window is kept open, no matter what page they visit, if they come back to this page, the session will still be in play and the function won't be called again.

Hope that helps.

Regards...
Copy linkTweet thisAlerts:
@dpkyteauthorJan 14.2006 — Not sure if this will work, I always want the Calendar item to be displayed, it is part of my navigation bar. So when the user clicks on another navigation item, this seems like the Calendar item will not be displayed on the next page.

My goal is to call the function once (on startup) then store $cal_info and reference it when needed.

Thx,

DPK
Copy linkTweet thisAlerts:
@bokehJan 14.2006 — When posting code please use the code buttons provided for this purpose ([URL=https://webdeveloper.com/forum/showthread.php?t=64280]posting guidelines[/URL]). You could try the following... it will load the calender into a session variable on the initial page load and then use it for subsequent pages.[code=php]<?php

session_start();

if(!isset($_SESSION['cal_info'])){
$_SESSION['cal_info'] = calendar();
}

echo "<li><a href="javascript:void(0)" onClick="buildwindow(500,400,'Calendar of Events','{$_SESSION['cal_info']}')">Calendar</a></li>";

?>[/code]
Copy linkTweet thisAlerts:
@dpkyteauthorJan 14.2006 — This seems like the way to go. I did encounter an issue though.

I had to put the function call @ the very beginning of the main index.php page. Otherwise getting the error: "Warning: session_start(): Cannot send session cache limiter - headers already sent ... " There cannot even be blank lines.

Anyway, after this was fixed, put the below in the index.php file @ the end, all was displayed ok.

<?php

echo $_SESSION['cal_info'];

?>

Then I removed the above and put in:

<frameset frameborder="0" framespacing="0" border="0" rows="100%,*">

<frame name="TOPFRAME" src="http://www.yoursite.com/main.php" noresize>

<noframes>

<body>

.

.

.

in Main.php I put the echo (same as above from the index.php file) and it did not display. I'm sure we are on the right track, but something is missing on my end.

Thanks

DPK
Copy linkTweet thisAlerts:
@dpkyteauthorJan 14.2006 — Found issue: Needed to add session_start(); @ the top of each page.

Thx all for the help.

DPK
×

Success!

Help @dpkyte spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...