I am very new to this, so any help you can give will be appreciated. I am trying to display info page by page where the records selected are greater than a user inputted value: I have tried to adapt a code snippet I found but can't get it to work properly. The first instance displays properly but clicking for the next page results in this error code:
Warning: Supplied argument is not a valid MySQL result resource in /home/a/a/******.org/html/show_survey_results.php on line 60
Warning: Supplied argument is not a valid MySQL result resource in /home/a/a/*****.org/html/show_survey_results.php on line 72
Here is the code:
// Database Connection
//Connects to the database using mysql_connect()
mysql_connect("****, ****","******"
//Select the database
mysql_select_db("******"
//Get ID number from Control_panel_survey_select1
$SelectID = $_REQUEST['SelectID'];
echo "Selected records with ID greater than: ";
echo $SelectID;
echo "<p>\n";
// If current page number, use it
// if not, set one!
if(!isset($_GET['page'])){
$page = 1;
} else {
$page = $_GET['page'];
}
// Define the number of results per page
$max_results = 1;
// Figure out the limit for the query based
// on the current page number.
$from = (($page * $max_results) - $max_results);
// Perform MySQL query on only the current page number's results
//$sql = mysql_query("SELECT * FROM Surveyinfo LIMIT $from, $max_results"
$sql = mysql_query("SELECT * FROM Surveyinfo WHERE ID >= $SelectID LIMIT $from, $max_results"
while($row = mysql_fetch_array($sql)){
// Build your formatted results here.
echo $row['Date']."<br />";
echo $row['Age']."<br />";
echo $row['ID']."<br />";
}
// Calculate final record number
//$last_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM Surveyinfo",0);
// Figure out the total number of results in query:
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM Surveyinfo WHERE ID >= $SelectID ",0);
//display total records found
echo "Records found = ";
echo $total_results;
// Calculate final record number
// Figure out the total number of pages. Always round up using ceil()
$total_pages = ceil($total_results / $max_results);
// Build Page Number Hyperlinks
echo "<center>Select a Page<br />";
// Build Previous Link
if($page > 1){
$prev = ($page - 1);
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev\"><<Previous</a> ";
}
for($i = 1; $i <= $total_pages; $i++){
if(($page) == $i){
echo "$i ";
} else {
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> ";
}
}
// Build Next Link
if($page < $total_pages){
$next = ($page + 1);
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\">Next>></a>";
}
echo "</center>";
//Close the database connection
mysql_close();
?>
I think the variable $SelectID is not being retained when the new page is called, but I have no idea how to fix it.
Thanks in advance
Warning: Supplied argument is not a valid MySQL result resource in /home/a/a/******.org/html/show_survey_results.php on line 60
Warning: Supplied argument is not a valid MySQL result resource in /home/a/a/*****.org/html/show_survey_results.php on line 72
Here is the code:
// Database Connection
//Connects to the database using mysql_connect()
mysql_connect("****, ****","******"
//Select the database
mysql_select_db("******"
//Get ID number from Control_panel_survey_select1
$SelectID = $_REQUEST['SelectID'];
echo "Selected records with ID greater than: ";
echo $SelectID;
echo "<p>\n";
// If current page number, use it
// if not, set one!
if(!isset($_GET['page'])){
$page = 1;
} else {
$page = $_GET['page'];
}
// Define the number of results per page
$max_results = 1;
// Figure out the limit for the query based
// on the current page number.
$from = (($page * $max_results) - $max_results);
// Perform MySQL query on only the current page number's results
//$sql = mysql_query("SELECT * FROM Surveyinfo LIMIT $from, $max_results"
$sql = mysql_query("SELECT * FROM Surveyinfo WHERE ID >= $SelectID LIMIT $from, $max_results"
while($row = mysql_fetch_array($sql)){
// Build your formatted results here.
echo $row['Date']."<br />";
echo $row['Age']."<br />";
echo $row['ID']."<br />";
}
// Calculate final record number
//$last_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM Surveyinfo",0);
// Figure out the total number of results in query:
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM Surveyinfo WHERE ID >= $SelectID ",0);
//display total records found
echo "Records found = ";
echo $total_results;
// Calculate final record number
// Figure out the total number of pages. Always round up using ceil()
$total_pages = ceil($total_results / $max_results);
// Build Page Number Hyperlinks
echo "<center>Select a Page<br />";
// Build Previous Link
if($page > 1){
$prev = ($page - 1);
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev\"><<Previous</a> ";
}
for($i = 1; $i <= $total_pages; $i++){
if(($page) == $i){
echo "$i ";
} else {
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> ";
}
}
// Build Next Link
if($page < $total_pages){
$next = ($page + 1);
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\">Next>></a>";
}
echo "</center>";
//Close the database connection
mysql_close();
?>
I think the variable $SelectID is not being retained when the new page is called, but I have no idea how to fix it.
Thanks in advance