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
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
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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.