set value from sql() methond

set value from sql() methond

aristidispaparistidispap Posts: 4Questions: 4Answers: 0
edited April 2017 in Editor

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.

Answers

  • tangerinetangerine Posts: 3,342Questions: 35Answers: 394

    Have you checked the value of $row after $row = $result->fetch(); ?

  • allanallan Posts: 61,452Questions: 1Answers: 10,055 Site admin

    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

This discussion has been closed.