gpt4 book ai didi

php - 具有由下拉菜单填充的分页的表格

转载 作者:行者123 更新时间:2023-11-30 00:49:08 25 4
gpt4 key购买 nike

我正在开发一个填充下拉菜单的页面,通过 SQL 查询来显示属于特定用户的车辆。一旦选择了车辆,它就会运行一个函数,打开一个表格,其中包含与该车辆相关的发票。问题是发票的数量相当大,我想使用分页来向前和向后移动它们。到目前为止,它可以很好地显示第一页。当我单击下一步时,它给我一个错误,说 undefined index q 并且它还丢失了我所有的 html 格式,很可能是因为转发到我的 getuser.php 页面。请看一下我的代码并告诉我我做错了什么,我已经尝试让它工作几个小时了

securepage.php 的源代码

<?php


include('config.inc');
include('func.inc.php');
include('db.inc.php');

$hostname = 'localhost'; // Your MySQL hostname. Usualy named as 'localhost', so you're NOT necessary to change this even this script has already online on the internet.
$dbname = 'ServiceHistoryDB'; // Your database name.
$username = 'root'; // Your database username.
$password = ''; // Your database password. If your database has no password, leave it empty.

// Let's connect to host
mysql_connect($hostname, $username, $password) or DIE('Connection to host is failed, perhaps the service is down!');
// Select the database
mysql_select_db($dbname) or DIE('Database name is not available!');


// This could be supplied by a user, for example

$username = $_SESSION['username'];

// Formulate Query
// This is the best way to perform an SQL query
// For more examples, see mysql_real_escape_string()
$query = sprintf("SELECT * FROM customers
WHERE username='%s'",
mysql_real_escape_string($username));

// Perform Query
$result = mysql_query($query);

// Check result
// This shows the actual query sent to MySQL, and the error. Useful for debugging.
if (!$result) {
$message = 'Invalid query: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $query;
die($message);
}

// Use result
// Attempting to print $result won't allow access to information in the resource
// One of the mysql result functions must be used
// See also mysql_result(), mysql_fetch_array(), mysql_fetch_row(), etc.
while ($row = mysql_fetch_assoc($result)) {
echo $row['CustNum'];

$custnum = $row['CustNum'];

}

// Free the resources associated with the result set
// This is done automatically at the end of the script
mysql_free_result($result);
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Arndt Automotive</title>
<style type="text/css">
body {
background-image: url(Background.png);
}
</style>
</head>

<body>
<table width="1050" border="0" align="center">
<tr align="center">
<td><img src="Banner.png" width="1050" height="275" alt="Banner" /></td>
</tr>
</table>
<table width="1200" height="638" border="0" align="center" background="backgroundmaybe2.png" " style="background-repeat: no-repeat; background- position: center;&gt;
&lt;tr align="center">
<td><table width="1090" height="638" border="0" align="center">
<tr align="left">
<td width="225"><table width="225" height="638" border="0" id="Left">
<tr>
<td align="center" valign="top" background="backgroundtable1.png"><p>&nbsp;</p>
<p><a href="index.php"><img src="Home.png" width="170" height="30" alt="Home" /></a></p>
<p><a href="AboutUs.php"><img src="About Us.png" width="170" height="30" alt="About Us" /></a></p>
<p><a href="Services.php"><img src="Services.png" width="170" height="30" alt="Services" /></a></p>
<p><a href="RecentWork.php"><img src="Recent Work.png" width="170" height="30" alt="Recent Work" /></a></p>
<p><a href="Login.php"><img src="My Account.png" width="170" height="30" alt="My Account" /></a></p>
<p><a href="ContactUs.php"><img src="Contact Us.png" width="170" height="30" alt="Contact Us" /></a></p>
<p><a href="Promotions.php"><img src="Promotions.png" width="170" height="30" alt="Promotions" /></a></p>
<p><a href="Location.php"><img src="Location.png" width="170" height="30" alt="Location" /></a></p>
<p><img src="Hours.png" width="170" height="150" alt="Hours" /></p></td>
</tr>
</table></td>
<td width="125">&nbsp;</td>
<td width="850"><table width="850" height="638" border="0" background="backgroundtable2.png" >

<tr>
<td align="center"><html>

<head>
<title></title>
<script>
function showUser(str)
{
if (str=="")
{
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","getuser.php?q="+str,true);
xmlhttp.send();
}
</script>

<body>
<?php echo $username?></b>
<?php echo $custnum?></b>




<form>
<select name="dropdown" onChange="showUser(this.value)">
<?php query() ;
?>
</select>
<?php close() ?>
</form>
<div id="txtHint"><b>Invoice info will be listed here.</b></div></td>
<p><a href="logout.php">Logout</a></p>

</tr>
</table></td>
</tr>
</table></td>
</tr>
</table>
<table width="1050" height="275" border="0" align="center" background="Footer.png">
<tr>
<td><table width="950" border="0" align="center">
<tr>
<td width="256" align="left"><a href="http://www.acdelco.com/"><img src="AC Delco Logo.png" width="245" height="47" alt="AC Delco" /></a></td>
<td width="265" align="center"><a href="http://www.asashop.org/"><img src="ASA Logo.png" width="248" height="115" alt="ASA" /></a></td>
<td width="141" align="center"><a href="https://www.ase.com/Home.aspx"><img src="ASE Logo.png" width="112" height="115" alt="ASE" /></a></td>
<td width="270"><a href="http://www.jasperengines.com/index.php"><img src="Jasper Logo.png" width="252" height="81" alt="Jasper" /></a></td>
</tr>
</table></td>
</tr>
</table>
<p>&nbsp;</p>
</body>
</html>

这是 getuser.php 的源代码

        <?PHP 
// Connects to your Database

mysql_connect('localhost', 'root') or die(mysql_error());

mysql_select_db("ServiceHistoryDB") or die(mysql_error());

$q=$_GET["q"];
//This checks to see if there is a page number. If not, it will set it to page 1

if (!(isset($pagenum)))

{

$pagenum = 1;

}


//Here we count the number of results

//Edit $data to be your query

$data = mysql_query("SELECT * FROM invoices") or die(mysql_error());

$rows = mysql_num_rows($data);



//This is the number of results displayed per page

$page_rows = 10;



//This tells us the page number of our last page

$last = ceil($rows/$page_rows);



//this makes sure the page number isn't below one, or more than our maximum pages

if ($pagenum < 1)

{

$pagenum = 1;

}

elseif ($pagenum > $last)

{

$pagenum = $last;

}

//This sets the range to display in our query

$max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows;

//This is your query again, the same one... the only difference is we add $max into it


$data_p = mysql_query("SELECT * FROM invoices WHERE CarNum = '".$q."' $max") or die(mysql_error());


//This is where you display your query results

echo "<table border='1'>
<tr>
<th>Date</th>
<th> Service </th>
</tr>";


while($info = mysql_fetch_array( $data_p ))

{ echo "<tr>";
echo "<td>" .date('M d Y', strtotime($info['Date'])) . "</td>";
echo "<td>" . $info['BriefDescription'] . "</td>";
echo "<br>";
echo "</tr>";
}
echo "</table>";



// This shows the user what page they are on, and the total number of pages



// First we check if we are on page one. If we are then we don't need a link to the previous page or the first page so we do nothing. If we aren't then we generate links to the first page, and to the previous page.

if ($pagenum == 1)

{

}

else

{

echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1'> <<-First</a> ";

echo " ";

$previous = $pagenum-1;

echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'> <-Previous</a> ";

}


//just a spacer

echo " ---- ";


//This does the same as above, only checking if we are on the last page, and then generating the Next and Last links

if ($pagenum == $last)

{

}

else {

$next = $pagenum+1;

echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'>Next -></a> ";

echo " ";

echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last'>Last ->></a> ";

}

?>

最佳答案

尝试这个有用的 Jquery 插件。

Jquery Plugin for data Table

关于php - 具有由下拉菜单填充的分页的表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21130325/

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