Page 1 of 1

Error...

Posted: Mon Sep 29, 2003 8:49 pm
by 3.14
I get this message:

Query failed : You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #3' at line 1

Whenever I run the following code:

Code: Select all

<?php

<!doctype html public "-//W3C//DTD html 4.0 Transitional//EN">
<html>
<head>
<title> Members </title>
<meta name="Author" content="3.14">
</head>

<body>

<? 

/* Connecting, selecting database */
    $link = mysql_connect("localhost", "root", "")
        or die("Could not connect : " . mysql_error());
    mysql_select_db("members") or die("Could not select database");

// 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 
$query = mysql_query("SELECT * FROM tblEmployee LIMIT $from, $max_results"); 
$result = mysql_query($query) or die("Query failed : " . mysql_error());
$num_rows = mysql_num_rows($result);

// echo $query;

while ($line = mysql_fetch_array($result, MYSQL_ASSOC))
	{
		$EmployeeID = $line['MemberID'];
		$FirstName = $line['FirstName'];
		$LastName = $line['LastName'];
		$Address = $line['Address'];
		$Suburb = $line['Suburb'];
		$State = $line['State'];
		$Postcode = $line['Postcode'];
		$Phone = $line['Phone'];
		$StartDate = $line['StartDate'];
		$EndDate = $line['EndDate'];
	}
	
	/* Draw the html table for the data to be placed into */
	?>
	<table border="1" cellpadding="2" cellspacing="0" align="center" width="50%" 		bordercolorlight="#C0C0C0" bordercolordark="#FFFFFF">
	<tr>
		<td><font face="Arial" color="#006699">Member ID:</font></td>
		<td><font face="Arial" size=2><? echo $MemberID; ?></font></td>
		<td><font face="Arial" color="#006699">Name:</font></td>
		<td><font face="Arial" size=2><? echo $FirstName . " " . $LastName; ?></font></td>
	</tr>
	<tr>
		<td><font face="Arial" color="#006699">Address:</font></td>
		<td><font face="Arial" size=2><? echo $Address; ?></font></td>
		<td><font face="Arial" color="#006699">Suburb:</font></td>
		<td><font face="Arial" size=2><? echo $Suburb; ?></font></td>
	</tr>
	<tr>
		<td><font face="Arial" color="#006699">State:</font></td>
		<td><font face="Arial" size=2><? echo $State; ?></font></td>
		<td><font face="Arial" color="#006699">Postcode:</font></td>
		<td><font face="Arial" size=2><? echo $Postcode; ?></font></td>
	</tr>
	<tr>
		<td><font face="Arial" color="#006699">Telephone:</font></td>
		<td><font face="Arial" size=2><? echo $Phone; ?></font></td>
	</tr>
	<tr>
		<td><font face="Arial" color="#006699">Start Date:</font></td>
		<td><font face="Arial" size=2><? echo $StartDate; ?></font></td>
		<td><font face="Arial" color="#006699">End Date:</font></td>
		<td><font face="Arial" size=2><? echo $EndDate; ?></font></td>
	</tr>
	</table>

<?

// Figure out the total number of results in DB: 
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM employee"),0); 

// 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 Record<br />"; 

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

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

</body>

</html>

?>

Any clues as to where I'm going wrong? :?:

Posted: Mon Sep 29, 2003 9:18 pm
by JAM

Code: Select all

$query = mysql_query("SELECT * FROM tblEmployee LIMIT $from, $max_results");
$result = mysql_query($query) or die("Query failed : " . mysql_error());
You need to skip the first mysql_query().
Looks like you are trying to mysql_query(mysql_query(...)) so to speak.

Posted: Mon Sep 29, 2003 9:44 pm
by 3.14
Ah, thanks for that... was driving me batty.