Page 1 of 1

strange mysql_fetch_row behaviour ??

Posted: Wed Dec 10, 2008 5:43 am
by stoodent
hey,
ill post a few lines of code, everything before works fine, its just arithmetic with the result of a call to mysql_fetch_row that is strange:

Code: Select all

 
function test($link_from) {
     $r = mysql_query("SELECT COUNT(*) FROM cms WHERE is_active = 1 AND link_from = " .$link_from);
     $rows = mysql_fetch_row($r);
     die($rows[0]);
     die($rows[0]+1);
}
 
test(1);
 
of course the database connection etc. is set up and working. now the output is as follows, when the 2 die() statements are uncommented of course only the first one is executed, and the output is 6. when i uncomment the first line, there is no output. seemingly $rows[0] has a value but you cant perform arithmetic on it.

ive tried all sorts of variations, typecasting to (int), return the variable and then adding a value, putting $rows[0] in its own variable, etc. ive changed the sql query to count(id), even to "select *" and then used mysql_num_rows($r) and the same result. whats going on, the query works fine, the output is as expected according to the database data, but i cant alter the result??
im baffled...