gpt4 book ai didi

PHP 找到多少行

转载 作者:太空宇宙 更新时间:2023-11-04 13:28:21 24 4
gpt4 key购买 nike

我有谷歌如何做到这一点,但我无法弄明白。所以这是我的代码:

<?php
session_start();

Function PrintAll() {
echo "<center>";
echo "Filmpje Nummer: ".$_SESSION['hits'];
echo "</center>";
$dbnaam = "a2943462_Pages";

$connection = mysql_connect($dbhost,$uname,$pass) or die ("niet gelukt om als $user te connecten met $host");
$result = mysql_select_db($dbnaam,$connection);

$sql = "SELECT * FROM PagesInfo WHERE ID=".$_SESSION['hits']; // sql select query
$result = mysql_query($sql, $connection);

while ($rij = mysql_fetch_array($result))
{
echo "<center>";
echo "<h3>" . $rij["Title"] . "</h3>";
echo $rij["Video"] . "<br/>";
echo "<p>" ."Posted By: " . $rij["Posted"] . "</p>";
echo "</center>";
}
}

function ShowButtons() {
echo "<html>
<head><title>COUNTER</title>
<link rel='stylesheet' type='text/css' href='style.css'/>
</head>
<body><center>
<form method='get'>
<input type='submit' name='Previous' value='<< Previous'/>
<input type='submit' name='Next' value='Next >>'/>
</form></center>
</body>
</html>";
}

function DisPre() {
echo "<html>
<head><title>COUNTER</title>
<link rel='stylesheet' type='text/css' href='style.css'/>
</head>
<body><center>
<form method='get'>
<input type='submit' name='Next' value='Next >>'/>
</form></center>
</body>
</html>";
}

if($_GET){
$pageShow = $_SESSION['hits'];
if(isset($_GET['Next'])){
$_SESSION['hits']++;
PrintAll();
}elseif(isset($_GET['Previous'])){
if ($_SESSION['hits'] < 1) {
echo "Cannot go further Back";
DisPre();
}else{
$_SESSION['hits']--;
PrintAll();
}
}
}

if(isset($_SESSION['hits'])){
if ($_SESSION['hits'] < 1){
disPre();
}else{
ShowButtons();
}
}else{
$_SESSION['hits']=1;
PrintAll();
}
?>

那么我必须如何以及在哪里添加执行此操作的代码:

如果它在表 PagesInfo 中没有找到任何行,那么它将回显:

echo "<center><img src='Sourceher' height='390px' width='640px' /></center>";

也许有人可以将代码放入我的代码中??非常感谢任何帮助。

最佳答案

更改此部分:

$sql = "SELECT * FROM PagesInfo WHERE ID=".$_SESSION['hits']; // sql select query 
$result = mysql_query($sql, $connection);

while ($rij = mysql_fetch_array($result))
{
echo "<center>";
echo "<h3>" . $rij["Title"] . "</h3>";
echo $rij["Video"] . "<br/>";
echo "<p>" ."Posted By: " . $rij["Posted"] . "</p>";
echo "</center>";
}

到:

$sql = "SELECT * FROM PagesInfo WHERE ID=".$_SESSION['hits']; // sql select query 
$result = mysql_query($sql, $connection);
if(mysql_num_rows($result) >0){
while ($rij = mysql_fetch_array($result))
{
echo "<center>";
echo "<h3>" . $rij["Title"] . "</h3>";
echo $rij["Video"] . "<br/>";
echo "<p>" ."Posted By: " . $rij["Posted"] . "</p>";
echo "</center>";
}
}
else {
echo "<center><img src='Sourceher' height='390px' width='640px' /></center>";

}

注意: mysql_* 已弃用,请使用 PDOmysqli_*

关于PHP 找到多少行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23550478/

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