The following code prints a number incremented by 2 every time I reload the page.
<?php
//Memcahce
$memcache = new Memcached;
$memcache->increment('hits');
echo "hitcount = ".$memcache->get('hits');
output
hitcount = 2
Expected : It should increment by 1.
I tried setting it to 2 and 5 but still it increments by 4 and 10 respectively.
Related
I want to hit 2 values with the same id on PhpMyAdmin. According to the codes below, only the aggregation is running in the outputs I receive. I get a value of 0 when I multiply instead of adding.
<?php
$a = 0;
$oran = new sorgu;
$k_id = $kuponlar->veri->id;
$oran->select("*","matches","kid=$k_id");
while($oran->verioku()){
$a = $a+ floatval($oran->veri->oran);
}
echo $a;
?>
Screenshots:
It is necessary to multiply the "oran" values in there. But those with the same "kid" value are at least struck for that table.
That's the code that's running
Action Required:
1,25 x 1,5 x 1,3 x 1,55
I have a webpage that refreshes every X minute and shows some information from an array.
Name Value
-------------
Mark 546
Donald 312
My question is what is the easiest way to temporarily store the old value and compare it to the new value between page refreshes (see below)? It could be per user based simply when visiting the page. Php session and cookies maybe?
Name Value Change
--------------------
Mark 559 +13
Donald 233 -79
So you can easily do it with sessions
//structure in sessions could be like this
$_SESSION['last'] = $data; // all the data you echo
$_SESSION['last']['timestamp'] = $time; //timestamp when you fetched this data
$_SESSION['previous'] = $old_data; // store the last data
// each time last data is older than 5 min, refresh
if (time() - $_SESSION['last']['timestamp'] > 5 * 60){
//store current data as previous
$_SESSION['previous'] = $_SESSION['last'];
//set new data in $data
$_SESSION['last'] = $data; // set all your new data
$_SESSION['last']['timestamp'] = time(); //set timestamp
}
I'm having some kind of problem and i don't know how i solve it.
The problem is, that i have 500 registers in another database, and the query to get them its has them all, but when i do the cycle to insert/update them in m y database the foreach cycle don't reach the end and it doesn't show any error.
Here is the cycle:
foreach ($this->getMetaEmpregado()->getAll()->result_array() as $modelData) {
$oEmpregado = $this->getEmpregadoObject($modelData);
$arrayEmpWhere = array(
'idempregado' => $oEmpregado->getIdEmpregado(),
'idsociedade' => $oEmpregado->getIdSociedade(),
'nif' => $oEmpregado->getNif()
);
if ($this->getWayUtilizador()->get($arrayEmpWhere)->num_rows() == 0) {
$countInsert++;
$this->insertNewEmp($oEmpregado);
} else {
$countUpdate++;
$this->UpdateEmp($oEmpregado);
}
}
echo "Total Updates: $countUpdate Total Inserts: $countInsert<br>";
It down't shoe the echo in the end because its stops around the 260 register, but sometimes it reaches the 300 others not even 100.
Regards,Elkas
It seems that the script is taking too long, You need to increase the Max_Execution_Time in your php.ini.
You can use ini_set method to change it, like this:
ini_set('max_execution_time', 600); //600 seconds = 10 minutes
Hope this helps.
I have a table comment as follow:
Comment
comment_id cmt followupid
1 Hello 3
2 hi 4
3 Hey 2
4 wassup 1
My query is that I want to echo "Hello", "hi", "hey" , "Wassup" and other (the record continues) individualy, I have used
$comment = mysql_result($runQuery, $i,"cmt");
echo $comment;
which works fine but the problem is that it echoes all the comments at once, what I want is to echo all the comment but one at a time. the comment are in a div tag such that each the div appears only after 1 second the page is loaded. I want each comment to appear after different time interval
for e.g:
Hello to appear at 5pm (not necessarily the corect time it can be just an int)
hi 5.10 pm
hey 6.30 pm
Please Help!
The following code should give you some hints.
$result = mysql_query($runquery);
while($row=mysql_fetch_assoc($result)){
// $row contains a single row.
echo $row['cmt'], $row['comment_id']
}
Create another variable storing time divisions(or number of rows). So that different output at different time can be fetched. For eg. If your table has 24 rows(or items), then this variable shall have a value 24. Use it to divide you output times(As in 24 hours, each hour a different value).
Now, the PHP part(I am not much familiar with date and time functions in PHP, so you can totally ignore the paragraph above.
$result = mysql_query($runquery);
$j = 0;
$i = rand( 0, mysql_num_rows($result) );
while($row=mysql_fetch_assoc($result)){
// $row contains a single row.
if( $j++ = $i )
echo $row['cmt'], $row['comment_id'];
}
This will fetch one random row from the table, but not depending upon the server time.
Hope you can help I have a simple query updating positions x and y based various user id etc. But I have a problem when I pass the variable to be updated (through ajax) to PHP, I get the variable fine but on placing it in a query a number 1 is added to the query end making the last id unusable (see example id 68 becomes 681).
Never seen this before, I am relatively new to sql tho, hope someone can shed some light on this?
$xupdate = $_POST['xupdate'];
$yupdate = $_POST['yupdate'];
$stickytext_id = $_POST['stickytextid'];
$user_id= $_POST['uid'];
$proj_id=$_POST['projid'];
echo $xupdate; //output 358
echo'<br>';
echo $yupdate; //output 203
echo'<br>';
echo $stickytext_id; //output 68
echo'<br>';
echo $proj_id; //output 7
echo'<br>';
$sql_update_stickyxy="UPDATE textsticky SET textsticky_x = $xupdate AND textsticky_y = $yupdate
WHERE textsticky_id = $stickytext_id";
echo $sql_update_stickyxy; //outputs UPDATE textsticky SET textsticky_x = 358 WHERE textsticky_id = 681 not 68?
Looking at your echo'd output you obviously embezzled some of your code. As a first debugging measure you might use $_POST['stickytextid'] instead of $stickytext_id inside your query and see where it gets you.