0

look , i have create this code at php page called "func_selects.php".

<?php 
require('functions.php');
impressoras();
$result = impressoras();


function call(){
            
$imp_select = "";
foreach( $result as $imp){
$imp_select .= '<option value="'.$imp['nome'].'">'.$imp['nome'].'</option>';

} 
return $imp_select;

 }


 ?>

remember that result came from a another page called "functions.php" that run a PDO Query that return in array .

But for example , how u can see , my code above only create some options .

i wanna create a another page , for example called "index.php" where i'll execute that function.

for example

"f0.php"

<?php
 require('func_selects.php');
 call();
 $imp_select = call();

 ?>

<html>
<body>
<script type="text/javascript">
call();
</script>
<select name="kakaka" class="form-control"><option 
 value="2">sdsdsds</option><option value="talvez"><?php echo $imp_select ?>
 </option></select>
 </body>
</html>

but dont return nothing , someone could help me ?

Getting these errors

Notice: Undefined variable: result in /var/www/tkclientespdo/func_selects.php on line 10

Warning: Invalid argument supplied for foreach() in /var/www/tkclientespdo/func_selects.php on line 10

Community
  • 1
  • 1
Joe Doe
  • 57
  • 10
  • 1
    so where did you include your functions.php file? – Harpreet Singh Jul 11 '17 at 18:47
  • Have you defined `$result` somewhere before looping it? Enable error-reporting `error_reporting(E_ALL); ini_set('display_errors', 1);` and check your logs. – Qirel Jul 11 '17 at 18:50
  • i made some changes to undestand better. – Joe Doe Jul 11 '17 at 18:58
  • can you share the value of $result ? – Marcogomesr Jul 11 '17 at 19:00
  • returned this with display_erros : Notice: Undefined variable: result in /var/www/tkclientespdo/func_selects.php on line 10 Warning: Invalid argument supplied for foreach() in /var/www/tkclientespdo/func_selects.php on line 10 Notice: Undefined variable: result in /var/www/tkclientespdo/func_selects.php on line 10 Warning: Invalid argument supplied for foreach() in /var/www/tkclientespdo/func_selects.php on line 10 – Joe Doe Jul 11 '17 at 19:06
  • can you do a var_dump($result) ? – Marcogomesr Jul 11 '17 at 19:10
  • Invalid argument supplied for foreach() - this $imp['nome'] might not exist ... I still waiting to see what is $result, 3er time that I asked my code is working but I use plain html instead the foreach because you never show the content of $result – Marcogomesr Jul 11 '17 at 20:24

1 Answers1

0

Update your func_selects.php as below.

<?php 
  require('functions.php');

  function call(){
    $result = impressoras();
    $imp_select = "";
    foreach( $result as $imp){
      $imp_select .= '<option value="'.$imp['nome'].'">'.$imp['nome'].'</option>';
    } 
    return $imp_select;
  }
?>
Tomas
  • 514
  • 4
  • 13
  • 37