How to populate an editor with the result of a raw SQL query ?
How to populate an editor with the result of a raw SQL query ?
Hello !
First, sorry if i make mistakes, english is not my first language.
I'm having trouble using the result of a simple SQL query to populate an editor. According most of the discussions in the forum, I have to use the sql() method, then encode the result with "json_encode". Here is what I have :
$RAW_SQL_QUERY="SELECT * FROM `mytable`";
$r=$db ->sql($RAW_SQL_QUERY)->fetchAll();
$arr=array("data"=>$r,"options"=>'',"files"=>'');
echo json_encode(array("data" => $arr));
Then I create my editor :
Editor::inst( $db, $arr )
->fields(
Field::inst( 'id' )
->validator( Validate::notEmpty( ValidateOptions::inst()
->message( 'ID' )
) ),
Field::inst( 'nom' )
->validator( Validate::notEmpty( ValidateOptions::inst()
->message( 'Saisissez un nom correct pour ...' )
) ),
Field::inst( 'nom_abrg' )
->validator( Validate::notEmpty( ValidateOptions::inst()
->message( 'Saisissez un nom abrégé correct pour ...' )
) )
)
->process( $_POST )
->json();
**I'm pretty sure that I'm missing something and that it's not possible to do **
Editor::inst( $db, $arr )
where $arr is the result of my query after json encoding. I looked in the "Query.php" file and according this check :
public function table ( $table )
{
if ( $table === null ) {
return $this;
}
my table is a null type.
How can I do to display the result of my query inside of my editor ?
Thank you if you take from your time to help a noob like me.