everytime that there are 256 hashes available there should be added 1 credits to the user account.
but it keeps looping , it add's more credits to the user account then there are actually hashes been made...
how can i fix this?
this is where i am :
<?php //second one ,much loops to
$x = $obj->hashes;
$minimal_withdraw = "255";
if ($obj->hashes > $minimal_withdraw)
do {
$DBcon->query("UPDATE promotion_users SET credits=credits+1 WHERE username='$session'");
$response = file_get_contents("https://webminepool.com/api/PK_bzM7NcgKs2c4pkidkiNpp/withdraw/" . $userRow[username] . "/" . $minimal_withdraw);
$x = $obj->hashes;
} while ($x >= $minimal_withdraw) ;
?>
This is what i also try'd :
<?php // first one
//$minimal_withdraw = "256";
//if ($obj->hashes > $minimal_withdraw) { $DBcon->query("UPDATE * FROM promotion_users SET credits=credits + 1 WHERE username=='$session'");
//$response = file_get_contents("https://webminepool.com/api/PK_bzM7NcgKs2c4pkidkiNpp/withdraw/" . //$userRow[username] . "/" . $minimal_withdraw); }
?>
And this one (didnt even load):
<?php //didnt load page
//$x = $obj->hashes;
//$minimal_withdraw = "256";
//foreach ($x >= $minimal_withdraw) {
//$DBcon->query("UPDATE promotion_users SET credits=credits+1 WHERE username='$session'");
//$response = file_get_contents("https://webminepool.com/api/PK_bzM7NcgKs2c4pkidkiNpp/withdraw/" . //$userRow[username] . "/" . $minimal_withdraw);
//} ?>
Related
I have the following code that is overwriting my array on the second pass through of the while loop.
Here is my code:
<?php
require '../vendor/autoload.php';
require_once 'constants/constants.php';
use net\authorize\api\contract\v1 as AnetAPI;
use net\authorize\api\controller as AnetController;
require('includes/application_top.php');
define("AUTHORIZENET_LOG_FILE", "phplog");
function getUnsettledTransactionList()
{
//get orders that are in the exp status
$orders_pending_query = tep_db_query("select orders_id as invoice_number from " . TABLE_ORDERS . " where orders_status = '14' order by invoice_number");
$orders_pending = array();
while ($row = mysqli_fetch_array($orders_pending_query, MYSQLI_ASSOC)) {
$orders_pending[] = $row;
}
/* Create a merchantAuthenticationType object with authentication details
retrieved from the constants file */
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
$merchantAuthentication->setName(\SampleCodeConstants::MERCHANT_LOGIN_ID);
$merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY);
// Set the transaction's refId
$refId = 'ref' . time();
$pagenum = 1;
do {
$request = new AnetAPI\GetUnsettledTransactionListRequest();
$request->setMerchantAuthentication($merchantAuthentication);
$paging = new AnetAPI\PagingType;
$paging->setLimit("1000");
$paging->setOffset($pagenum);
$request->setPaging($paging);
$controller = new AnetController\GetUnsettledTransactionListController($request);
$response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::PRODUCTION);
$transactionArray = array();
$resulttrans = array();
if (($response != null) && ($response->getMessages()->getResultCode() == "Ok")) {
if (null != $response->getTransactions()) {
foreach ($response->getTransactions() as $tx) {
$transactionArray[] = array(
'transaction_id' => $tx->getTransId(),
'invoice_number' => $tx->getInvoiceNumber()
);
// echo "TransactionID: " . $tx->getTransId() . "order ID:" . $tx->getInvoiceNumber() . "Amount:" . $tx->getSettleAmount() . "<br/>";
}
$invoiceNumbers = array_column($orders_pending, "invoice_number");
$result = array_filter($transactionArray, function ($x) use ($invoiceNumbers) {
return in_array($x["invoice_number"], $invoiceNumbers);
});
$resulttrans = array_column($result, "transaction_id");
} else {
echo "No unsettled transactions for the merchant." . "\n";
}
} else {
echo "ERROR : Invalid response\n";
$errorMessages = $response->getMessages()->getMessage();
echo "Response : " . $errorMessages[0]->getCode() . " " . $errorMessages[0]->getText() . "\n";
}
$numResults = (int) $response->getTotalNumInResultSet();
$pagenum++;
print_r($resulttrans);
} while ($numResults === 1000);
return $resulttrans;
}
getUnsettledTransactionList();
?>
the print_r($resulttrans); is actually printing 2 separate arrays, instead of my desired 1 array.
If I move the print_r($resulttrans) to after the while loop, I am only seeing the second array, meaning the first array was overwritten. I am not seeing where this is happening though as to me it seems like all results should be added onto the array.
Your code is supposed to work as you described because you are reassigning the array variable in your loop like this
$resulttrans = array_column($result, "transaction_id");
If you need to get all the resulting values in the same array you need to append it to the array. you can do that by merging the new result into your array variable like this
$resulttrans = array_merge($resulttrans, array_column($result, "transaction_id"));
I have a csv file containing about 3500 user's data. I want to import these users to my database and send them an email that they are registered.
I have the following code:
public function importUsers()
{
$this->load->model('perk/engagement_model');
$this->load->model('user/users_model');
$this->load->model('acl/aclUserRoles_model');
$allengagements = $this->engagement_model->getAll();
$filename = base_url() . 'assets/overdracht_users.csv';
$file = fopen($filename, "r");
$count = 0;
$totalImported = 0;
$importFails = array();
$mailFails = array();
while (($mappedData = fgetcsv($file, 10000, ";")) !== FALSE)
{
$count++;
//Skip first line because it is the header
if ($count > 1) {
if (!empty($mappedData[0])) {
$email = $mappedData[0];
$user = $this->users_model->getByEmail($email);
if (!$user) {
$user = new stdClass();
$user->email = $mappedData[0];
$user->first_name = $mappedData[1];
$user->family_name = $mappedData[2];
$user->address_line1 = $mappedData[3];
$user->address_postal_code = $mappedData[4];
$user->address_city = $mappedData[5];
$user->address_country = 'BE';
$user->volunteer_location = $mappedData[5];
$user->volunteer_location_max_distance = 50;
$user->phone = $mappedData[6];
if (!empty($mappedData[7])) {
$user->birthdate = $mappedData[7] . "-01-01 00:00:00";
} else {
$user->birthdate = null;
}
foreach ($allengagements as $eng) {
if ($eng->description == $mappedData[8]) {
$engagement = $eng->engagement_id;
}
}
$user->engagement = $engagement;
if (!empty($mappedData[9])) {
$date_created = str_replace('/', '-', $mappedData[9]);
$date_created = date('Y-m-d H:i:s', strtotime($date_created));
} else {
$date_created = date('Y-m-d H:i:s');
}
$user->created_at = $date_created;
if (!empty($mappedData[10])) {
$date_login = str_replace('/', '-', $mappedData[10]);
$date_login = date('Y-m-d H:i:s', strtotime($date_login));
} else {
$date_login = null;
}
$user->last_login = $date_login;
$user->auth_level = 1;
$user->is_profile_public = 1;
$user->is_account_active = 1;
$combinedname = $mappedData[1] . $mappedData[2];
$username = str_replace(' ', '', $combinedname);
if (!$this->users_model->isUsernameExists($username)) {
$uniqueUsername = $username;
} else {
$counter = 1;
while ($this->users_model->isUsernameExists($username . $counter)) {
$counter++;
}
$uniqueUsername = $username . $counter;
}
$user->username = $uniqueUsername;
$userid = $this->users_model->add($user);
if (!empty($userid)) {
$totalImported++;
//Add the user in the volunteer group in ACL
$aclData = [
'userID' => $userid,
'roleID' => 1,
'addDate' => date('Y-m-d H:i:s')
];
$this->aclUserRoles_model->add($aclData);
//Registration mail to volunteer
$mail_data['name'] = $user->first_name . ' ' . $user->family_name;
$mail_data['username'] = $user->username;
$this->email->from(GENERAL_MAIL, 'Test');
$this->email->to($user->email);
//$this->email->bcc(GENERAL_MAIL);
$this->email->subject('Test');
$message = $this->load->view('mail/register/registration',$mail_data,TRUE);
$this->email->message($message);
$mailsent = $this->email->send();
if (!$mailsent) {
array_push($mailFails, $mappedData);
}
} else {
array_push($importFails, $mappedData);
}
if ($count % 50 == 0) {
var_dump("count is " . $count);
var_dump("we are sleeping");
$min=20;
$max=40;
$randSleep = rand($min,$max);
sleep($randSleep);
var_dump("end of sleep (which is " . $randSleep . "seconds long)");
}
var_dump($user);
} else {
array_push($importFails, $mappedData);
}
}
}
}
var_dump("Totale aantal rijen in het bestand (met header) : " . $count);
var_dump("Totale aantal geimporteerd in de database : " . $totalImported);
var_dump("Totale aantal gefaalde imports in de database : " . count($importFails));
var_dump("Deze zijn gefailed : ");
var_dump($importFails);
}
If I do not add the users in the database, or send out a mail, and just var_dump() the $user, i can see all 3500+ users being correctly created in php objects (so they should be able to be inserted correctly).
The problem is that I want to add in a random sleep, between 20 and 40 seconds after every 50 mails that I sent.
So I started doing some testing and after commenting out the insert and mail code, I started running the script, noticing that after some amount (not 50 at all), it just stops for a bit, then continues and shows me the the var_dumps in my if case at the bottom, it can be shown here in the screenshots below.
The first screenshot shows the code stopping for a bit (note that I am only var_dumping stuff, i am not adding something in the database or sending out an email yet).
This screenshot shows what happens after the script reaches 200:
The script just completely stops from this point on. I have tried this 3 times, and every single time it stops exactly on 200.
What is happening here??
Most likely you're hitting default PHP limits. temporarily remove PHP default limits with:
ini_set('memory_limit',-1);
set_time_limit(0);
then, rerun the script and check your output.
There can be multiple reasons, but to know the exact one please enable error output with.
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
and if limits are not the problem, the errors will tell you more.
HINT: using logs are still better than outputting errors to the visitors, but my guess is you're testing this on your computer.
My problem is in my code I'm having problems with it calculating something with a variable that does not exists some times and some times does.
I want it to give me back number of deaths if empty '0' if not prints me what is in the variable, but for some reason i get this:
E_NOTICE : type 8 -- Undefined property: stdClass::$numDeaths -- at
line 66 E_WARNING : type 2 -- Division by zero -- at line 71
here is my code:
<?php
$apiKey = 'e9044828-20e3-46cc-9eb5-545949299803';
$summonerName = 'tamini';
$new = rawurlencode($summonerName);
$news = str_replace(' ', '', $summonerName);
$str = strtolower($news);
// get the basic summoner info
$result = file_get_contents('https://euw.api.pvp.net/api/lol/euw/v1.4/summoner/by-name/' . $new . '?api_key=' . $apiKey);
$summoner = json_decode($result)->$str;
$id = $summoner->id;
// var_dump($summoner);
?>
<?php
$clawzz = file_get_contents('https://euw.api.pvp.net/api/lol/euw/v1.3/game/by-summoner/' . $id . '/recent?api_key=' . $apiKey);
$gazazz = json_decode($clawzz);
?>
<?php
$entrieszz = $gazazz->games;
usort($entrieszz, function($ac,$bc){
return $bc->createDate-$ac->createDate;
});
foreach($entrieszz as $statSummaryzz){
$gamemodekillz = $statSummaryzz->stats->championsKilled;
$gamemodedeathz = $statSummaryzz->stats->numDeaths;
$gamemodeassistz = $statSummaryzz->stats->assists;
$kdamatchhistoryeach = ($gamemodekillz + $gamemodeassistz) / $gamemodedeathz;
echo ' <br>';
echo $gamemodekillz;
echo ' <br>';
if ($gamemodedeathz == 0){
echo '0';
}
else {
echo $gamemodedeathz ;
}
echo ' <br>';
echo $gamemodeassistz;
echo ' <br>';
if ($gamemodedeathz == 0){
echo 'Perfect Score';
}
else {
echo $kdamatchhistoryeach ;
}
?>
You need to check if the value exist:
if( isset($statSummaryzz->stats) && isset($statSummaryzz->stats->numDeaths) ) {
$gamemodedeathz = $statSummaryzz->stats->numDeaths;
}
I have this code that store a "student" object in $_SESSION:
if(isset($_POST["name"]) && isset($_POST["note"]) && isset($_POST["year"]))
{
$nom = $_POST["name"];
$note = $_POST["note"];
$session = $_POST["year"];
$vec = array("name" => $name, "note" => $note, "year" => $year);
$_SESSION["students"][] = $vec;
echo "The student has been added.<br><br>";
}
Then I have this code in another page:
function calculateAverage()
{
$av = 0;
$count = 0;
foreach($_SESSION['students'] as $student)
{
$av = $av + $student["note"];
$count = $count + 1;
}
return $av / $count;
}
function bestNote()
{
//$best = array_search(max())
return $best;
}
function worstNote()
{
$worst = min(array_search(["note"], $_SESSION['students']));
return $worst;
}
if(isset($_SESSION['students']))
{
echo "The average note of the group is = " . calculateAverage() . "\n";
echo "The one with the best note is " . bestNote()["name"] . " is " . hauteNote()["note"] . " points.\n";
echo "The one with the worst note is " . worstNote()["name"] . " with " . basseNote()["note"] . " points.\n";
}
As you can see, it is not finished. What I want to do is to be able to get the note of a student that is stored in $_SESSION["students"]. How can I do this?
Thanks for answers.
you can access the stored values within a nested array like so:
$studentNote = $_SESSION["students"][YourActiveStudent]["note"];
However, you are currently not adding but overwriting data. Use array_push() to add data to an array (your students).
And when adding a student to the array, make sure to give it a name to make it associative so you can simply "call a student":
$_SESSION["students"][$nom] = $vec;
this way, if the $nom was "Max", you could say
$_SESSION["students"]["Max"]["note"]
to get Max's note (BTW, I assume you are talking about grades or marks, rather than notes?)
I've seen a lot of posts on adding multiple rows of data (from an array) to a mysql table. I've looked at many of these and have tried some of the suggestions but nothing has worked to date. I have a problem I've seen others mention - only the first insert is entered in my table (in WordPress) to record user reviews of conference sessions.
In overview, I'm gathering data from a form which lists about 25 sessions in a conference program. I'm asking users to rate which one they prefer to see broadcast on the Internet. I'm able to get this data via $_POST and load it into an array. The array seems to be created successfully but I only get 1 line new data added to my virt_proposal_ratings table when I try to insert it using the foreach routine below. Here is the key code:
for ($i = 0; $i != $lrow; $i+=1) {
for ($x = 0; $x <= 5; $x+=1) {
echo "<p>column: " . $fcol_array["$x"] . "</p>";
$vthscol = $fcol_array["$x"];
$vratename = "rate_proposal" . $vthscol . $i;
$vpropidvar = "f_propid" . $vthscol . $i;
$vrating = $_POST[$vratename];
$vprop_id = $_POST[$vpropidvar];
$vdayrowcol = $vconfday . $vthscol . $i;
if ($vrating) {
echo "<p>vrating: " . $vrating . "</p>";
if ($rc == 0) {
$newratings[] = array('review_id'=>$vreview_id,
'user_id'=>$vrater_user_id,
'prop_id'=>$vprop_id, 'virt_rating'=>$vrating, 'dayrowcol'=>$vdayrowcol);
}
else {
array_push($newratings, $vreview_id, $vrater_user_id, $vprop_id,
$vrating, $vdayrowcol);
$rc = $rc + 1;
}
}
foreach ( $newratings as $newrec ) {
$wpdb->insert('virt_proposal_ratings',
$newrec, array("%d", "%d", "%d", "%s"));
}