set value from sql() methond
set value from sql() methond
aristidispap
Posts: 4Questions: 4Answers: 0
i have this code
Field::inst( 'row_array' )->setValue( function () use ($db) {
$result = $db->sql('SELECT min(usb_rw.row_array) + 1 from usb_rw ');
$row = $result->fetch();
24 return $row [0];
})
i want to get a number from query < SELECT min(usb_rw.row_array) + 1 from usb_rw >
but the error is << Undefined offset: 0 in C:\wamp\www\USB READ\Editor-PHP-1.4.2\php\table.mem_symbols.php on line 24
How can i fix it?
Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
This discussion has been closed.
Answers
Have you checked the value of $row after $row = $result->fetch(); ?
Agreed - it sounds like there is no record being returned by the SQL server.
It could also be that it is returning only a column name so you would need to access it as an associative array. Using
print_r( $row);
and viewing the result in your browser's network tools would show what the data actually is.Allan