douyanjing0822 2012-12-29 21:29
浏览 29
已采纳

函数总是返回false [关闭]

I am working on a project that users apply for events. The pertinent code I have now is as follows:

      <? if(in_array($u_id, $app)){ ?>
          <td>Unapply:</td>
          <td><a href="event_unapply.php?event_id=<?=$e_id; ?>">Unapply</a></td>
      <? } else{ ?>
           <td>Apply:</td>
           <td><a href="event_apply.php?event_id=<?=$e_id; ?>">Apply!</a></td>
      <? }?>

Now if a user is applied, the print_r of the array looks like:

Array ( [0] => Array ( [id] => 3 [Userid] => 1 ) )

$u_id matches the [Userid] in the event but it always goes to the else statement.

I tried doing $app['0'] but then every time the user is not applied for an event, it returns a PHP error.

Does anyone have an idea to make it so it would work?

  • 写回答

1条回答 默认 最新

  • dregduc63699 2012-12-29 21:31
    关注

    Nvmd, had a tad of a brain fart but I got it working correctly by using:

          <? if($u_id == $app['0']['Userid']){ ?>
              <td>Unapply:</td>
              <td><a href="event_unapply.php?event_id=<?=$e_id; ?>">Unapply</a></td>
          <? } else{ ?>
               <td>Apply:</td>
               <td><a href="event_apply.php?event_id=<?=$e_id; ?>">Apply!</a></td>
          <? }?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请问有会的吗,用MATLAB做
  • ¥15 phython如何实现以下功能?查找同一用户名的消费金额合并—
  • ¥15 ARIMA模型时间序列预测用pathon解决
  • ¥15 孟德尔随机化怎样画共定位分析图
  • ¥18 模拟电路问题解答有偿速度
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序,怎么查看客户esp32板子上程序及烧录地址
  • ¥50 html2canvas超出滚动条不显示