Search code examples
javascriptphpdatatable

How do I return more than one entry from the database when using SSP


Hi I used ssp class for datatable.

function prod($a){
    $query= mysql_query("SELECT name FROM products WHERE sipid = '$a'");
    while($row = mysql_fetch_array($query)){
        return $row[name];
    }
}

Ssp.class.php

array(
  'db'        => 'id',
  'dt'        => 5,
  'formatter' => function( $d, $row ) {
     return prod($d);
  }
)

I have two rows in database but this it only shows one row?


Solution

  • No statements will be executed after return

    you are returning inside whlie

    while($row = mysql_fetch_array($query)){
       return $row[name];// this is wrong
    }
    

    Change it to

    $name = array();
    while($row = mysql_fetch_array($query)){
       $name[] = $row[name];// assign to array
    }
    return $name;//   <--- return here.
    

    Also switch to mysqli_* or PDO as mysql_* is deprecated.