문제

I am testing Paypal's masspay using their 'MassPay NVP example' and I having difficulty trying to amend the code so inputs data from my MySql database.

Basically I have user table in MySql which contains email address, status of payment (paid,unpaid) and balance.

CREATE TABLE `users` (
  `user_id` int(10) unsigned NOT NULL auto_increment,
  `email` varchar(100) collate latin1_general_ci NOT NULL,
  `status` enum('unpaid','paid') collate latin1_general_ci NOT NULL default 'unpaid',
  `balance` int(10) NOT NULL default '0',
  PRIMARY KEY  (`user_id`)
) ENGINE=MyISAM AUTO_INCREMENT=6 DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci

Data :

1   test1@example.net   paid    100
2   test2@example.net   unpaid  11
3   test3@example.net   unpaid  20
4   test4@example.net   unpaid  1
5   test5@example.net   unpaid  20
6   test6@example.net   unpaid  15

I then have created a query which selects users with an unpaid balance of $10 and above :

  $conn = db_connect();
  $query=$conn->query("SELECT * from users WHERE 
                       balance >='10'
                       AND status = ('unpaid')"); 

What I would like to is for each record returned from the query for it to populate the code below:

Now the code which I believe I need to amend is as follows:

    for($i = 0; $i < 3; $i++) {
    $receiverData = array(  'receiverEmail' => "user$i@paypal.com",
                            'amount' => "example_amount",);
    $receiversArray[$i] = $receiverData;
}

However I just can't get it to work, I have tried using mysqli_fetch_array and then replaced "user$i@paypal.com" with $row['email'] and "example_amount" with row['balance'] in various methods of coding but it doesn't work. Also I need it to loop to however many rows that were retrieved from the query as <3 in the for loop above.

So the end result I am looking for is for the $nvpStr string to pass with something like this:

$nvpStr = "&EMAILSUBJECT=test&RECEIVERTYPE=EmailAddress&CURRENCYCODE=USD&L_EMAIL0=$test2@example.net&L_Amt=11&L_EMAIL1=$test3@example.net&L_Amt=11&L_EMAIL2=$test3@example.net&L_Amt=20&L_EMAIL3=$test5@example.net&L_Amt=20&L_EMAIL0=$test6@example.net&L_Amt=15";

Thanks

도움이 되었습니까?

해결책

I have resolved the issue after some trial and error:

   <?php
     $nvpStr="&EMAILSUBJECT=$emailSubject&RECEIVERTYPE=$receiverType&CURRENCYCODE=$currency";   

$conn = db_connect();
  $query=$conn->query("SELECT email,balance from users WHERE 
                       balance >='10'
                       AND status = ('unpaid')");
$i = 0;
  while ($i <= mysqli_fetch_row) {
    while($row = mysqli_fetch_object($query)) { 
      $nvpStr.="&L_EMAIL$i=$row->email&L_Amt$i=$row->balance"; 
      $i++;    
}
}

    ?>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top