PDA

View Full Version : PHP Help



-Adam
04-11-2009, 03:19 PM
Well, I have 2 questions to do with PHP.

For my mafia game im making, I need to sort out 2 things.

1. Im making better crimes for you when you get to a certain rank, Ect bodyguard. So how would I make it so that the link appears when your bodyguard+. Also, How would I make it so that if your not bodyguard and you try and get onto the page it says You are not the required rank!

2. For my Newspaper control panel, how would I make it say you are not an editor if editor=0, as if editor=1 you will be an editor.

Please help :P

LMS16
04-11-2009, 03:55 PM
Well, i know simple php so id do this:


<?php
session_start();
include("config.php");
$username = $_SESSION['username'];
$check = mysql_query("SELECT * FROM `staff` WHERE `username`='$username'") or die (mysql_error());
$get = mysql_fetch_array($check);
if($get[rank] == "bodyguard"){
?>
PUT CODE U WANNA SHOW IF THEIR RANK IS BODYGUARD HERE
<?}else{ echo("Error, you aint a bodyguard!!"); }?>

For the editor bit, its the same..


<?php
session_start();
include("config.php");
$username = $_SESSION['username'];
$check = mysql_query("SELECT * FROM `staff` WHERE `username`='$username'") or die (mysql_error());
$get = mysql_fetch_array($check);
if($get[editor] == "1"){
?>
PUT CODE U WANNA SHOW IF THEIR RANK IS EDITOR HERE
<?}else{ echo("Error, you aint an editor!!"); }?>

Its just a simple way, there are other and ppl will probs flame me for this but yeah.

Lew.

-Adam
04-11-2009, 03:58 PM
Thanks:)

-Adam
04-11-2009, 05:03 PM
Doesnt work. I forgot to mention I only want the 1st question for a section in a menu

LMS16
04-11-2009, 07:23 PM
It basically works the same way...

<?php
session_start();
include("config.php");
$username = $_SESSION['username'];
$check = mysql_query("SELECT * FROM `staff` WHERE `username`='$username'") or die (mysql_error());
$get = mysql_fetch_array($check);
if($get[rank] == "bodyguard"){
?>
PUT IMAGE OR DIV HERE FOR BODY GUARD NAVIGATION BUTTON
<?}?>

-Adam
04-11-2009, 08:54 PM
I dont think you get me.

EDIT: Also, what would I put for the query and the fetch bit. The 'rank' table is in the 'players' database.

This is a section in my menu of my game:

<br />
<table align="center" width="100%" class="tbl">
<tr><td align="center" class="hdr">.::Crime Scene::.</td></tr>
<tr><td align="left" class="tbl">
&nbsp;<a href="kill.php" target="main">Kill</a><br />
&nbsp;<a href="bf.php" target="main">Bullet factory</a><br />
&nbsp;<a href="crime.php" target="main">Crimes</a><br />
&nbsp;<a href="gta.php" target="main">Car theft</a><br />
&nbsp;<a href="bta.php" target="main">Boat theft</a><br />
&nbsp;<a href="extortion.php" target="main">Extortion</a><br />
&nbsp;<a href="garage.php" target="main">Garage</a><br />
&nbsp;<a href="dock.php" target="main">Dock</a><br />
&nbsp;<a href="drugs.php" target="main">Drugs</a><br />
&nbsp;<a href="bank.php" target="main">Bank</a><br />
&nbsp;<a href="atm.php" target="main">ATM</a><br />
&nbsp;<a href="mission.php" target="main">Missions</a><br />
&nbsp;<a href="oc.php" target="main">OC</a><br />
</td></tr>
</table>
<br />

Say If I wanted to make that section for bodyguards only, what would I put above that section. For my admincp bit, iv got above it: <? if ($a['level'] == "3"){ ?>
Then nothing else and it works. So It would be nearly the same to have it as a rank. So what would I put? I need just the one line of code.

Blinger1
04-11-2009, 09:53 PM
I don't think you are explaining yourself clearly.. But i think you mean something like this (its a switch function).. (probably not the best coding ever either)



<?php
function getRank($username){

$sql = "SELECT rank FROM rank WHERE username='{$username}'";
$query = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_array($query);
$rank = $row['rank'];

switch ($rank) {
case "apprentice":

echo('<br />
<table align="center" width="100%" class="tbl">
<tr><td align="center" class="hdr">.::Crime Scene::.</td></tr>
<tr><td align="left" class="tbl">
&nbsp;<a href="kill.php" target="main">Kill</a><br />
&nbsp;<a href="bf.php" target="main">Bullet factory</a><br />
&nbsp;<a href="crime.php" target="main">Crimes</a><br />
&nbsp;<a href="oc.php" target="main">OC</a><br />
</td></tr>
</table>
<br />');

break;

case "bodyguard":

echo('<br />
<table align="center" width="100%" class="tbl">
<tr><td align="center" class="hdr">.::Crime Scene::.</td></tr>
<tr><td align="left" class="tbl">
&nbsp;<a href="kill.php" target="main">Kill</a><br />
&nbsp;<a href="bf.php" target="main">Bullet factory</a><br />
&nbsp;<a href="crime.php" target="main">Crimes</a><br />
&nbsp;<a href="gta.php" target="main">Car theft</a><br />
&nbsp;<a href="bta.php" target="main">Boat theft</a><br />
&nbsp;<a href="extortion.php" target="main">Extortion</a><br />
&nbsp;<a href="garage.php" target="main">Garage</a><br />
&nbsp;<a href="dock.php" target="main">Dock</a><br />
&nbsp;<a href="drugs.php" target="main">Drugs</a><br />
&nbsp;<a href="bank.php" target="main">Bank</a><br />
&nbsp;<a href="atm.php" target="main">ATM</a><br />
&nbsp;<a href="mission.php" target="main">Missions</a><br />
&nbsp;<a href="oc.php" target="main">OC</a><br />
</td></tr>
</table>
<br />');
break;
}

}
?>


and for usage do this:



<?php
getRank("Blinger");
?>

Want to hide these adverts? Register an account for free!