Jump to content

unexpected T_STRING


eMonk

Recommended Posts

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>";
      }
    }
}

Link to comment
https://forums.phpfreaks.com/topic/249002-unexpected-t_string/#findComment-1278801
Share on other sites

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>";
?>

Link to comment
https://forums.phpfreaks.com/topic/249002-unexpected-t_string/#findComment-1278809
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/249002-unexpected-t_string/#findComment-1278829
Share on other sites

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;
}

 

 

Link to comment
https://forums.phpfreaks.com/topic/249002-unexpected-t_string/#findComment-1278831
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/249002-unexpected-t_string/#findComment-1278836
Share on other sites

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".

Link to comment
https://forums.phpfreaks.com/topic/249002-unexpected-t_string/#findComment-1278840
Share on other sites

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 ???

Link to comment
https://forums.phpfreaks.com/topic/249002-unexpected-t_string/#findComment-1278843
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.