Jump to content

Perl to PHP problem


pzt_penguin

Recommended Posts

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 7
scripts 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 to
prase 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)
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

  • 3 weeks later...
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. :-\
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.