【发布时间】:2015-06-28 02:20:59
【问题描述】:
当我将一个参数从我的数据库传递给一个 javascript 函数时,我遇到了这个问题,我得到一个递减的数字,而且它与我期望显示的数字不同
我传递的格式是(####-####)
<?php
include 'connect.php';
session_start();
if(isset($_SESSION['name']) && $_SESSION['name'] != "")
{
?>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="css/main.css" />
<script src="js/main.js"></script>
</head>
<body>
<div id="TopContainer">
<div id="user">
<div id="msg">
<a href="logout.php">
<button type="button" style="width:60px;float:right;padding:5px;" class="submit">
Log Out
</button>
</a>
<span style="float:left;">
Hello, <?php echo $_SESSION['name']; ?>
</span>
</div>
</div>
<form action="main.php" method="POST" id="form" name="form">
<div id="box" name="box" style="-webkit-transition:1s;overflow:hidden;">
<label class="boxes"><input type="checkbox" id="All" name="All" onclick="checkAll()" /><span>All</span></label>
<label class="boxes"><input type="checkbox" id="books" name="books" onclick="rmOthers(1)"/><span>Books</span></label>
<label class="boxes"><input type="checkbox" id="journals" name="journals" onclick="rmOthers(2)"/><span>Journals</span></label>
<label class="boxes"><input type="checkbox" id="guidelines" name="guidelines" onclick="rmOthers(3)"/><span>Guidelines</span></label>
<label class="boxes"><input type="checkbox" id="pe" name="pe" onclick="rmOthers(4)"/><span>Patient Education</span></label>
</div>
<button type="button" class="submit" id="hide" style="padding:15px 20px;" onclick="hideBoxes()">+</button><input type="search" name="search" class="inputs" placeholder="Search Articles" value="<?php echo isset($_POST['search']) ? $_POST['search'] : ""; ?>" /><button type="submit" name="submit" class="submit" >Search</button><br />
<div id="sq">
<select id="sqType" style="width:5%;">
<option class="ar">And</option>
<option class="ar">Or</option>
</select>
<input type="search" class="inputs" placeholder="Filter Results" name="filter" style="width:70%;" value='<?php echo (isset($_POST['filter']) ? $_POST['filter'] : ''); ?>' />
<button type='submit' id="fil" name='btn_filter' class="submit" style="-webkit-transform:translateX(-5px) translateY(-3px); width:7%;" >Filter</button>
</div>
</form>
</div>
<br /><br /><br /><br /><br /><br /><br /><br />
<div id="BottomContainer">
<?php
if((isset($_POST['submit'])) || (isset($_POST['btn_filter'])))
{
$search = mysqli_real_escape_string($con,$_POST['search']);
$sql = (strcmp($search, "") == true ? "SELECT * FROM tbl_additionals JOIN tbl_general_info WHERE tbl_general_info.reference_number LIKE '%$search%' OR tbl_general_info.title LIKE '%$search%' OR tbl_general_info.author LIKE '%$search%' OR tbl_additionals.abstract LIKE '%$search%'" : "SELECT * FROM tbl_additionals JOIN tbl_general_info WHERE tbl_general_info.reference_number LIKE '%$search%' OR tbl_general_info.title LIKE '%$search%' OR tbl_general_info.author LIKE '%$search%' OR tbl_additionals.abstract LIKE '%$search%' LIMIT 30");
$query = mysqli_query($con, $sql);
if(mysqli_num_rows($query) != 0)
{
while($run = mysqli_fetch_assoc($query))
{
$reference = (string)$run['reference_number'];
$title = (strlen($run['title']) > 121) ? substr($run['title'], 0, strpos(wordwrap($run['title'], 121), "\n")) . '...' : $run['title'];
echo '<div class="SearchResults">';
echo " <span class='top'>";
echo " <a>";
echo " <h3>". strtoupper($title) ."</h3>";
echo " </a>";
echo " <br />";
echo " <h5 class='sub'>";
echo $run['reference_number'];
echo " Authors :<a class='authors'>Dr.Michael Ramsay</a><a class='authors'>Dr.Lars Benitez</a><a class='authors'>Dr.Kevin John Pascual</a><br><br>";
echo " </h5>";
echo " </span>";
echo " <span class='bottom'>";
echo " <span class='bottomLeft'>";
echo ($run['abstract'] != "" ? " <a class='options' onclick='showOverlay(".$reference.")'>Abstract</a><span style='margin:0px 5px;'>|</span>" : "" );
echo " <a target='_blank' href='view.php?filename=NKTI Proceedings vol. 1 no. 1 Feb. 1996' class='options'>";
echo " Full Article";
echo " </a>";
echo " </span>";
echo " <div class='overlay' id='". $run['reference_number'] ."' onclick='hideOverlay(this, event)'> ";
echo " <iframe class='abstract' src='abstract.php?id=".$run['reference_number']."' style='padding:0px;' scrolling='no'>";
echo " </iframe>";
echo " </div>";
echo " <span class='bottomRight'>";
echo " <p class='label'>NKTI Proceedings volume 1, January - April 2015 @ Pg. 1-15</p>";
echo " </span>";
echo " </span>";
echo " <br style='clear:both;'/>";
echo "</div>";
}
}
}
?>
</div>
</body>
</html>
<?php
}
else
{
echo "<script>alert('Please Login To Continue');window.open('index.php','_self');</script>";
}
?>
这是我的 javascript 代码
function showOverlay(id)
{
alert(id);
document.getElementById(id).style['display'] = "block";
document.getElementById(id).style['opacity'] = "1";
}
我刚刚发出警告声明,这样我就可以看到程序在 javascript 上传递了什么,这就是发生的事情
我点击了显示的第一个摘要链接,如您所见,我回显了应该在作者之前传递的内容,然后传递的内容在警报框上
我似乎找不到问题是我的 mysql 语句还是 javascript 代码或 php 代码
【问题讨论】:
-
作为旁注,您可以使用 console.log(variable here) 查看值是什么
-
什么是 console.log?以及它将如何帮助我调试我的程序?
-
您没有显示将 PHP 值写入客户端的代码。
-
@YesSir 你能从搜索(?)结果页面中发布一些处理过的 HTML 吗?这将有助于确定错误发生的位置。似乎 JS 或 PHP 在某处从 1999 中减去 0001,这将导致您的新四位数
id数字。 -
当然,我更新了我的问题并粘贴了我的整个源代码以供搜索
标签: javascript php html mysql