djrichwz Posted October 21, 2008 Share Posted October 21, 2008 I am fairly new to php but have been doing quite well at understand the php and mysql but i just cant seem to get the syntax right with the below sql statement. $sql = mysql_query ("SELECT * FROM results WHERE resultteam='$team'" order by ID DESC LIMIT ".$Start.",".$pageLimit); can anybody help please Quote Link to comment https://forums.phpfreaks.com/topic/129383-solved-error-in-my-sql-staetement/ Share on other sites More sharing options...
GKWelding Posted October 21, 2008 Share Posted October 21, 2008 $sql = mysql_query ("SELECT * FROM results WHERE resultteam='$team' order by ID DESC LIMIT ".$Start.",".$pageLimit."); I think, I have no way of testing it from here. Quote Link to comment https://forums.phpfreaks.com/topic/129383-solved-error-in-my-sql-staetement/#findComment-670727 Share on other sites More sharing options...
djrichwz Posted October 21, 2008 Author Share Posted October 21, 2008 No Im afraid it did not work just gave me a blank page like when the php script insnt working. There was no sql error either. sql error in my syntax: 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 '5' at line 1 Quote Link to comment https://forums.phpfreaks.com/topic/129383-solved-error-in-my-sql-staetement/#findComment-670732 Share on other sites More sharing options...
ranjuvs Posted October 21, 2008 Share Posted October 21, 2008 try this $sql = mysql_query ("SELECT * FROM results WHERE resultteam='".$team."' order by ID DESC LIMIT '".$Start."','".$pageLimit."'"); Quote Link to comment https://forums.phpfreaks.com/topic/129383-solved-error-in-my-sql-staetement/#findComment-670733 Share on other sites More sharing options...
djrichwz Posted October 21, 2008 Author Share Posted October 21, 2008 Afraid Not I still get the same error message. Thanks for your continuing help Hopefully we can solve this Quote Link to comment https://forums.phpfreaks.com/topic/129383-solved-error-in-my-sql-staetement/#findComment-670735 Share on other sites More sharing options...
ranjuvs Posted October 21, 2008 Share Posted October 21, 2008 please try this $sql = mysql_query ("SELECT * FROM results WHERE resultteam='".$team."' order by ID DESC LIMIT $Start,$pageLimit"); Quote Link to comment https://forums.phpfreaks.com/topic/129383-solved-error-in-my-sql-staetement/#findComment-670737 Share on other sites More sharing options...
R4nk3d Posted October 21, 2008 Share Posted October 21, 2008 $sql = "SELECT * FROM results WHERE 'resultteam'=$team' order by ID DESC LIMIT $Start,$pageLimit"; $result = mysql_query($sql,$connection); try that, Quote Link to comment https://forums.phpfreaks.com/topic/129383-solved-error-in-my-sql-staetement/#findComment-670741 Share on other sites More sharing options...
djrichwz Posted October 21, 2008 Author Share Posted October 21, 2008 Ok now it validates but with the code i am using does not display any records but it works without that where statement. here is my code: resultteam is my db field Varchar(45) code: <?php $team=$_GET["t"]; $results=$_GET["results"]; If ($results=="final") { include('dbinfo.php'); // connect to DB. $conn = mysql_connect( $dbhost, $dbuser, $dbpass ); mysql_select_db($dbname); $result = mysql_query("SELECT * FROM finaltable order by ID DESC"); $row = mysql_fetch_array($result) or die(mysql_error()); $finaltable=$row['finalresults']; If ($finaltable==NULL) { echo "<P>No Current Final Results Table<BR>Please Check Back At The End Of The Season</P>"; }else{ $finalresults = nl2br(htmlentities($finaltable)); echo "<P>"; echo "<B>BTFC Final Results Table 2008</B>"; echo "<br><br>"; echo $finalresults; echo "</P>"; } }else{ $team=$_GET["t"]; $results=$_GET["results"]; // Start Results Page include('dbinfo.php'); // include your code to connect to DB. $conn = mysql_connect( $dbhost, $dbuser, $dbpass ); mysql_select_db($dbname); $noEntriesQuery = mysql_query("SELECT * FROM results") or die(mysql_error()); // read the number $noEntries = mysql_num_rows($noEntriesQuery); // set page limit $pageLimit = 5; // calculate the number of pages $noPages = ceil($noEntries / $pageLimit); // current page $currentPage = 0; // check if the $_GET value exists, if yes.. set the $currentPage to that value if(isset($_GET['spag']) && is_numeric($_GET['spag']) && $_GET['spag'] > 0 && $_GET['spag'] < $noPages){ // the test passed, set the current page $currentPage = $_GET['spag']; } // start number $start = $currentPage * $pageLimit; // the query for the current page $sql = "SELECT * FROM results WHERE 'resultteam'=$team' order by ID DESC LIMIT $Start,$pageLimit"; $result = mysql_query($sql,$conn); if($sql){echo " Command is successful ";} else {echo "Command is not successful ";} echo $team; // Start Results Loop while($row = mysql_fetch_array($result)) { echo "<BR>"; echo $row['resultdate']; echo "<BR>"; echo $row['resultdetails']; echo "<BR>"; } echo "<BR>"; // Query for number of pages for($a = 0; $a < $noPages; $a++){ if($currentPage == $a){ echo "PAGE"; echo ($a+1); }else{ echo '<a class="pagelinks" href="'.$_SERVER['PHP_SELF'].'?content=results&results=match&t='.$team.'&spag='.$a.'">'.($a+1).'</a>'; } if($a < $noPages - 1){ echo '-'; } } //End Results Page } I presume this is still part of the same problem sorry if it is not considered part. can anybody help thank you for your help so far can anybody help Quote Link to comment https://forums.phpfreaks.com/topic/129383-solved-error-in-my-sql-staetement/#findComment-670756 Share on other sites More sharing options...
R4nk3d Posted October 21, 2008 Share Posted October 21, 2008 It could be this but i dont think so, ur missing a " ' " before $team in the $sql. $sql = "SELECT * FROM results WHERE 'resultteam'='$team' order by ID DESC LIMIT $Start,$pageLimit"; Quote Link to comment https://forums.phpfreaks.com/topic/129383-solved-error-in-my-sql-staetement/#findComment-670818 Share on other sites More sharing options...
revraz Posted October 21, 2008 Share Posted October 21, 2008 You can't use a Single Quote ' around a Field Name, it's either a backtic ` or nothing. The best way to see your error is to just echo the query. Quote Link to comment https://forums.phpfreaks.com/topic/129383-solved-error-in-my-sql-staetement/#findComment-670854 Share on other sites More sharing options...
djrichwz Posted October 21, 2008 Author Share Posted October 21, 2008 Solved It thanks to all your help i used this code in the end $sql = "SELECT * FROM results where resultteam='$team' order by ID DESC LIMIT $start,$pageLimit"; Quote Link to comment https://forums.phpfreaks.com/topic/129383-solved-error-in-my-sql-staetement/#findComment-670856 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.