当且仅当来自数据库的数据与特殊代码匹配时,我想重定向到另一个页面。在这里,我有两个文件名 index.php 和 load.php 。 load.php在index.php页面中加载
当检索到的数据与代码匹配时,index.php页面将重定向到另一个页面。
主要问题是“ load.php在load.php文件中使用标题('Location:https://qwezxc.com/'); 时不会加载。< b>“它只在删除位置标题后加载。
这是代码:
的index.php
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script>
<script>
setInterval(
function()
{
$('#content').load('load.php');
$("#content").animate({
scrollTop: $("#content")[0].scrollHeight}, 300);
}, 5000);
</script>
<style>
#content{
background-color:#00A1E0;
font-size:24px;
font-weight:bold;
padding-top:10px;
color:#fff;
height: 200px;
overflow: auto;
}
#content,h1{
text-align: center;
}
</style>
<title>Auto Load Page in Div using Jquery</title>
</head>
<body>
<h1>Auto Load Page in Div</h1>
<div id="content"> Please wait .. </div>
</body>
<html>
的 load.php
<?php
echo ' 5 seconds ..<br/>';
$connection = mysqli_connect("localhost","root","","bot") or die("Error " . mysqli_error($connection));
$user_array=array();
$main_array=array();
$sql_query = "SELECT * FROM `subscribe_user` WHERE catagory LIKE '%top%';";
$result = mysqli_query($connection,$sql_query);
while($row =mysqli_fetch_assoc($result))
{
if($row['catagory']=="otopo") {
// echo "U la la la ";
header('Location: https://qwezxc.com/');
} else {
echo $user_array['catagory']=$row['catagory'];
echo "<br>";
}
array_push($main_array,$user_array);
}
?>
答案 0 :(得分:0)
您对此声明的了解
if($row['catagory']=="otopo") {
因为该声明希望得到整个单词以检查您想要查看的单词的一部分,
就像我的例子一样,在我的数据库中有(穆罕默德A)作为元素。
$sql_query = "SELECT * FROM subscribe_user WHERE catagory LIKE '%moha%';";
输出是穆罕默德A否,(否)它的意思是输出不等于我搜索$row['catagory']!="Mohammed"
的整个单词
所以,我建议你使用mysqli_num_rows()
现在这是整个文件:)
$sql_query = "SELECT * FROM `subscribe_user` WHERE catagory LIKE '%top%';";
$result = mysqli_query($connection,$sql_query);
$numrows = mysqli_num_rows($result);
while($row = mysqli_fetch_assoc($result)){
echo $row['catagory'];// show you the element you have in database
if($numrows > 0){
echo " Yes";//print (Yes) if there is more than 1 element
//header('Location: https://qwezxc.com/');//i just remove it because i want to try, i dont want to get redirect.
}
array_push($main_array,$user_array);
}
或者你可以删除,如果它不重要
$sql_query = "SELECT * FROM `subscribe_user` WHERE catagory LIKE '%top%';";
$result = mysqli_query($connection,$sql_query);
$num = mysqli_num_rows($result);
if($num > 0){
echo " Yes";
//header('Location: https://qwezxc.com/');
}else{
echo 'No';
}
我希望我的回答可以帮助你:)
<强> EDITED 强>
很抱歉没有注意到您首先遇到来自JavaScript的重定向问题。
第二个问题是header("Location: site");
根据我的经验,它不适用于JavaScript。
因此,您必须使用<script>window.location='https://qwezxc.com/';</script>
代替header("Location: site");
这是最终代码。
if($numrows > 0){
echo "Redirecrting... <script>window.location='https://qwezxc.com/';</script>";
}