2uzhan.com
Advertisement
Now Place:2uzhan.com » Adding a Link into PHP code

Adding a Link into PHP code

PHP @ December 30, 1969   Views:0

How would i add a Url in here so when you click on the image it takes you to a presenters profile???? heres the code and the working script can be found under http://www.castlefm.net under 'On Air'

PHP Code:

<?php

function getImageName()

{

$hour = getdate(); // current time as array

$hour = $hour['hours']; // and from there the hours-Element

if ($hour<1)

{

if ($hour==24 || $hour == 0)  //

return 'onairandy.gif';

else

return 'transmissionbreak.jpg'; //

}

elseif ($hour <1)

return array ('onairmaurice.gif','Maurice Taggart');

elseif ($hour <2)

return array ('onairmaurice.gif','Maurice Taggart');

elseif ($hour <3)

return array ('onairjustin.gif','Justin Macartney');

elseif ($hour <4)

return array ('onairjustin.gif','Justin Macartney');

elseif ($hour <5)

return array ('onairjustin.gif','Justin Macartney');

elseif ($hour <6)

return array ('onairkenny.gif','Kenny Davis');

elseif ($hour <7)

return array ('onairkenny.gif','Kenny Davis');

elseif ($hour <8)

return array ('onairstuart.gif','Stuart Robinson');

elseif ($hour <9)

return array ('onairstuart.gif','Stuart Robinson');

elseif ($hour <10)

return array ('onairstuart.gif','Stuart Robinson');

elseif ($hour <11)

return array ('onairstuart.gif','Stuart Robinson');

elseif ($hour <12)

return array ('onairsimon.gif','Simon Barr');

elseif ($hour <13)

return array ('onairsimon.gif','Simon Barr');

elseif ($hour <14)

return array ('onairstevie.gif','Stevie Robinson');

elseif ($hour <15)

return array ('onairstevie.gif','Stevie Robinson');

elseif ($hour <16)

return array ('onairandy.gif','Andy Pugh');

elseif ($hour <17)

return array ('onairandy.gif','Andy Pugh');

elseif ($hour <18)

return array ('transmissionbreak.jpg','Citybeat 96.7 FM<br>Kenny Tosh');

elseif ($hour <19)

return array  ('transmissionbreak.jpg','Citybeat 96.7 FM<br>Kenny Tosh');

elseif ($hour <20)

return array  ('transmissionbreak.jpg','Citybeat 96.7 FM<br>Kenny Tosh');

elseif ($hour <21)

return array  ('transmissionbreak.jpg','Citybeat 96.7 FM<br>Kenny Tosh');

elseif ($hour <22)

return array  ('transmissionbreak.jpg','Citybeat 96.7 FM<br>Kenny Tosh');

elseif ($hour <23)

return array  ('transmissionbreak.jpg','Citybeat 96.7 FM<br>Kenny Tosh');

elseif ($hour <0)

return array  ('transmissionbreak.jpg','Citybeat 96.7 FM<br>Kenny Tosh');

}

$desc = getImageName();

print '<span><img src="'.$desc[0].'"/><br/>'.$desc[1].'</span>';

?>

--------------Solutions-------------

Assuming you want an <a> entity (it could also be done with a form seeing as you're apparently using an image to click on, but the ordinary link is a lot simpler).

The href attribute refers to the profile script, of course. It includes a query string "?presenter=...", where the ... is some id unique to each presenter (so you know which one was chosen). The profile page of course retrieves this info via $_GET['presenter']. Remember to use urlencode().

Or maybe just a plain old ordinary link (without a query string) and use the same code you've got here to figure out who's on at the moment. But that means duplicating code.

On a strategic note, it must be pointed out that your code is pretty inflexible at the moment; annoying amounts of recoding would be necessary every time the schedule changes. At least consider using a switch() statement.

lol I'm very basic when it comes to PHP so that meant next to nothing to me whats a switch() Statement do?????

Hi,

more info on switch() statement here :

http://www.php.net/manual/en/control...res.switch.php

Hervé.

Try this:

In each of your arrays within the getImageName() function, add an element. Example, for

return array ('onairmaurice.gif','Maurice Taggart');

change it to

return array ('linktopage.php', 'onairmaurice.gif','Maurice Taggart');

Where "linktopage.php" is the document that you want to link to.

Then, for your "print" statement, change it to something like:

print "<span><a href=\"" . $desc[0] . "\"><img src=\"" . $desc[1] . "\" border=0></a><br>" . $desc[2] . "</span>";

I think that should work.

Note that I escaped double quotes like \" rather than just using single quotes ' . It usually works better cross-browser (just to make sure), and makes for neater, more standardized coding.

As well, I used a space in between the concatinations ( . ). It makes for easier modification later because it won't look so crowded.

Happy coding!

Tags:
© 2018 2uzhan.com Contact