Mysql column name not found

Mysql column name not found

shaviimanshaviiman Posts: 1Questions: 1Answers: 0
edited October 2023 in Free community support

Hi, everyone.

I am using Editor-PHP-2.0.10 library.

My SQL table has these columns

  • id_presupuesto (as primary key)
  • id_razon
  • razon (can be NULL)
  • fecha
  • moneda
  • monto
  • validez
  • estatus

PHP

    $data = Editor::inst( $db, 'presupuestos' )
            ->fields(
                Field::inst( 'presupuestos.id_presupuesto'),
                Field::inst( 'presupuestos.fecha' )->getFormatter( Format::dateSqlToFormat( 'Y-m-d' ))->setFormatter( Format::dateFormatToSql('Y-m-d' ) ),        
                Field::inst( 'presupuestos.validez' ),
                Field::inst( 'IFNULL(razonesSociales.razon,presupuestos.razon)', 'razonesSociales.razon'),
                Field::inst( 'presupuestos.moneda' ),
                Field::inst( 'presupuestos.monto' ),
                Field::inst( 'presupuestos.estatus' )
            )    
            ->debug(true)
            ->leftJoin( 'razonesSociales', 'razonesSociales.id_razon', '=', 'presupuestos.id_razon' )               
            ->process( $_POST )
            ->json();

JS DATATABLE INIT

columns: [
                { data: "presupuestos.id_presupuesto" },
                { data: "presupuestos.fecha" },
                { data: "presupuestos.validez" },
                { data: "razonesSociales.razon" },
                { data: "presupuestos.moneda" },
                { data: "presupuestos.monto" },         
                { data: "presupuestos.estatus" }
            ],

HTML TABLE

            <table id="tabla_dt" class="table table-sm table-striped table-bordered text-nowrap" style="width:100%">
                <thead>
                    <tr>
                        <th>No.</th>
                        <th>Fecha</th>
                        <th>Valido</th>                 
                        <th>Cliente</th>
                        <th>Moneda</th>
                        <th>Subtotal</th>
                        <th>Estatus</th>                                
                    </tr>
                </thead>
                <tbody>

                </tbody>
                <tfoot>             
                    <tr>
                        <th colspan="5" style="text-align:right">Total Pagina</th>
                        <th colspan="2" class="st_pag_usd"></th>

                    </tr>       
                </tfoot>
            </table>

ERROR ALERT

DataTables warning: table id=tabla_dt - An SQL error occurred: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'presupuestos.id' in 'field list'

WHY THIS IS HAPPENING?

I have not declared the presupuestos.id column anywhere because it does not really exist, the column with primary key is presupuestos.id_presupuesto

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,083Questions: 26Answers: 4,908
    Answer ✓

    See if the Editor Primary Key docs answers your question. Looks like you need to add a third parameter to the constructor to use the id_presupuesto ID as the primary key.

    Kevin

  • allanallan Posts: 62,992Questions: 1Answers: 10,367 Site admin

    You should probably also use:

     Field::inst( 'presupuestos.id_presupuesto')->set(false)
    

    assuming that the id is auto-generated by the database. You don't want someone changing a row's id!

    Allan

Sign In or Register to comment.