我有一個while循環,並在列表中每一個顯示<li></li>
,有沒有辦法告訴PHP其他每個迴路應附和說:while循環,每個其他循環的語句?
<li style="background: #222;"></li>
,並在我的CSS我將有另一種顏色#111設置爲默認值,以便我的網站用戶可以輕鬆地確定他們正在查看哪一行數據?
我的請求代碼:
function user_details($dbc, $q, $details) {
echo '<ul class="userlist">';
while ($user = $q -> fetch(PDO::FETCH_ASSOC)) {
echo '<li><span>(' . $user['id'] . ')</span> <a href="/viewaccount?id=' . $user['id'] . '">' . $user['username'] . '</a><div>';
if ($user['admin'] > 0) {
echo '<img class="Tooltip" src="gameimages/admin.png" width="18" height="18" title="Is game admin." alt="" />';
}
echo '<img class="Tooltip" src="gameimages/' . $user['gender'] . '.png" width="18" height="18" title="' . $user['gender'] . '" alt="" />';
$last_active = time() - $user['last_active'];
$seconds = $last_active % 60;
$minutes = ($last_active - $seconds)/60;
if ($minutes <= 4) {
echo '<img class="Tooltip" src="gameimages/active5.png" width="18" height="18" alt="" title="';
if ($seconds == 0) {
echo 'Last active ' . $minutes . ' minutes ago." />';
}
elseif ($minutes == 0) {
echo 'Last active ' . $seconds . ' seconds ago." />';
}
else {
echo 'Last active ' . $minutes . ' minutes and ' . $seconds . ' seconds ago." />';
}
}
elseif ($minutes <= 9) {
echo '<img class="Tooltip" src="gameimages/active10.png" width="18" height="18" alt="" title="';
if ($seconds == 0) {
echo '<strong>Last active ' . $minutes . ' minutes ago." />';
}
else {
echo 'Last active ' . $minutes . ' minutes and ' . $seconds . ' seconds ago." />';
}
}
elseif ($minutes <= 14) {
echo '<img class="Tooltip" src="gameimages/active15.png" width="18" height="18" alt="" title="';
if ($seconds == 0) {
echo 'Last active ' . $minutes . ' minutes ago." />';
}
else {
echo 'Last active ' . $minutes . ' minutes and ' . $seconds . ' seconds ago." />';
}
}
if ($user['subscriber'] > 0) {
echo '<img class="Tooltip" src="gameimages/subscriber.png" width="18" height="18" title="Subscriber with ' . $user['subscriber'] . ' days left." alt="" />';
}
echo '</div>';
echo '<a href="#"><img class="Tooltip" src="gameimages/sendmessage.png" width="18" height="18" title="Send ' . $user['username'] . ' a message." alt="" /></a>';
$is_friend = $dbc -> prepare("SELECT id, friend_id FROM friends WHERE id = ? && friend_id = ?");
$is_friend -> execute(array($details['id'], $user['id']));
$friend_request = $dbc -> prepare("SELECT id, id_to FROM friend_requests WHERE id = ? || id_to = ? && id = ? || id_to = ?");
$friend_request -> execute(array($user['id'], $details['id'], $details['id'], $user['id']));
if ($is_friend -> rowCount() > 0) {
echo '<img class="Tooltip" src="gameimages/isfriend.png" width="18" height="18" title="Friend request sent to ' . $user['username'] . '." alt="" />';
}
elseif ($friend_request -> rowCount() > 0) {
echo '<img class="Tooltip" src="gameimages/friendrequested.png" width="18" height="18" title="There is a request pending to be friends with ' . $user['username'] . '." alt="" />';
}
else {
echo '<a href="/confirm?action=addfriend&id=' . $user['id'] . '"><img class="Tooltip" src="gameimages/addfriend.png" width="18" height="18" title="Add ' . $user['username'] . ' as a friend." alt="" /></a></li>';
}
}
echo '</ul>';
}
它是在最小的功能,基本上互相行應該有另一個背景:)
我已經讀了兩遍 - 這個問題到底是什麼? –
你能告訴我們你的while循環嗎? – TJHeuvel
現在編輯它? – carlgcode