Click to See Complete Forum and Search --> : Im looking for help with PHP
airforcefc
02-23-2008, 04:26 AM
Hello,
I really need a professional that knows PHP to get some of my script working properly. I have been in the process of getting a Rock, Paper, Scissors game together and would love to share the whole thing once finished but am stuck on the final process script if anyone could help please post a reply and I will repost the script for you to look at,
Thanx in advance
scragar
02-23-2008, 04:42 AM
you should have posted code right away. use the forums and tags.switch($_GET['pick']){// get choice:
case 'rock':
$user = 1;
break;
case 'paper':
$user = 2;
break;
case 'sissors':
$user = 3;
break;
default:
$user = 0;
break;
};
if($user){// if playing:
$comp = rand(1, 3);// generate random pick
$choices = array(1=>'rock', 2=>'paper', 3=>'sissors');
echo "<p>You picked {$choices[$user]}.</p>
<p>computer picked {$choices[$comp]}.</p>";
// work out who's won:
if($user == $comp)
echo "<p>DRAW</p>";
if($user+1 == $comp || ($user == 3 && $comp == 1))
echo "<p>COMPUTER VICTORY</p>";
if($user == $comp+1 || ($user == 1 && $comp == 3))
echo "<p>USER VICTORY</p>";
};
echo "<p>pick a choice:</p>
<p><a href='?pick=rock'>rock</a>
<a href='?pick=paper'>paper</a>
<a href='?pick=sissors'>sissors</a></p>";
blue-eye-labs
02-23-2008, 04:56 AM
yeah... always just post the script, as scragar said, and then everyone will take a look and try to help.
airforcefc
02-23-2008, 08:00 PM
Here is the script Im having trouble with. I didn't post the script because i posted it in another thread but no1 could help. The way I have it working if that a member on my site submits a challenge to another member then the member that received the challenge will submit their pick, then this process needs to be done but cannot get it to work as I do not understand how to make it work,
<?php
//Connect to server and select database.
mysql_connect("$host", "$username1", "$password1")or die("cannot connect to server");
mysql_select_db("$db_name")or die("cannot select DB");
$id=$_POST['id'];
$defender=$_POST['pkVal0'];
$from_member=$_POST['from_member'];
$to_member=$_POST['to_member'];
$attacker=$_POST['challenger_pick'];
//Need help here
if($attacker selected "1" && $defender selected "2") then
defender wins
elseif(attacker selected "1" && defender selected "3") then
attacker wins
if($attacker selected "2" && $defender selected "1") then
attacker wins
elseif(attacker selected "2" && defender selected "3") then
defender wins
if($attacker selected "3" && $defender selected "1") then
defender wins
elseif(attacker selected "3" && defender selected "2") then
attacker wins
If attacker = defender selection both = "DRAW"
//Add points up
from_memberladder= 1 point for $WIN,$Draw,$Loss
to_memberladder= 1 point for $WIN,$Draw,$Loss
// Insert data from Attacker into database
$sql="INSERT INTO gameladder(member,win,draw,loss)VALUES('$from_memberladder','$win','$draw','$loss')";
$result=mysql_query($sql) or die("SQL Error: $sql<br>" . mysql_error());
// Insert data from Defender into database
$sql="INSERT INTO gameladder(member,win,draw,loss)VALUES('$to_memberladder','$win','$draw','$loss')";
$result=mysql_query($sql) or die("SQL Error: $sql<br>" . mysql_error());
// Insert HISTORY data into database
$sql="INSERT INTO gamehistory(from_member,from_selected,to_member,to_selected,winner)VALUES('$from_member','$from_sele cted','$to_member','$to_selected','$winner')";
$result=mysql_query($sql) or die("SQL Error: $sql<br>" . mysql_error());
if($result){
header("location:rpschallenge.php");
}
else {
echo "ERROR";
}
// close connection
mysql_close();
?>
airforcefc
02-23-2008, 08:10 PM
This was the extra info that might help also:
I have a selection system where from the FORM where the member selects their pick I have made it so value - rock=1 , paper=2 , scissors=3.
Now once the member selects their opponent, they click submit.
The information goes into a Table:
Table = "game".
id / from_member / to_member / selected
When the member that has received the challenge selects play and picked their selection I have this file that needs to process it all but I am stuck with limited PHP knowledge on this one so roughly did it out how I think it might go.
I also have a Ladder that displays all members with their win,draw,loss totals.
And I have a history for both the attacker and the defender so that each can see who they have played and which people they have won and lost again and also each players moves.