Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I am trying to create a query from the data i receive from an array of objects in php. I keep receiving an error on the nested if inside a case. unexpected '{', is it because I can't have an if within a case?
switch($name){
case 'players':
$query .= " min_players <=".$value." AND max_players >=".$value." AND";
break;
case 'max-duration':
if((intval($value) >= 45) {
$min = intval($value)-30;
$query .= " duration <=".$value." AND duration >=".$min." AND";
} else { //if duration < 45
$query .= " duration <=".$value." AND";
}//end else
break;
}
switch($name){
case 'players':
$query .= " min_players <=".$value." AND max_players >=".$value." AND";
break;
case 'max-duration':
if((intval($value)) >= 45) {
$min = intval($value)-30;
$query .= " duration <=".$value." AND duration >=".$min." AND";
} else { //if duration < 45
$query .= " duration <=".$value." AND";
}//end else
break;
}
You had to add a ) after
if((intval($value)
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 5 years ago.
Improve this question
I have table on mysql like this:
insert into `city` (`ID`,`NAMES`) values
(1,'Białystok, Radom, Sandomierz'),
(2,'Olsztyn, Warka, Grójec, Poznań'),
(3,'Białowieża, Zakopane, Wrocław, Gdańsk, Sopot'),
(4,'Augustów, Kielce')
After select I would like to see a view, like:
A B C D.........Z - links to section
A
Augustów
B
Białystok
Białowieża
G
Gdańsk
Grójec
How do this in PHP?
I have tried with this PHP code.
You may help this.
$arr = array("Sky","Stackoverflow","Cloud", "Birds","Banana", "Rainbow", "Moon","Apple","Aeroplane","Ambulance");
sort($arr);
$last = '';
$concate = "<ul>";
foreach ($arr as $key => $val)
{
$first = substr($val,0,1);
if($first == $last)
{
$concate .= '<li>'.$val.'</li>';
}
else
{
$concate .= $first;
$concate .= '<li>'.$val.'</li>';
}
$last = $first;
}
$concate .= "</ul>";
echo $concate;
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I want to loop through $i which starts from 790000000 and echo every 100000 up to 799999999:
790000000
790100000
790200000
790300000
790400000
...
I tried this code but it didn't work:
for ($i=790000000; $i<=800000000; $i+100000) {
echo $i . '<br>';
}
For loop wrong code, you are missing actual code update as $i+100000 does not update variable. Use $i += 100000 instead.
// Here is problem in your code
for ($i=790000000; $i<=800000000; $i += 100000) {
echo $i . '<br>';
}
Update your loop using += instead of i.
Only using + will not increment your $i variable value.
for ($i=790000000; $i<=800000000; $i+=100000) {
echo $i . '<br>';
}
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Have a weird issue, break doesn't break while loop and keep rotating. Logically it should break the cycle and I set some output
while ($c++ != 5)
{
// here is curl request, doesn't relevant so I have removed it
preg_match("!<.*?>(\S*)[^<>]*?{$to}<!", $resp, $result) ;
//
echo 'cnt = ' .count($result).'<br>';
if(!count($result))
{
$amount = 0;
echo 'sleep called';
sleep(4);
exit;
continue;
}
else
{
$amount = trim(#$result[1]);
$amount = round($amount + $amount * $exchange_ratio, $precision);
echo 'break happen<br>';
break;
}
}
so output is
cnt = 2
break happen
cnt = 0
sleep called
So it skipped break and keep rotating. How so?
EDIT
works fine on my localhost so issue probably with php version?
You must be running this code multiple times: is there a second call to this script, or a second loop around this part? Look at my test code: it clearly breaks after the break:
$ cat tmp.php
<?php
$c = 0;
while ($c++ != 5)
{
if(false) //just emulating you
{
$amount = 0;
echo 'sleep called';
sleep(4);
exit;
continue; //this will never be called by the way
}
else
{
echo 'break happen<br>';
break; //this indeed breaks out of the while
}
}
$ php tmp.php
break happen<br>$
(the $ is the next prompt, on the same line as I did not put in a newline :) )
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Having trouble locating the problem in this elseif
Code checker suggests an extra } however I cannot find it
if (get_field('job_salary') == "Competitive") {
echo "Competitive";
} elseif (get_field('job_salary') == "P.A") {
echo the_field('job_salary_singular');
} elseif (get_field('job_salary') == "P.A Range"){
echo "£" . the_field('job_salary_range_start') . " - " . thefield('job_salary_range_end');
} elseif (get_field('job_salary') == "Per Day"){
echo "£" . thefield('job_salary_day_rate') == " per day";
} elseif (get_field('job_salary') == "Per Day Range"){
echo "£" . the_field('job_salary_day_range_start') . " - " . the_field('job_salary_day_range_end') . " pd"
}
There is no semi-colon on your last 'echo' line. :) Therefore, the last } appears to be extra.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
<?php
$sql_apr = " SELECT SUM ( meter * minute ) FROM table";
$rs_apr = #mysql_query($sql_apr);
$total_apr = #mysql_fetch_array($rs_apr);
$try4 = $total_apr['SUM(meter * minute'];
while ($rs_t = #mysql_fetch_array($rs_t)) {
$minute = '';
$sql_t = "SELECT DATEDIFF(MINUTE,'e_date e_time','s_date s_time') AS minute";
$rs_t = #mysql_query($sql_t);
$minute = $rs_t['minute'];
}
?>
You are looking at the wrong result:
$rs_t=#mysql_query($sql_t);
$minute = $total_t['minute'];
should be
$rs_t=#mysql_query($sql_t);
$minute = $rs_t['minute'];
// ^ use the rs_t result, not the result from the first query
You are also result the variable that you are looping on. I highly doubt that this while loop will ever end. You are looping on the result from $rs_t and then you reassign $rs_t inside the loop.
why don't you do this in correct order
$query = "SELECT DATEDIFF(MINUTE,'e_date e_time','s_date s_time') AS minute";
$results = #mysql_query($query);
$row = #mysql_fetch_array($results);
$minute = $row['minute'];
print_r($minute);
$sql_apr = " SELECT SUM ( meter * " . $minute . " ) AS my_sum FROM table";
$rs_apr = #mysql_query($sql_apr);
$total_apr = #mysql_fetch_array($rs_apr);
$try4 = $total_apr['my_sum'];
You try to get result (in while) before you run query.
edit:
$query = "SELECT TIMESTAMPDIFF(MINUTE,'s_date s_time','e_date e_time') AS minute";