douyueju2912 2014-04-09 22:27
浏览 40
已采纳

PHP不显示函数数据

I am trying to make a call to the database so it displays a list with certain information, but for some reason it isn't working even though the same code was working before with other database.

It displays the following error:

Fatal error: Call to undefined function displayLabs() in C:\wamp\www\MyFirstProyect\labs.php on line 258

This is the code:

 function getLabs(){
$query = "SELECT bk.idlab , bk.capacidad, bk.carrera, bk.ubicacion FROM labs as bk";

$result = do_query($query);

   return $result;
 }

 function displayLabs(){

$labs = getLabs();

while($row = mysql_fetch_assoc($labs)){
echo '<ul>' .
        '<li>"Nombre: "' . $row['idlab'] . '</li>' .
        '<li>"Capacidad: "' . $row['capacidad'] . '</li>' .
        '<li>"Carrera: "' . $row['carrera'] . '</li>' .
        '<li>"Ubicación: "' . $row['ubicacion'] . '</li>' .
     '</ul>';
    }

}

Just in case this is html:

    <div class="popUp1" id="popUpCorrecto1">
        <div class="estiloPopUp">
          <span>Información de laboratorio</span>
          <span value="Cerrar" id="btnCerrar">x</span>
        </div>
            <?php displayLabs() ?>

          <input type = "button" value = "Eliminar" id = "btnEliminar" onclick="window.location='labEliminado.html';" />
          <input type = "button" value = "Modificar" id = "btnModificar"      onclick="window.location='modificarLab.html';" />

        </div>  

Any help would be very much appreciated.

EDIT: Something Mr.Fred told me gave me an idea and it worked, now it is displaying the information, BUT not of just one "Lab" But all of them XD So with the 4 test labs I entered into the database it is making 5 lists.

I guess I need to figure some kind of filter.

  • 写回答

1条回答 默认 最新

  • douqi2804 2014-04-09 22:58
    关注

    As per OP's request, comment to answer. (to close the question)

    "Just in case this is html:" --- what's that file extension set as, .php? .html?

    I see two file references labEliminado.html and modificarLab.html if you're trying to run PHP in those, it won't work, unless you've instructed Apache to treat .html as PHP.

    Also, if your displayLabs() is inside another file besides your first body of code, then that's the reason why.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 ansys fluent计算闪退
  • ¥15 有关wireshark抓包的问题
  • ¥15 需要写计算过程,不要写代码,求解答,数据都在图上
  • ¥15 向数据表用newid方式插入GUID问题
  • ¥15 multisim电路设计
  • ¥20 用keil,写代码解决两个问题,用库函数
  • ¥50 ID中开关量采样信号通道、以及程序流程的设计
  • ¥15 U-Mamba/nnunetv2固定随机数种子
  • ¥15 vba使用jmail发送邮件正文里面怎么加图片
  • ¥15 vb6.0如何向数据库中添加自动生成的字段数据。