Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with selecting multiple records

Status
Not open for further replies.

Zepher2

Technical User
Dec 29, 2001
25
US
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 &quot;<p>\n&quot;;


// 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(&quot;SELECT * FROM Surveyinfo LIMIT $from, $max_results&quot;);
$sql = mysql_query(&quot;SELECT * FROM Surveyinfo WHERE ID >= $SelectID LIMIT $from, $max_results&quot;);

while($row = mysql_fetch_array($sql)){
// Build your formatted results here.
echo $row['Date'].&quot;<br />&quot;;
echo $row['Age'].&quot;<br />&quot;;
echo $row['ID'].&quot;<br />&quot;;
}

// Calculate final record number

//$last_results = mysql_result(mysql_query(&quot;SELECT COUNT(*) as Num FROM Surveyinfo&quot;),0);

// Figure out the total number of results in query:
$total_results = mysql_result(mysql_query(&quot;SELECT COUNT(*) as Num FROM Surveyinfo WHERE ID >= $SelectID &quot;),0);

//display total records found
echo &quot;Records found = &quot;;
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 &quot;<center>Select a Page<br />&quot;;

// Build Previous Link
if($page > 1){
$prev = ($page - 1);
echo &quot;<a href=\&quot;&quot;.$_SERVER['PHP_SELF'].&quot;?page=$prev\&quot;><<Previous</a> &quot;;
}

for($i = 1; $i <= $total_pages; $i++){
if(($page) == $i){
echo &quot;$i &quot;;
} else {
echo &quot;<a href=\&quot;&quot;.$_SERVER['PHP_SELF'].&quot;?page=$i\&quot;>$i</a> &quot;;
}
}

// Build Next Link
if($page < $total_pages){
$next = ($page + 1);
echo &quot;<a href=\&quot;&quot;.$_SERVER['PHP_SELF'].&quot;?page=$next\&quot;>Next>></a>&quot;;
}
echo &quot;</center>&quot;;

//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
 
Here are some hints that will help you to track the error down:

Add error checking to the mysql commands:
Code:
mysql_connect($host,$user,$pass)
Code:
 OR die(mysql_error());

You can reuse the OR clause for mysql_select_db and mysql_query.

It will probably show you that on the second access there is a SQL error in the uery issued.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top