Reputation: 75
i made a function that has an addition operation inside.. but when i call the function it shows an error
A non-numeric value encountered in...
my function is like this:
function get_pages($start){
echo '
<a href="page/'. $start + 1 .'">Next</a>
<a href="page/'. $start - 1 .'">Previous</a>
'
}
Calling function
get_pages($_GET['page']);
please can you give any solution for it?
Upvotes: 0
Views: 27
Reputation: 2295
You need to first check if the passed value is_numeric (number or numeric string) and then group the operation together before concatenating it to a string:
function get_pages($start){
if(is_numeric($start)){
echo '
<a href="page/'. ($start + 1) .'">Next</a>
<a href="page/'. ($start - 1) .'">Previous</a>
';
}
}
Upvotes: 1