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
https://forums.phpfreaks.com/topic/30015-perl-to-php-problem/
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
https://forums.phpfreaks.com/topic/30015-perl-to-php-problem/#findComment-138163
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
https://forums.phpfreaks.com/topic/30015-perl-to-php-problem/#findComment-148921
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.