Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 days ago.
Improve this question
I'm trying to find the sum of numbers by querying a database using PHP and MYSQL. I need a while loop or any other solution that can add numbers that are >= 40 from a sequence of numbers. I'm only able to make the query but don't know how to go about the rest.
$selectMARK="SELECT mark FROM resultstbl WHERE mark >= 40";
$queryMARK=mysqli_query($dbCon, $select);
$sum=0;
while($rowz=mysqli_fetch_assoc($queryMARK))
{
// need some code to add the numbers here
}
You maybe need an
$iterator = 0;
outside the loop, that you can increment inside of it.
$sum += $rowz[$iterator];
$iterator++:
Then do your condition around it by checking $rowz[$iterator] <= 40
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 months ago.
Improve this question
Input data:
In the input file INPUT.TXT there are two non-negative integers are given by two rows and the numbers are less than 10 powered by 100.
Output data:
in the OUTPUT.TXT file is needed to return sum of the numbers to one row, without initial zeros
Example:
#
input.txt
output.txt
1
3
7
4
Check it , It will help you
$data = explode("\n", file_get_contents('INPUT.TXT'));
$sum = intval($data[0])+intval($data[1]);
echo $sum;
file_put_contents('OUTPUT.TXT', $sum);
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed last year.
Improve this question
Suppose , I have a array with some integers value (odd and even both mixed) in php.and I want to get last even number.
A loop that works backwards through the array would work.
$number=false;
$a=array(2,4,5,4,6,7,13,11,95,88,16,17,107);
for($i=count($a)-1; $i >= 0; $i--){
if( $a[$i] % 2 == 0 ){
$number=$a[$i];
break;
}
}
echo $number; //16
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
So, I want to generate all possible 4 digit numbers in columns, one by one, (0-9) from 0000 to 9999, and concatenate a string before them, like:
text0000
text0001
text0002
text0003
text0004
text0005
Thanks in advance.
Following will do the trick.
for($i=0;$i<10000;$i++)
echo "text".str_pad ($i,4,'0', STR_PAD_LEFT)."<br />";
$yourString = 'text';
$generateNumberUpTo=9999;
for ($i = 0; $i <= $generateNumberUpTo; $i++)
echo sprintf("$yourString%'.04d<br/>", $i);
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I have a function called calculate. And inside the calculate function I have a paramater next to it
function calculate($id){
..
}
What I'm trying to figure out how to do is make a loop which will start the loop and the function calculate will start with the ($id) next to it from 1 to 10. So it does the same thing 10 times with the id set to 1 then 2 then 3 and so on to 10.
Try using range
function calculate($id){
//other statements
// return ;
}
foreach (range(0, 10) as $id) {
calculate($id);
}
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
When I print out the integers (1 or 0), all the iterations (there are 3 of them in this case) print out the correct number. First and the second one return 1, the last one returns zero. BUT, 'if' statement seems to display everything in it anyway. What am I doing wrong?
All the code below is inside a bigger 'for' loop.
$yn = 0;
if(!in_array($pos, $blocks)){
$blocks[$x] = $pos;
$x++;
$yn = 1;
}
print_r($blocks);
print "YN: ".$yn; # this prints out 1, 1 and 0 on the last iteration
if(yn){
# show some stuff (is displayed in all three iterations, but it shouldn't be on the last)
}
Try:
if($yn){
PHP is interpreting yn as a string, rather than as the variable you should be using.