-
student.php
<?php function findStudentRecord() { //Db connection $q1 = "select * from student where gender = 'F'"; $r1 = mysqli_query($dbc, $q1); $total_records = mysqli_num_rows($r1); $record = array(); if($total_records > 0) { while($row1 = mysqli_fetch_array($r1, MYSQLI_ASSOC)) { $record[] = $row1; } } else { //[HERE] } return $record; } $record = findStudentRecord(); //[HERE] ?>
I want to find female student record but there is no record from my database. How do I return 0 value from function and display "No record found" on my web page in [HERE] section?
PHP使用函数查找学生记录
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
2条回答 默认 最新
- douci2022 2015-11-10 12:12关注
if($total_records > 0)
add no else block so it will return an empty array now you can do something like this
$records = findStudentRecord(); if(count($records) === 0) { echo "No record found"; }
解决 无用评论 打赏 举报
悬赏问题
- ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
- ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
- ¥15 MATLAB中streamslice问题
- ¥15 如何在炒股软件中,爬到我想看的日k线
- ¥15 seatunnel 怎么配置Elasticsearch
- ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
- ¥15 (标签-MATLAB|关键词-多址)
- ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
- ¥500 52810做蓝牙接受端
- ¥15 基于PLC的三轴机械手程序