pzt_penguin Posted December 9, 2006 Share Posted December 9, 2006 Hi I've been rewriting some old perl scripts to php and I'm stuck.I'm a novice at best with php, but I've already transfered about 7scripts to php. My problem right now is a mysql query.[i]The Perl/CGI query[/i][code]$query= "insert into $gametable ". "(user1,user2,yourname,opponentname,score,host,reportdate,time,comment,rating1,rating2,streak) ". "values ". "('$i{username}','$i{opponent}','$i{yourname}','$i{opponentname}','$score','$host',CURRENT_DATE(),CURRENT_TIME(),'$i{comment}','".$data->{rating}."','".$opponent->{rating}."','".$opponent->{winstreak}."')";$insert=$dbh->prepare($query);[/code]I'm getting stuck at [b]'".$data->{rating}",'".$opponent->{rating}."','".$opponent->{winstreak}."'[/b] [i]rating[/i] and [i]winstreak[/i] are fields in my DB. The problem I'm having is I can't figure out how toprase that for php. Could anyone give me some pointers on how to prase this?Here is The php query I have so far.[code]#Insert game data into the gametable$sql_games = mysql_query("insert into $gametable ". "(user1,user2,yourname,opponentname,score,reportdate,time,comment,rating1,rating2,streak) ". "values ". "('$username','$opponent','$yourname','$opponentname','$score','DATE()','localtime()','$comment','','','')") or die (mysql_error()); [/code]As you can tell I haven't finished the end of the query. Thanks in advance for the help. 8) Quote Link to comment Share on other sites More sharing options...
pzt_penguin Posted December 9, 2006 Author Share Posted December 9, 2006 could some atleast please explain this[code]$opponent -> winstreak[/code]I can't find any thing on that operator. Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted December 9, 2006 Share Posted December 9, 2006 In perl it is refering to the opponent object's winstreak value. In your perl script you say that the $data->{rating}, $opponent->{winstreak} and $opponent->{rating} are coming from the database...you need to execute those queries to get the results in another object...for this example I'll call them "data_query" and "opponent_query".[code]//execute the data_query$data_result = mysql_query($data_query);//retrieve the first object returned...using mysql_fetch_array or mysql_fetch_assoc would work here too$data = mysql_fetch_object($data_result); //repeat for opponent$opp_result = mysql_query($opponent_query);$opponent = mysql_fetch_object($opp_result);#Insert game data into the gametable$games_query = "INSERT INTO $gametable (user1, user2, yourname, opponentname, score, reportdate, time, comment, rating1, rating2, streak) " . "VALUES ('$username','$opponent','$yourname','$opponentname','$score','DATE()','localtime()','$comment','" . $data->rating ."','" . $opponent->rating . "','" . $opponent->winstreak . "')";$sql_games = mysql_query($games_query);[/code] Quote Link to comment Share on other sites More sharing options...
pzt_penguin Posted December 28, 2006 Author Share Posted December 28, 2006 Thanks for the help. 8) I would of replied sooner but I couldn't post. :-[ After reading the forum FAQs I found out why.I have another problem with some perl translation. The problem is with perl subroutines here is the code I'm having a problem with.[code]sub rateplayer{ my $player=shift; my $orating=shift; my $score=shift; my ($rate,%rec,$d,$p,$newrating,$diff,$newfloor);[/code]My problem is shift. I don't think the perl operator shift is like the php operator shift >> << after reading this.[quote]The second, and sometimes preferred, way is to use the shift operator. shift pulls the first member out of the array specified and returns it[/quote]I'm I wrong about that will the php shift operator work the same? If not what could I sub for that? I've tried searching,but the only thing I found was array_shift and I don't think that would work. :-\ Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.