php的“功能”不起作用

时间:2017-04-04 10:02:24

标签: php html sql function

我已经完成了这段代码:

$connection = mysqli_connect($IP_SQL, $ID_SQL, $PASS_SQL) or die('Could not connect:' . mysqli_error());  
  mysqli_select_db($connection, $DB_FORM) or die('non connette :D'); 
  $query = "SELECT marchio FROM Marchi ORDER BY marchio ASC";
  $result = mysqli_query($connection, $query) or die('non legge il DB_FORM');

  // conto il numero di occorrenze trovate nel db
  $numrows = mysqli_num_rows($result);

  // avvio un ciclo for che si ripete per il numero di occorrenze trovate
    for ($x = 0; $x < $numrows; $x++)
    {  
      // recupero il contenuto di ogni record rovato
      $resrow = mysqli_fetch_row($result);
      $marca = $resrow[0];
      echo '<option value="' . $marca . '">' . $marca . '</option>';  
    }
  // chiudo la connessione
  mysqli_close($connection);

然后我试图做一个功能

function datalist($table, $value){
$connection = mysqli_connect($IP_SQL, $ID_SQL, $PASS_SQL) or die('Could not connect:' . mysqli_error());  
  mysqli_select_db($connection, $DB_FORM) or die('non connette :D'); 
  $query = "SELECT `$value` FROM `$table` ORDER BY `$value` ASC";
  $result = mysqli_query($connection, $query) or die('non legge il DB_FORM');

  [...SAME AS UP...]
mysqli_close($connection);
}

但是当我尝试用datalist("Marchi", "marchio");调用它时,他没有连接SQL并显示数据,我冤枉了什么? 所有的代码都保存在同一个文件.php中,在工作之前和之后,idk如何解决它

0 个答案:

没有答案