...

View Full Version : PHP Echoed in Ajax



HoddzDJ
10-08-2012, 05:14 PM
Hi all, this is my first post here so please go easy on me!

I've built a site in PHP for my radio station, and the daily schedule is displayed dynamically using PHP script. I have added links to view different days but when it loads up it's just loading up a new page. I can't quite remember how I done it but I'd like it to be in ajax if that's possible.

If you head to pukkaradio.net you'll see it's on the homepage. But if you go to the specific schedule page you'll see that if you scroll down you get the homepage displayed too. I'm hoping that displaying it in ajax will stop that.

Anyway, I have no knowledge of what I need to do so any help to tutorials would be great.

Cheers, Ben.

sunfighter
10-09-2012, 02:06 AM
No ajax will not correct that. Your php is doing it and we can not see the php. Check your schedule php for the main page php code or a include call to the php file by searching for the file name.

HoddzDJ
10-10-2012, 08:30 PM
No ajax will not correct that. Your php is doing it and we can not see the php. Check your schedule php for the main page php code or a include call to the php file by searching for the file name.

Thanks for the tips Sunfighter. The PHP of both index.php and schedule.php can be found below. Hopefully I'll be able to get to the bottom of it with a bit of help.

index.php


<?php
/* Short and sweet */
define('WP_USE_THEMES', false);
require('./blog/wp-blog-header.php');
?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Pukka Radio | Not for the faint hearted!</title>
<meta name="google-site-verification" content="6qV_kVo0_SEhZ7P-qeljFkVSfoSdcg4ng0l_pTLEIs0" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="Keywords" content="pukka radio,pukka,radio,online radio,hoddz,madmuffin,stryka,nick-e,slaters,clowny,koopa,medowz,hardcore,hardstyle,hard trance,trance" />
<meta name="Description" content="Your source of free radio. Focusing on the rave scene, with every genre covered. Ranging from Hardcore, Drum &amp; Bass, Dubstep, Techno, Hardstyle, Hard Trance and everything inbetween! Come check us out, we really aren't for the haint hearted..." />

<link rel="stylesheet" href="css/reset.css" />
<link rel="stylesheet" href="css/style.css" />

<meta property="og:site_name" content="Pukka Radio" />
<meta property="og:image" content="http://www.pukkaradio.net/images/logo.og.png" />
<meta property="og:type" content="website" />
<meta property="og:url" content="http://www.pukkaradio.net/index.php" />
<meta property="og:title" content="Pukka Radio" />
<meta property="fb:app_id" content="162999380399" />

<!-- begin flash player pop-up script -->
<SCRIPT TYPE='TEXT/JAVASCRIPT'>
var pukkaplayer1Window=null;
function flashplayer(mypage,myname,w,h,pos,infocus){
if (pos == 'random')
{LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
else
{LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
settings='width='+ w + ',height='+ h + ',top=' + TopPosition + ',left=' + LeftPosition + ',scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';flashplayer Window=window.open('',myname,settings);
if(infocus=='front'){flashplayerWindow.focus();flashplayerWindow.location=mypage;}
if(infocus=='back'){flashplayerWindow.blur();flashplayerWindow.location=mypage;flashplayerWindow.blu r();}
}
</script>
<!-- end flash player pop-up script -->

<!-- begin tunein pop-up script -->
<SCRIPT TYPE='TEXT/JAVASCRIPT'>
var tuneinWindow=null;
function tunein(mypage,myname,w,h,pos,infocus){
if (pos == 'random')
{LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
else
{LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
settings='width='+ w + ',height='+ h + ',top=' + TopPosition + ',left=' + LeftPosition + ',scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';tuneinWindo w=window.open('',myname,settings);
if(infocus=='front'){tuneinWindow.focus();tuneinWindow.location=mypage;}
if(infocus=='back'){tuneinWindow.blur();tuneinWindow.location=mypage;tuneinWindow.blur();}
}
</script>
<!-- end tunein pop-up script -->

<!-- begin chat pop-up script -->
<SCRIPT TYPE='TEXT/JAVASCRIPT'>
var pukkachatWindow=null;
function pukkachat(mypage,myname,w,h,pos,infocus){
if (pos == 'random')
{LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
else
{LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
settings='width='+ w + ',height='+ h + ',top=' + TopPosition + ',left=' + LeftPosition + ',scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';pukkachatWi ndow=window.open('',myname,settings);
if(infocus=='front'){pukkachatWindow.focus();pukkachatWindow.location=mypage;}
if(infocus=='back'){pukkachatWindow.blur();pukkachatWindow.location=mypage;pukkachatWindow.blur();}
}
</script>
<!-- end chat pop-up script -->

<!-- begin onmouseover social script -->
<script language="javascript">
<!-- hide script from old browsers
//detect browser:
browserName = navigator.appName;
browserVer = parseInt(navigator.appVersion);
if (browserName == "Netscape" && browserVer >= 3) browserVer = "1";
else if (browserName == "Microsoft Internet Explorer" && browserVer == 4) browserVer = "1";
else browserVer = "2";
//preload images:
if (browserVer == 1) {
a1 = new Image(64,64);
a1.src = "images/social-icons/facebook-bw.png";
a2 = new Image(64,64);
a2.src = "images/social-icons/facebook.png";
b1 = new Image(64,64);
b1.src = "images/social-icons/twitter-bw.png";
b2 = new Image(64,64);
b2.src = "images/social-icons/twitter.png";
c1 = new Image(64,64);
c1.src = "images/social-icons/google-bw.png";
c2 = new Image(64,64);
c2.src = "images/social-icons/google+color.png";
d1 = new Image(64,64);
d1.src = "images/social-icons/youtube-bw.png";
d2 = new Image(64,64);
d2.src = "images/social-icons/youtube.png";
}
//image swapping function:
function hiLite(imgDocID, imgObjName, comment) {
if (browserVer == 1) {
document.images[imgDocID].src = eval(imgObjName + ".src");
window.status = comment; return true;
}}
//end hiding -->
</script>
<!-- end onmouseover social scrpt -->

</head>

<body>
<div id="container">

<div id="header">
<div id="header-wrapper">

<div id="logo">
<a href="index.php"><img src="images/header-logo.png" alt="Pukka Radio" width="" height="" border="0" /></a>
</div><!-- end -->

<ul id="navB">
<li><a href="index.php?id=schedule">Schedule</a></li>
<li><a href="http://www.pukkaradio.net/community/" target="_blank">Forums</a></li>
<li><a href="index.php?id=contact">Contact</a></li>
</ul>
<ul id="navA">
<li><a href="index.php?id=home">Home</a></li>
<li><a href="javascript:pukkachat('./chat/index.php','PukkaRadioChat','740','675','center','front');">Chat</a></li>
<li><a href="http://www.pukkaradio.net/blog/" target="_blank">Blog</a></li>
</ul>
</div><!-- #header-wrapper end -->
</div><!-- #header end -->

<?php
// Top level links
if($_GET['id'] == 'schedule')
{ include './sources/schedule.php'; }
if($_GET['id'] == 'autodj')
{ include './sources/autodj.php'; }
elseif($_GET['id'] == 'contact')
{ include './sources/contact.php'; }

// Homepage
else
{ include './sources/home.php'; }
?>

<div id="footer">
<div id="footer-wrapper">

<div class="socialBlock">
<h3 class="socialTitle">Connect with us:<h3>
<ul id="socialicons">
<li><a href="http://www.youtube.com/user/pukkatv" target="social" onMouseOver="hiLite('d','d2','Your Comment Here')" onMouseOut="hiLite('d','d1','')"><img name="d" src="images/social-icons/youtube-bw.png" border="0" width="64" height="64"></a></li>
<li><a href="https://plus.google.com/b/100127745757548011503/100127745757548011503/posts" target="social" onMouseOver="hiLite('c','c2','Your Comment Here')" onMouseOut="hiLite('c','c1','')"><img name="c" src="images/social-icons/google-bw.png" border="0" width="64" height="64"></a></li>
<li><a href="http://www.twitter.com/pukkaradio" target="social" onMouseOver="hiLite('b','b2','Your Comment Here')" onMouseOut="hiLite('b','b1','')"><img name="b" src="images/social-icons/twitter-bw.png" border="0" width="64" height="64"></a></li>
<li><a href="http://www.facebook.com/pukkaradio" target="social" onMouseOver="hiLite('a','a2','Your Comment Here')" onMouseOut="hiLite('a','a1','')"><img name="a" src="images/social-icons/facebook-bw.png" border="0" width="64" height="64"></a></li>
</ul>
</div>

<div id="copyright">
<p>Site built and maintained by Hoddz. Copyright 2007 - 2012 Pukka Radio, all rights reserved.</p>
<p>Pukka Radio streams at high volumes for prolonged periods, hearing protection is optional.</p>
<p>We will not be held responsible for any damaged caused to your hearing either temporarily or permanently.</p>
<p>You have been warned.</p>
</div>

</div><!-- #footer-wrapper end -->

</div><!-- #footer end -->

</body>
</html>


./sources/home.php


<div id="main">

<div id="primaryContent" class="">

<h1 class="title">Welcome</h1>
<p class="firstP">Pukka Radio is an internet radio station with a difference. We focus on bringing the harder sounds to the masses, from upfront UK Hardcore to Drum & Bass, Trance to Techno and everything in between. We really aren't for the faint hearted.</p>

<div class="clear"></div>

<div class="one-third firstItem">
<h4><span>Latest</span> News</h4><?php $posts = get_posts('numberposts=1&order=DES&orderby=post_date');
foreach ($posts as $post) : start_wp(); ?>
<p class="firstP"><?php the_time('F jS, Y') ?><br /><?php the_content(); ?></p>
<p>You can read up on all of our news over at our blog, just check it out <a href="http://www.pukkaradio.net/blog" target="_blank">here</a>.<?php endforeach; ?></p>
</div><!-- #one-third -->
<div class="one-third">
<h4><span>Todays</span> Live Schedule</span></h4>
<p class="firstP"><?php include ('./sources/schedule-home.php') ?></p>
<p align="center"><a href="?times=Monday">Mon</a> - <a href="?times=Tuesday">Tue</a> - <a href="?times=Wednesday">Wed</a> - <a href="?times=Thursday">Thur</a> - <a href="?times=Friday">Fri</a> - <a href="?times=Saturday">Sat</a> - <a href="?times=Sunday">Sun</a></p>
<p>These are just our live shows for today, don't forget we are on air around the clock and you can see our full weekly schedule <a href="index.php?id=schedule">here</a>.</p><p>&nbsp;</p>
<h4><span>Our</span> Community</span></h4>
<p class="firstP">The whole concept of Pukka Radio is to all unite with the music and that is our only boundary, and we have an active forum and also a great chat room to connect with other listeners and all of our staff. Why not sign up to our forums or jump straight into our chat room and see what it's all about?</p>
</div><!-- #one-third -->
<div class="one-third last">
<h4><span>Tune</span> In</h4>
<p class="firstP">You can tune into Pukka Radio in a few different ways, and we have set them out below so just pick how you wanna tune in and away you go. Should you not be able to tune in, please contact us so we can fix it!</p>
<p align="center"><a href="javascript:flashplayer('./tunein/html5.php','PukkaRadioWebPlayer','450','210','center','front');"><img alt="Tune in using our pop-up player" border="0" src="tunein/flash.png" height="50" width="50" title="Tune in using our pop-up player"></a> <a href="javascript:tunein('http://tunein.com/tuner/?StationId=153291&','PukkaRadioTuneInPlayer','619','350','center','front');"><img alt="Launch Pukka Radio on TuneIn.com" border="0" src="./tunein/tunein.png" height="50" width="50" title="Launch Pukka Radio on TuneIn.com"></a> <a href="javascript:flashplayer('./tunein/html5.php','PukkaRadioWebPlayer','450','210','center','front');"><img alt="Tune in using our pop-up player" border="0" src="tunein/ios.png" height="50" width="50" title="Tune in using our pop-up player"></a></p>
<p>If you an an iPhone/iPad user, you can tune in on the move! Please note that we only stream at 128kbs and this uses a large amount of data transfer per hour so we suggest you only tune in when you are connected to WiFi.</p>
</div><!-- #one-third -->

<div class="clear"></div>

<div class="one-half firstItem">
<h4><span>Featured</span> Event</h4>
<div id="featuredIMG"><?php include ('./featured/sql/event.php'); ?></div>
</div>
<div class="one-half last">
<h4><span>Featured</span> Video</h4>
<div id="featuredVID"><?php include('./featured/sql/youtube.php'); ?></div><br />
<h4><span>Featured</span> SoundCloud</h4>
<div id="featuredSND"><?php include('./featured/sql/soundcloud.php'); ?></div>
</div>

</div><!-- #primaryContent end -->
</div><!-- #main end -->

</div><!-- #container end -->


./sources/schedule-home.php


<?php
//set local variables
$dbhost = "localhost"; //Database Host
$dbuser = "****"; //Database User
$dbpass = "****"; //Database Password
$dbname = "****"; //Database Name
$serverdate = date('l',time() + 0000); // Set the correct studio day

//connect
$db = mysql_pconnect($dbhost,$dbuser,$dbpass);
mysql_select_db("$dbname",$db);

// create an array with the hours of the day, from 0 to 23
$hours = range(0, 23);

$valid_days = array (
'Sunday',
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday',
'Saturday',
);

if($_GET['times'] == "" OR !in_array($_GET['times'], $valid_days)) // you should also check if this $_GET['times'] is valid
{
$_GET['times'] = $serverdate;
}

$day = $_GET['times'];
if($_GET['times'] == ""){
$day = date("l",time() + 3600);
$_GET['times'] = date("l",time() + 3600);
}

$result = mysql_query("SELECT * FROM rp_timetable WHERE day = '$day'");
while($slot = mysql_fetch_assoc($result))
{
$today_live_sets = false;
echo "<p class=\"firstP\">\n";

$lastslot = null;
foreach($hours AS $hour)
{
$slot_number = $hour + 1;
if($lastslot === null)
{
$starthour = $hour;
}

if($slot[$slot_number] != "")
{
if(($hour + 1) <= 23 AND $slot[$slot_number + 1] == $slot[$slot_number])
{
$lastslot = $slot[$slot_number];
continue;
}
else
{
$endhour = $hour + 1;
$today_live_sets = true;
printf("%02d00 - %02d00 | <b>%s</b><br />\n", $starthour, $endhour == 24 ? 0 : $endhour, $slot[$slot_number]);
$lastslot = null;
}
}
}

echo "</p>";
if($today_live_sets == false)
{
echo "<p class=\"firstP\">No live sets today!</p>\n";
}
}

?>

HoddzDJ
10-10-2012, 08:31 PM
./sources/schedule.php


<div id="main">

<div id="primaryContent" class="">

<h1 class="title">Schedule</h1>
<p class="firstP">Below you will find out schedule for live sets, when there is no live DJ on air we will be streaming recorded mixes so there will always be something to listen to!</p>
<p>Always remember that our schedule is studio time and not necessarily your local time. We have displayed the current studio date and time below for your benefit.</p>
<p><strong>Studio Time &amp; Date (UK):</strong> <?php $serverdate = date('l, jS F Y. H:i',time() + 0000 ); echo($serverdate); ?></p>

<div class="clear"></div><a name="times"></a>

<div class="one-third firstItem">
<h4><span>Day</span> Selection</h4>
<p class="firstP">Don't want to see todays schedule? Not a problem, just hit the day you wanna see and we'll show you what's happening.</p>
<p><a href="?id=schedule&week=Monday#times">Monday</a><br />
<a href="?id=schedule&week=Tuesday#times">Tuesday</a><br />
<a href="?id=schedule&week=Wednesday#times">Wednesday</a><br />
<a href="?id=schedule&week=Thursday#times">Thursday</a><br />
<a href="?id=schedule&week=Friday#times">Friday</a><br />
<a href="?id=schedule&week=Saturday#times">Saturday</a><br />
<a href="?id=schedule&week=Sunday#times">Sunday</a></p>
</div><!-- #one-third -->
<div class="one-third">
<h4><span>Set</span> Times</span></h4>
<?php
//set local variables
$dbhost = "localhost"; //Database Host
$dbuser = "****"; //Database User
$dbpass = "****"; //Database Password
$dbname = "****"; //Database Name

//connect
$db = mysql_pconnect($dbhost,$dbuser,$dbpass);
mysql_select_db("$dbname",$db);

$day = $_GET['week'];
if($_GET['week'] == ""){
$day = date("l",time() + 3600);
$_GET['week'] = date("l",time() + 3600);
}
$result = mysql_query("SELECT * FROM rp_timetable WHERE day = '$day'");
while($slot = mysql_fetch_assoc($result)) {
if($slot["1"] == "")
{ $one = "OPEN SLOT"; }
else
{ $one = "<b>{$slot["1"]}</b>"; }

if($slot["2"] == "")
{ $two = "OPEN SLOT"; }
else
{ $two = "<b>{$slot["2"]}</b>"; }

if($slot["3"] == "")
{ $three = "OPEN SLOT"; }
else
{ $three = "<b>{$slot["3"]}</b>"; }

if($slot["4"] == "")
{ $four = "OPEN SLOT"; }
else
{ $four = "<b>{$slot["4"]}</b>"; }

if($slot["5"] == "")
{ $five = "OPEN SLOT"; }
else
{ $five = "<b>{$slot["5"]}</b>"; }

if($slot["6"] == "")
{ $six = "OPEN SLOT"; }
else
{ $six = "<b>{$slot["6"]}</b>"; }

if($slot["7"] == "")
{ $seven = "OPEN SLOT"; }
else
{ $seven = "<b>{$slot["7"]}</b>"; }

if($slot["8"] == "")
{ $eight = "OPEN SLOT"; }
else
{ $eight = "<b>{$slot["8"]}</b>"; }

if($slot["9"] == "")
{ $nine = "OPEN SLOT"; }
else
{ $nine = "<b>{$slot["9"]}</b>"; }

if($slot["10"] == "")
{ $ten = "OPEN SLOT"; }
else
{ $ten = "<b>{$slot["10"]}</b>"; }

if($slot["11"] == "")
{ $eleven = "OPEN SLOT"; }
else
{ $eleven = "<b>{$slot["11"]}</b>"; }

if($slot["12"] == "")
{ $twelve = "OPEN SLOT"; }
else
{ $twelve = "<b>{$slot["12"]}</b>"; }

if($slot["13"] == "")
{ $thirteen = "OPEN SLOT"; }
else
{ $thirteen = "<b>{$slot["13"]}</b>"; }

if($slot["14"] == "")
{ $fourteen = "OPEN SLOT"; }
else
{ $fourteen = "<b>{$slot["14"]}</b>"; }

if($slot["15"] == "")
{ $fifteen = "OPEN SLOT"; }
else
{ $fifteen = "<b>{$slot["15"]}</b>"; }

if($slot["16"] == "")
{ $sixteen = "OPEN SLOT"; }
else
{ $sixteen = "<b>{$slot["16"]}</b>"; }

if($slot["17"] == "")
{ $seventeen = "OPEN SLOT"; }
else
{ $seventeen = "<b>{$slot["17"]}</b>"; }

if($slot["18"] == "")
{ $eighteen = "OPEN SLOT"; }
else
{ $eighteen = "<b>{$slot["18"]}</b>"; }
if($slot["19"] == "")
{ $nineteen = "OPEN SLOT"; }
else
{ $nineteen = "<b>{$slot["19"]}</b>"; }

if($slot["20"] == "")
{ $twenty = "OPEN SLOT"; }
else
{ $twenty = "<b>{$slot["20"]}</b>"; }

if($slot["21"] == "")
{ $twentyone = "OPEN SLOT"; }
else
{ $twentyone = "<b>{$slot["21"]}</b>"; }

if($slot["22"] == "")
{ $twentytwo = "OPEN SLOT"; }
else
{ $twentytwo = "<b>{$slot["22"]}</b>"; }

if($slot["23"] == "")
{ $twentythree = "OPEN SLOT"; }
else
{ $twentythree = "<b>{$slot["23"]}</b>"; }

if($slot["24"] == "")
{ $twentyfour = "OPEN SLOT"; }
else
{ $twentyfour = "<b>{$slot["24"]}</b>"; }

$day = $_GET['week'];
echo "<p class=\"firstP\">You are currently viewing ";
echo "$day";
echo "'s times<p>";
echo "<p>0000 | $one<br />
0100 | $two<br />
0200 | $three<br />
0300 | $four<br />
0400 | $five<br />
0500 | $six<br />
0600 | $seven<br />
0700 | $eight<br />
0800 | $nine<br />
0900 | $ten<br />
1000 | $eleven<br />
1100 | $twelve<br />
1200 | $thirteen<br />
1300 | $fourteen<br />
1400 | $fifteen<br />
1500 | $sixteen<br />
1600 | $seventeen<br />
1700 | $eighteen<br />
1800 | $nineteen<br />
1900 | $twenty<br />
2000 | $twentyone<br />
2100 | $twentytwo<br />
2200 | $twentythree<br />
2300 | $twentyfour<p>";
}
?>
</div><!-- #one-third -->
<div class="one-third last">
<h4><span>What</span> About The Auto DJ</h4>
<p class="firstP">Our Auto DJ system randomly select mixes/tracks from our database of music to play randomly when we are off air which means there is always something on that you'll love.</p>
<p>If you are a DJ/MC and want your mix added to our database to be played at random, just get in touch via the Contact page, we'll happily get it on there for you.</p>
<p>You can find a list of all of the media in our database <a href="index.php?id=autodj" />here</a>!</p>
</div><!-- #one-third -->

</div><!-- #primaryContent end -->
</div><!-- #main end -->

</div><!-- #container end -->



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum