Hei,
i need help with php code. So, I have a lots of pages - but it would be nicer to put them to ONE page, if this is possible with "_GET" and "IF" function.. and with "echo".

Like when the page is "page.php?p=moderator" shows me moderators.. if this is "page.php?p=userinfo?id=1" shows me information of this user whose ID is 1(from database).

<?php $p = $_GET['p']; if ( !$p || $p == "hello1" ) 
{
echo "Hello1?";
}
if ( !$p || $p == "mode" ) 
{
echo "Text2?";
}

Put how to put like this, that if there's no ID($p) then it shows other text? :O

Or you could put contents of pages into separate files and then to load appropriate file in if or switch - like

if ($page == 'moderators')
    $content = file_get_contents('moderators.html');
else 
    $content = file_get_contents('somethingelse.html');
...
echo $content;

that way it would be easier to maintain :-)

Regards

I know about the switch and stuff. But how to add php in switch, like I have these kind of pages..

<?php
include("peaosa.php");
?>

<!-- main page start -->

<div id="content2">

<?php
if ($prot->showPage) {

if(($curuserrank3 > 1) && ($curuserrank3 < 6)){
?>

<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="10%" valign="top" id="leftbg">
	<?php 
	#if($prot->showPage){ 
	include("tegevused.php"); 
	#}
	?>

    <?php 
	#120x60 küljebännerid
	include("banners_right.php"); 
	?>

    
	</td>
    <td valign="top">



<font class="lehe_pealkiri">Kahtlased kasutajad</font>
Siin lehel on kasutajad, kes on moderaatorite meelest mingis mõttes kahtlased (fake?)<br>
Kes siia lisab m&otilde;ne kasutaja, see lisab sinna juurde ka kommentaari, et miks kasutaja tundub kahtlane<br>
v&otilde;i äkki lausa fake, aga pole 100% kindel.

<table width="100%" border="0" cellspacing="2" cellpadding="2">
  <tr>
    <td>
	
<table width="100%" border="0" cellspacing="2" cellpadding="2">
<?php 
$kasutaja2 = mysql_query("select * from myuser where fake_note!='' order by fake_date desc");
$kokkueri = mysql_num_rows($kasutaja2);
$i=0;
while($eriline = mysql_fetch_array($kasutaja2)){
	$user_id = $eriline["0"];
//	$src = $eriline["src"];
	//$subject = $eriline["subject"];
	//$comment = $eriline["comment"];
//	$user_name = $eriline["userName"];
	$adddate = $eriline["adddate"];
	$date = $eriline["fake_date"];
	//$active = $eriline["active"];
	$comment = stripslashes($eriline["fake_note"]);
	//$imgvoters = $eriline["numvotes"];
	//$imgvotes = $eriline["allvotes"];
	//$imgscore = $eriline["score"];	
	//$usersex = $eriline["usersex"];
	$mode_id = $eriline["fake_mode_id"];
	$block = $eriline["blok_com"];

// laeme kasutaja pildi:
			$sel_pic2 = mysql_query("select id,src from photo where userid='$user_id' LIMIT 1");
			$if_is2=mysql_num_rows($sel_pic2);
	
$showuser = showusername($user_id, "index");
if(empty($mode_id)){
$showmode = showusername("2167", "index");
}else{
$showmode = showusername($mode_id, "index");
}
if ($i == 0){ 
echo '<TR>'; 
}
echo"<TD valign='top' colspan=3 width='632' align='left'>
<div id='top_pildikast_top'>#$kokkueri</div>
</td></tr>
<TR><TD valign='top' id='pildikast' width=130 align='center'>";

//kuvame pildi:	
		if($if_is2=="1"){
			$picinf2=mysql_fetch_array($sel_pic2);
			$fid2=$picinf2["id"];
			$fsrc2=$picinf2["src"];
			
			echo"<a href=\"vaata.php?id=$fid2\"><img src=\"thumb/$fsrc2\" border=0  class='img' vspace=1 ></a>";
		}else{
		echo"<a href=\"kasutaja.php?id=$user_id\"><img src=\"images/nopic.gif\" border=0 class='img' vspace=1 ></a>";
		}
	echo "<br>".$showuser;
//pildi lõpp//

echo"</td>
<TD valign='middle' id='pildikast' width=110 align='center'>
Liitus:<br>"
.$adddate."<br><br>
Lisati siia:<br>"
.$date."
</td>
<TD valign='middle' id='pildikast' width=390 align='center'>
<b>".$comment."</b>
<p>Lisas: ".$showmode;
if(!empty($block)) echo"<br><br><font color='#FFFFFF'>Blokeeritud: ".$block."</font>";

echo"</TD></TR>";

if($i>=1){
echo '</TR>';
$i=0;
}else{
$i++;
}
$kokkueri--;
} 
echo '</TABLE>';


?>

	</td>
  </tr>
</table>





    </td>
    <td width="10%" valign="top" id="rightbg" align="center">



<div class="slist">Info</div>

<table border="0" cellpadding="0" cellspacing="0" width="100%">
	<tr>
		<td class="tbl_top" colspan="2">
		</td>
		<td class="tbl_topr">
		</td>
	</tr>
	<tr>
		<td class="tbl_mid">
		</td>
		<td class="tbl_cont" valign="top">

Kahtlased kasutajad

		</td>
		<td class="tbl_midr">
		</td>
	</tr>
	<tr>
		<td class="tbl_bot" colspan="2">
		</td>
		<td class="tbl_botr">
		</td>
	</tr>
</table>

    <?php 
	#120x600 küljebänner
	include("120x600.php"); 
	?>

	</td>
  </tr>
</table>



<?php
}
}
?>

</div>


<?php 
include("alus.php");
?>

&

<?php
include("peaosa.php");
if ($prot->showPage) {

if($userismode==true){


//actions
if($_POST['allow']){
$id=$_GET['id'];
$sqlallow=mysql_query("update photo set active='1' where id='$id'");
}
if($_POST['deny']){
$id=$_GET['id'];
$pohjus=addslashes($_POST['reason']);
if(!empty($pohjus)){
$sqlallow=mysql_query("update photo set active='2', reason='$pohjus' where id='$id'");
$delsrc=$_GET['src'];
$f="gallery/".$delsrc;
if(is_file($f)&&unlink($f)){}
}
}
if($_POST['special']){
$id=$_GET['id'];
$eriline=addslashes($_POST['spec_com']);
$sqlallow=mysql_query("update photo set active='1', reason='$eriline', special='1', mode='$curUserID' where id='$id'");
}

//pildid

$andmedimg = mysql_query("select * from photo where active='0' order by id LIMIT 1");
$countimg = mysql_num_rows($andmedimg);
if($countimg > 0){
while($DSL_img = mysql_fetch_array($andmedimg)){
	$img_id = $DSL_img["id"];
	$src = $DSL_img["src"];
	$subject = htmlspecialchars(stripslashes($DSL_img["subject"]));
	$comment = htmlspecialchars(stripslashes($DSL_img["comment"]));
	$user_id = $DSL_img["userid"];
	$name_from = $DSL_img["username"];
	$date = $DSL_img["date"];
	$active = $DSL_img["active"];
	$reason = $DSL_img["reason"];
	$imgvoters = $DSL_img["numvotes"];
	$imgvotes = $DSL_img["allvotes"];
	$imgscore = $DSL_img["score"];	
	$usersex = $DSL_img["usersex"];
}
?>
Siin lehel saab vaadata viimaseid lisatud pilte, neid lubada või keelata, pilti saab võrrelda allolevate kasutaja andmetega ja teiste piltidega.<br>
<br>
<a href="kasutaja.php?id=<?php echo"$user_id"; ?>"><img src="gallery/<?php echo"$src"; ?>" border="0"></a><br>
<font class=imgsubject><?=$subject?></font><br>
<?=$comment?><br>
Pildi lisaja: <a href="kasutaja.php?id=<?php echo"$user_id"; ?>"><font class="vote"><?php echo"$name_from"; ?></font></a> | Lisamise aeg: <?php echo"$date"; ?><br>

<form name="allowf" method="post" action="mode.php?id=<?=$img_id?>">
<input class="logout" type="submit" name="allow" value="lasen pildi üles">
</form><br>
<form name="denyf" method="post" action="mode.php?id=<?=$img_id?>&src=<?=$src?>">
	<SELECT NAME="reason">
	<option value="">Põhjus:</option>
	<option value="Täpsusta oma asukohta pildil">Täpsusta oma asukohta pildil</option>
	<option value="Pilt on liiga väike">Pilt on liiga väike</option>
	<option value="Halb kvaliteet">Halb kvaliteet</option>
	<option value="Liigselt või halvasti töödeldud">Liigselt või halvasti töödeldud</option>
	<option value="Kinnitage autoriõigusi">Kinnitage autoriõigusi</option>
	<option value="Korduv pilt">Korduv pilt</option>
	<option value="Porno või erootika">Porno või erootika</option>
	<option value="Keelatud aineid propageeriv">Keelatud aineid propageeriv</option>
	<option value="Otsene reklaam">Otsene reklaam</option>
	<option value="Pole ennast piisavalt esile toonud">Pole ennast piisavalt esile toonud</option>
        <option value="Pilt ei sobi HyperRate keskkonda">Pilt ei sobi HyperRate keskkonda</option> 
       </SELECT>
<input class="logout" type="submit" name="deny" value="ei lase pilti üles">
</form><p>
<form name="specialf" method="post" action="mode.php?id=<?=$img_id?>">
kommentaar:<input class="logout" type="text" name="spec_com" value="">
<input class="logout" type="submit" name="special" value="lisa erilistesse">
</form><p>

<?php
}else{
echo"<b>Pole enam uusi pilte</b>";
}
//pildid

}
}
include("alus.php");
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.