eMonk Posted October 12, 2011 Share Posted October 12, 2011 Does anyone see an error in the following code? I'm getting an unexpected T_STRING error from it: $LimitValue = $page * $LIMIT – ($LIMIT); Quote Link to comment https://forums.phpfreaks.com/topic/249002-unexpected-t_string/ Share on other sites More sharing options...
Pikachu2000 Posted October 12, 2011 Share Posted October 12, 2011 Post the five lines before and after that line. Quote Link to comment https://forums.phpfreaks.com/topic/249002-unexpected-t_string/#findComment-1278800 Share on other sites More sharing options...
eMonk Posted October 12, 2011 Author Share Posted October 12, 2011 Before: include("../includes/connect.php"); $strqry = "SELECT id from model"; $result = $db->query($strqry); $TOTALROWS = $result->num_rows; $NumOfPages = $TOTALROWS / $LIMIT; $LimitValue = $page * $LIMIT – ($LIMIT); After: <html> <body> <div id="pages" align="right">Pages: <?php If ($page == ceil($NumOfPages) && $page != 1) { for($i = 1; $i <= ceil($NumOfPages)-1; $i++) { // Loop through the number of total pages if($i > 0) { // if $i greater than 0 display it as a hyperlink echo "<a href=\"/{$i}\">{$i}</a>"; } } } Quote Link to comment https://forums.phpfreaks.com/topic/249002-unexpected-t_string/#findComment-1278801 Share on other sites More sharing options...
Pikachu2000 Posted October 13, 2011 Share Posted October 13, 2011 There doesn't appear to be a closing ?> php tag before the html. You either need that, or use echo to output the html. Quote Link to comment https://forums.phpfreaks.com/topic/249002-unexpected-t_string/#findComment-1278804 Share on other sites More sharing options...
eMonk Posted October 13, 2011 Author Share Posted October 13, 2011 I tried to echo the html but still get the same error. Here's the entire code: <?php $LIMIT = 5; if (isset($_GET['page'])) { $page = $_GET['page']; if ($page <= 0) { $page = 1; } } else { $page = 1; } include("../includes/connect.php"); $strqry = "SELECT id from model"; $result = $db->query($strqry); $TOTALROWS = $result->num_rows; $NumOfPages = $TOTALROWS / $LIMIT; $LimitValue = $page * $LIMIT – ($LIMIT); echo "<div id=\"paginating\" align=\"right\">Pages:"; if ($page == ceil($NumOfPages) && $page != 1) { for($i = 1; $i <= ceil($NumOfPages)-1; $i++) { if($i > 0) { echo "<a href=\"/{$i}\">{$i}</a>"; } } } If ($page == ceil($NumOfPages) ) { $startPage = $page; } else { $startPage = 1; } for ($i = $startPage; $i <= $page+6; $i++) { if ($i <= ceil($NumOfPages)) { if($i == $page) { echo " [{$i}] "; } else { echo "<a href="\"/{$i}\">{$i}</a> "; } } } echo "</div>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/249002-unexpected-t_string/#findComment-1278809 Share on other sites More sharing options...
MasterACE14 Posted October 13, 2011 Share Posted October 13, 2011 I'm not sure what's happened here, but it isn't right: if ($page == ceil($NumOfPages) && $page != 1) { should be if ($page == ceil($NumOfPages) && $page != 1) { Quote Link to comment https://forums.phpfreaks.com/topic/249002-unexpected-t_string/#findComment-1278813 Share on other sites More sharing options...
eMonk Posted October 13, 2011 Author Share Posted October 13, 2011 Thanks MasterACE14. That line has been fixed however the problem still remains. Quote Link to comment https://forums.phpfreaks.com/topic/249002-unexpected-t_string/#findComment-1278822 Share on other sites More sharing options...
MasterACE14 Posted October 13, 2011 Share Posted October 13, 2011 I can't see anything else wrong with it, is that the entire file? And can you copy/paste the full error message. Quote Link to comment https://forums.phpfreaks.com/topic/249002-unexpected-t_string/#findComment-1278823 Share on other sites More sharing options...
eMonk Posted October 13, 2011 Author Share Posted October 13, 2011 That's the entire file... here's the complete error message... Parse error: syntax error, unexpected T_STRING in /usr/www/........ on line 29 Line 29 is... $LimitValue = $page * $LIMIT – ($LIMIT); Quote Link to comment https://forums.phpfreaks.com/topic/249002-unexpected-t_string/#findComment-1278827 Share on other sites More sharing options...
AltarofScience Posted October 13, 2011 Share Posted October 13, 2011 um, is one of your variables a string? like the stuff you are calling from the database, as opposed to a number? i am trying to think of the things that happen when i get a t_string error and it usually involves one of my variables not being a number. are you positive that is line 29? also why () around limit? also, are there 8 lines of text in the included file? otherwise i only count that line as like 21. Quote Link to comment https://forums.phpfreaks.com/topic/249002-unexpected-t_string/#findComment-1278829 Share on other sites More sharing options...
MasterACE14 Posted October 13, 2011 Share Posted October 13, 2011 okay your last loop should be: echo "<a href=\"/{$i}\">{$i}</a> "; your line 29 should be: $LimitValue = $page * $LIMIT - ($LIMIT); You have a character there that isn't what it should be, I'm not even sure how you get that character lol, but it's acting like a hyphen(string) as opposed to a minus sign. and this has an extra curly brace in it... if ($page <= 0) { $page = 1; } } else { $page = 1; } should be if ($page <= 0) { $page = 1; } else { $page = 1; } Quote Link to comment https://forums.phpfreaks.com/topic/249002-unexpected-t_string/#findComment-1278831 Share on other sites More sharing options...
eMonk Posted October 13, 2011 Author Share Posted October 13, 2011 It's working now.. there was also a missing closing bracket in the first if statement. Now it's echoing "Pages:" but not the hyperlink numbers, for example.. "Pages: 1 2" $strqry = "SELECT id from model LIMIT $LimitValue, $LIMIT"; The query above should have 11 records so it should create 2 pages. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/249002-unexpected-t_string/#findComment-1278836 Share on other sites More sharing options...
eMonk Posted October 13, 2011 Author Share Posted October 13, 2011 I moved $LimitValue above $strqry so it looks like this: $LimitValue = $page * $LIMIT - ($LIMIT); $strqry = "SELECT id from model LIMIT $LimitValue, $LIMIT"; Now it's displaying: Pages: [1] I added an echo for $TOTALROWS and it's displaying "5" which is what $LIMIT is set to but $TOTALROWS should be "11". Quote Link to comment https://forums.phpfreaks.com/topic/249002-unexpected-t_string/#findComment-1278840 Share on other sites More sharing options...
eMonk Posted October 13, 2011 Author Share Posted October 13, 2011 Ok now $TOTALROWS returns "11" and the html output is: Pages: [1] 2 3 Now when you click on the links, for example, http://www.test.com/2 ... it leads to a 404 page because it cannot be found... do I need to create a script like page.php and make the url output http://www.test.com/page.php?page=2 ??? Quote Link to comment https://forums.phpfreaks.com/topic/249002-unexpected-t_string/#findComment-1278843 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.