gpt4 book ai didi

php - 我的代码只向我显示第一个结果并带来另一个空值

转载 作者:行者123 更新时间:2023-11-29 00:10:19 26 4
gpt4 key购买 nike

<分区>

我有一个问题...

我有一个名为 event attends 的表,我们将它们记录到带有 ID 的表中。事件 ID 和用户 ID。

当我想列出参加的事件时,我需要从用户表中获取用户并获取姓名、电话和电子邮件。

但是当我编写代码时,ID 结果为真。但是当我将第二个 SQL 放入循环中时,代码只为我带来了第一条记录并带来了另一个空值。

谁能帮帮我...

我是 PHP 的初学者,所以我有错误:(

// START TABLE CONNECTIONS //
$result_event_attends = mysql_query("SELECT * FROM event_attends where course_id='" .$val_selected_event_id. "' ORDER BY idcourse_attends DESC");
$total_results_event_attends = mysql_num_rows($result_event_attends);
$total_pages_event_attends = ceil($total_results_event_attends / $per_page);
// END TABLE CONNECTIONS //


// PAGINATION START //
// check if the 'page' variable is set in the URL (ex: view-paginated.php?page=1)
if (isset($_GET['page']) && is_numeric($_GET['page']))
{
$show_page = $_GET['page'];

// make sure the $show_page value is valid
if ($show_page > 0 && $show_page <= $total_pages)
{
$start = ($show_page -1) * $per_page;
$end = $start + $per_page;
}
else
{
// error - show first set of results
$start = 0;
$end = $per_page;
}
}
else
{
// if page isn't set, show first set of results
$start = 0;
$end = $per_page;
}

// PAGINATION END //

// START TO GET RESUTLS //

// CHECK IF THE RESULTS 0 AND GIVE ERROR //

$num_rows_event_attends = mysql_num_rows($result_event_attends);

if($num_rows_event_attends == 0)
{
echo "<div class='alert alert-error'>";
echo "<center><strong>Oh snap!</strong> There are no records. Do you want add records?</center>";
echo "</div>";
}

// END CHECK IF THE RESULTS 0 AND GIVE ERROR //

else {
echo "<BR><table class='table table-striped table-bordered table-condensed'>";

echo "<tr>";
echo '<th style="vertical-align:middle"><center>Attender Name</center></td>';
echo '<th style="vertical-align:middle"><center>Registration No</center></td>';
echo '<th colspan="4"><center>Actions</center></td>';
echo "</tr>";

for ($i = $start; $i < $end; $i++)
{
// make sure that PHP doesn't try to show results that don't exist
$user_id = mysql_result($result_event_attends, $i, 'user_id');
$user_info = mysql_query("SELECT * FROM users where userID='" .$user_id. "'");
$total_results_user_info = mysql_num_rows($user_info);

if ($i == $total_results_event_attends) { break; }

// echo out the contents of each row into a table
echo "<tr>";
echo '<td style="vertical-align:middle">' . mysql_result($user_info, $i, 'name') . '</td>';
echo '<td style="vertical-align:middle">' . mysql_result($result_event_attends, $i, 'company_id') . '</td>';
echo '<td width="40px"><center><a href="events.php?action=delete_conf&id=' . mysql_result($result, $i, 'EV_ID') . '" class="btn btn-mini btn-info" title="Attendes List"><i class="icon-group"></i></a></center></td>';
echo '<td width="40px"><center><a href="events.php?action=delete_conf&id=' . mysql_result($result, $i, 'EV_ID') . '" class="btn btn-mini btn-info" title="Delete"><i class="icon-trash-o"></i></a></center></td>';
echo '<td width="40px"><center><a href="events.php?action=edit&id=' . mysql_result($result, $i, 'EV_ID') . '" class="btn btn-mini btn-info" title="Edit"><i class="icon-edit"></i></a></center></td>';
echo '<td width="40px"><center><a href="events.php?action=details&id=' . mysql_result($result, $i, 'EV_ID') . '" class="btn btn-mini btn-info" title="Details"><i class="icon-bars"></i></a></center></td>';
echo "</tr>";
}

// close table>
echo "</table>";

// display pagination
echo "<br />";
echo "<div class='pagination pagination-centered'>";
echo "<ul> ";
for ($i = 1; $i <= $total_pages; $i++)
{
echo "<li><a href='?page=$i'>$i</a></li> ";
}
echo "</ul> ";
echo "</div> ";
}

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com