当我将数据库中的参数传递给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上传递了什么&#39 ps
我点击了第一个出现的抽象链接,你可以看到我回应了应该在作者之前传递然后传递的内容是在警报框中
我似乎无法发现这里的错误是我的mysql语句或javascript代码还是php代码
答案 0 :(得分:1)
将ID添加到Abstract链接并将showOverlay(".$reference.")
更改为onclick='showOverlay(this.dataset.articlenum)'
请参阅下面的PHP行:
echo ($run['abstract'] != "" ? "<a class='options' data-articlenum='" . $reference . "' onclick='showOverlay(this.dataset.articlenum)'>Abstract</a><span style='margin:0px 5px;'>|</span>" : "" );