-6

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?

xxx
  • 1,153
  • 1
  • 11
  • 23
wildy
  • 1
  • 3
  • 3
    Lets be frank, this makes no sense to anyone but you does it ? – adeneo Dec 07 '15 at 16:20
  • `return` stops the function. `If called from within a function, the return statement immediately ends execution of the current function` -http://php.net/manual/en/function.return.php – chris85 Dec 07 '15 at 16:20
  • 1
    Please [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). [These extensions](http://php.net/manual/en/migration70.removed-exts-sapis.php) have been removed in PHP 7. Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) statements for [PDO](http://php.net/manual/en/pdo.prepared-statements.php) and [MySQLi](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) and consider using PDO, [it's really pretty easy](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard Dec 07 '15 at 16:21
  • 1
    [Your script is at risk for SQL Injection Attacks.](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) – Jay Blanchard Dec 07 '15 at 16:21
  • 1
    @JayBlanchard - PHP7, Due to launch some time in 2043 with the current pace (and yes, I know they skipped a few versions and launched a few days ago, it still sucks) – adeneo Dec 07 '15 at 16:23
  • @adeneo what on earth are you talking about? What sucks about the PHP 7 release? – Mark Amery Dec 07 '15 at 18:57

1 Answers1

1

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.

Niranjan N Raju
  • 12,047
  • 4
  • 22
  • 41