PDA

View Full Version : PHP code help needed




mum4d
Nov 2, 2004, 10:12 AM
I'm trying to learn PHP. The test page I have created here (http://www.screenhouse.kicks-ass.net:16080/shg/untitled-2.php) uses the following code to "include" another php file to generate the text, button and rubbish in the gray area:
<? $x = 'test.php'; ?>
<?php include($x); ?>

How do I wright the code so when i click on one of the buttons at the top of the page (home, what, how....) the php file placed by the "include" function changes and the content of the gray area changes? I'm sure it must be somthing like "<? $x = 'test2.php'; ?>" or "<? $x = 'test3.php'; ?> and so on, but I dont know how to attach this to the button image????

The php code for the main page is <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript">
<!--

function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_callJS(jsStr) { //v2.0
return eval(jsStr)
}
//-->
</script>


<style type="text/css">

<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
.style4 {
font-family: Arial, Helvetica, sans-serif;
font-size: 9px;
color: #333333;
}
.style3 { font-family: Arial, Helvetica, sans-serif;
font-size: 10px;
color: #000000;
}
-->

</style>
</head>

<body onLoad="MM_preloadImages('home_f2.gif','what_f2.gif','how_f2.gif','work_f2.gif','contact_f2.gif','news_f2.gi f','ftp_f2.gif')">
<table width="700" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="700" bgcolor="#FFFFFF">
<div align="left"><img src="SHG.gif" width="613" height="103"></div></td>
</tr>
<tr>
<td><a href="<? $x = 'test.php'; ?>"><img src="home.gif" name="Image1" width="100" height="15" border="0" id="Image1" onMouseOver="MM_swapImage('Image1','','home_f2.gif',1)" onMouseOut="MM_swapImgRestore()"></a><img src="what.gif" name="Image2" width="100" height="15" id="Image2" onMouseOver="MM_swapImage('Image2','','what_f2.gif',1)" onMouseOut="MM_swapImgRestore()"><img src="how.gif" name="Image3" width="100" height="15" id="Image3" onMouseOver="MM_swapImage('Image3','','how_f2.gif',1)" onMouseOut="MM_swapImgRestore()"><img src="work.gif" name="Image4" width="100" height="15" id="Image4" onMouseOver="MM_swapImage('Image4','','work_f2.gif',1)" onMouseOut="MM_swapImgRestore()"><img src="contact.gif" name="Image5" width="100" height="15" id="Image5" onMouseOver="MM_swapImage('Image5','','contact_f2.gif',1)" onMouseOut="MM_swapImgRestore()"><img src="news.gif" name="Image6" width="100" height="15" id="Image6" onMouseOver="MM_swapImage('Image6','','news_f2.gif',1)" onMouseOut="MM_swapImgRestore()"><img src="ftp.gif" name="Image7" width="100" height="15" id="Image7" onMouseOver="MM_swapImage('Image7','','ftp_f2.gif',1)" onMouseOut="MM_swapImgRestore()"></td>
</tr>
<tr>
<td height="350" valign="top" background="logo.gif"><div align="center">
<table width="90%" >
<tr>
<td><span class="style3">
<?php include($x); ?>
</span></td>
</tr>
</table>
</div></td>
</tr>
<tr>
<td height="12" bgcolor="#CCCCCC"><div align="center" class="style4">Coptright&copy; 2004
Screenhouse Group</div></td>
</tr>
</table>
<p>&nbsp;</p>
</body>
</html>



rand()
Nov 2, 2004, 03:00 PM
<? $x = 'test.php'; ?>
<?php include($x); ?>

Firstly, you don't need to '?> it off after each line. Simply:
<?php $x = 'test.php';
include($x);?>

would work, as long as you aren't going to be dividing those lines with HTML.

Secondly, HUH??? I'm not figuring out in any way what you're trying to do. I think that you're completely confused on the purpose of the include() function.

If you want a PHP function to generate text for you, you have to denote that text by using the "echo" function.

<?php echo "Hi.";?>
would add the text "Hi." to that portion of the document. If the functions in your PHP file doen't have any echo statements they're probably running, but aren't relaying their text into your final file.

Anyway, I hope that helps. If you could clarify what exactly you're trying to do, that would be helpful also (i.e., include the text of your 'test.php' file).

Code on!
-rand()

brianellisrules
Nov 3, 2004, 09:29 AM
I'm not sure if I follow completely, but it sorta sounds like you want the person to be able to click on a button and have the value of $x change with each click?

I'd think the code might look something like:
<?php
if (!$x) {include('test.php');
else {include ($x.'.php');}
?>

and your links would look like:
<a href="?x=test"> or <a href="?x=test2">

mum4d
Nov 4, 2004, 08:46 AM
I'm not sure if I follow completely, but it sorta sounds like you want the person to be able to click on a button and have the value of $x change with each click?

I'd think the code might look something like:
<?php
if (!$x) {include('test.php');
else {include ($x.'.php');}
?>

and your links would look like:
<a href="?x=test"> or <a href="?x=test2">

Thats exacly what I needed

Thanks very much

logicat2001
Nov 4, 2004, 09:33 AM
<edited></edited>

Ah. Just realized the href's in the html above.

Best,
Logicat