Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-11-2009, 03:58 PM   PM User | #1
DJ Hands3
New Coder

 
Join Date: Feb 2009
Posts: 90
Thanks: 5
Thanked 0 Times in 0 Posts
DJ Hands3 is an unknown quantity at this point
converting my existing javascript to php

hello all after working with php now i have come to learn the benifits, I have a code below that basically processes a query string then refresehes the page with its value to force a download of the mp3,

also there is a random image with corresponding link to picture, i have found a php script that will do this but still need to address the first issue.

so far I have this - the picture rotating code

PHP Code:
<?php
// Random Image With Link PHP Script
// Butterfly Media Romania Blog
// http://blog.butterflymedia.ro/
//
// Usage:
// 
// Save this file as ads.php and use the include function to call it inside your web site

function display_random_img($array) {
    
$key rand(count($array) -1);
    
$link_url $array[$key]['url'];
    
$alt_tag $array[$key]['alt'];
    
$random_img_url $array[$key]['img_url'];
    list(
$img_width$img_height) = getimagesize($random_img_url);
    return 
"<a href=\"$link_url\"><img src=\"$random_img_url\" width=\"$img_width\" height=\"$img_height\" alt=\"$alt_tag\" /></a>";
}

// Edit the following values accordingly
$ads_array = array(
    array(
        
'url' => 'http://www.google.com/',
        
'alt' => 'Google',
        
'img_url' => 'images/1.png'
    
),
    array(
        
'url' => 'http://www.yahoo.com/',
        
'alt' => 'Yahoo!',
        
'img_url' => 'images/2.png'
    
),
    array(
        
'url' => 'http://www.msn.com/',
        
'alt' => 'MSN',
        
'img_url' => 'images/3.png'
    
)
);

echo 
display_random_img($ads_array);
?>
now to make the page refresh to call the query string value is my next hurdle any ideas on this one? I have included my exsisting html below of the page at the moment
Code:
<html>
<head>
<title>dj-promo.co.uk - Download file</title>

<script type="text/javascript"><!--

function getRefToDivMod( divID, oDoc ) {
	if( !oDoc ) { oDoc = document; }
	if( document.layers ) {
		if( oDoc.layers[divID] ) { return oDoc.layers[divID]; } else {
			for( var x = 0, y; !y && x < oDoc.layers.length; x++ ) {
				y = getRefToDivNest(divID,oDoc.layers[x].document); }
			return y; } }
	if( document.getElementById ) { return oDoc.getElementById(divID); }
	if( document.all ) { return oDoc.all[divID]; }
	return oDoc[divID];
}

function resizeWinTo( idOfDiv ) {
	var oH = getRefToDivMod( idOfDiv ); if( !oH ) { return false; }
	var x = window; x.resizeTo( screen.availWidth, screen.availWidth );
	var oW = oH.clip ? oH.clip.width : oH.offsetWidth;
	var oH = oH.clip ? oH.clip.height : oH.offsetHeight; if( !oH ) { return false; }
	x.resizeTo( oW + 200, oH + 200 );
	var myW = 0, myH = 0, d = x.document.documentElement, b = x.document.body;
	if( x.innerWidth ) { myW = x.innerWidth; myH = x.innerHeight; }
	else if( d && d.clientWidth ) { myW = d.clientWidth; myH = d.clientHeight; }
	else if( b && b.clientWidth ) { myW = b.clientWidth; myH = b.clientHeight; }
	if( window.opera && !document.childNodes ) { myW += 16; }
	//second sample, as the table may have resized
	var oH2 = getRefToDivMod( idOfDiv );
	var oW2 = oH2.clip ? oH2.clip.width : oH2.offsetWidth;
	var oH2 = oH2.clip ? oH2.clip.height : oH2.offsetHeight;
	x.resizeTo( oW2 + ( ( oW + 200 ) - myW ), oH2 + ( (oH + 200 ) - myH ) );
}

//-->
</script>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function getParams() {
var idx = document.URL.indexOf('?');
var params = new Array();
if (idx != -1) {
var pairs = document.URL.substring(idx+1, document.URL.length).split('&');
for (var i=0; i<pairs.length; i++) {
nameVal = pairs[i].split('=');
params[nameVal[0]] = nameVal[1];
   }
}
return params;
}
params = getParams();
//  End -->
</script>
	</head>
	<body onload="resizeWinTo('mydiv');window.location.href='http://www.dj-promo.co.uk/mixes/downloadfile.php?file=' + unescape(params['filename1']);" style="padding:0;margin:0;" topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0" marginwidth="0" marginheight="0">
		<div style="position:absolute;left:0px;top:0px;" id="mydiv">
			<table border="0">
				<tr><td><script language="JavaScript">
<!--

/*
Random Image Link Script- By JavaScript Kit(http://www.javascriptkit.com) 
Over 200+ free JavaScripts here!
Updated: 00/04/25
*/

function random_imglink(){
var myimages=new Array()
//specify random images below. You can have as many as you wish
myimages[1]="flyers/urbanaffairmarch272009.jpg"
myimages[2]="flyers/urbanaffairmarch272009back.jpg"
myimages[3]="flyers/enticebabalou.jpg"


//specify corresponding links below
var imagelinks=new Array()
imagelinks[1]="http://www.urbanfmtv.com/"
imagelinks[2]="http://www.urbanfmtv.com/"
imagelinks[3]="http://www.enticeparties.com/"


var ry=Math.floor(Math.random()*myimages.length)
if (ry==0)
ry=1
document.write('<a href='+'"'+imagelinks[ry]+'"'+' target="_blank" title="click here to view further information"><img src="'+myimages[ry]+'" border=0></a>')
}
random_imglink()
//-->
</script></td></tr>
			</table>
		</div>
</body>
</head>
Thanks for looking
DJ Hands3 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:58 PM.


Advertisement
Log in to turn off these ads.