[thelist] one more PHP question - using a function
Bojan Tesanovic
btesanovic at gmail.com
Tue Oct 16 09:22:52 CDT 2007
Wow, well you should first separate HTML and PHP in your head ;)
Those are completely different things.
lets say that user clicked on 'events.php?id=4'
so user is requesting events.php file with id=4;
let events.php file look like this
<?php
$ID = isset($_GET['id']) ? $_GET['id'] : '';
if( ! is_numeric($ID) ) $ID='';
$info = '';
if($ID){
$info = GetRaceInfo($ID);
}
$links = '';
$arrayIds = array(1=>'name1' ,3 =>'name3' ,4 ........);
foreach($arrayIds as $id=>$name){
$links .= "<a href='events.php?id=$id'>$name</a><br>";
}
//template
$HTML=<<<TPL
<h2>Hello There<h2>
<div> $info <div>
Available events
$links
<h3>bye</h3>
TPL;
echo $HTML;
function GetRaceInfo($id){
...
return $info;
}
?>
So eny request to events.php with or without ID will print possible links for events
and if ID is present in URL it will call GetRaceInfo function and print $info
above links
Tom Dell'Aringa wrote:
> Thanks for all the answers folks, really helpful. One more question. I want
> to use a function to call the data when the user clicks a link. If I don't I
> end up with errors because code is just running willy nilly in the page.
>
> So I have this example function
>
> function GetRaceinfo($raceId)
> {
> // make sure there is a race id selected before attempting to pull data
> if(isset($raceId))
> {
> ...do some stuff, etc....
> }
> }
>
> Then I have the link that is being written out like so:
>
> <a href=\'events.php?id=\'' . $info['id'] . '>' . $info['name'] . '</a>
>
> How can I switch this so when the link is clicked, it still calls
> events.php?id=
> but it does it via the function instead? Would I just do this:
>
> <a href='<?php GetRaceinfo(' . $raceId . ')?>'>linkname</a>
>
> then at the end of my function use header to hit the page?
>
> header('Location: http://blah.com/events.php?id=4');
>
> I'm thinking I've got something backwards here though...
>
> CC me at pixelmech at gee mail dot com if you can...thanks!
>
> Tom
--
Bojan Tesanovic
http://www.classicio.com/
http://www.real-estates-sale.com/
More information about the thelist
mailing list