Page 1 of 1
how do i force a variable to be int
Posted: Wed Jun 14, 2006 1:35 pm
by pedrotuga
Code: Select all
int $half=mysql_num_rows($result)/2;
can anybody help me please... i want to use the $half so i can know when am in the midle of the output so i can insert another line on a html table...
the above code generates this error...
Code: Select all
Parse error: parse error, unexpected T_VARIABLE in...
the manual doesnt say so much about variable types
thx in advance
Posted: Wed Jun 14, 2006 1:42 pm
by Roja
You were VERY close.
Code: Select all
(int) $half=mysql_num_rows($result)/2;
(int)
casts the variable to an int.
Re: how do i force a variable to be int
Posted: Wed Jun 14, 2006 1:43 pm
by bdlang
pedrotuga wrote:
the manual doesnt say so much about variable types
PHP Manual:
Types
PHP Manual:
Integers
PHP Manual:
Type Juggling
You can cast type using (int), e.g.
Code: Select all
$half=mysql_num_rows($result);
$output= (int) $half / 2;
Posted: Wed Jun 14, 2006 1:56 pm
by pedrotuga
thank you everybody
i still have some C habits
Posted: Wed Jun 14, 2006 5:21 pm
by bokehman
What are you going to do if mysql reurns an odd number?