Jump to content

Pagnation help


yandoo

Recommended Posts

Hi there,

 

Im trying to add some pagnation to some records that are displayed on my page...I keep getting an error saying: Notice: Undefined variable: PHP_SELF in line 414, 433.

 

I tried changing the lines of PHP_SELF pagnation code to:

"<a href=\"$_SERVER['$PHP_SELF']?page=$i\">$i</a>"

. I did this for all the NEXT, PREV and number links and found i got this new error: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in line 207...

 

That points to this line: <a href=\".$_SERVER['PHP_SELF'].?page=$pageprev\">PREV</a>

 

If anybody can tell me why or help me that would be super! :)

 

Heres my full code:

<?php require_once('Connections/woodside.php'); ?>
<?php

// Report all PHP errors (bitwise 63 may be used in PHP 3)
error_reporting(E_ALL);
?>

<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO animalexperience (AnimalExpID, AnimalID, ExpID, Experience) VALUES (%s, %s, %s, %s)",
                       GetSQLValueString($_POST['animalexperienceid'], "int"),
                       GetSQLValueString($_POST['animalid'], "int"),
                       GetSQLValueString($_POST['select'], "int"),
				   GetSQLValueString($_POST['experience'], "text"));
				   
  mysql_select_db($database_woodside, $woodside);
  $Result1 = mysql_query($insertSQL, $woodside) or die(mysql_error());

  $insertGoTo = "add_animal_exp.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}

$colname_animal = "-1";
if (isset($_GET['recordID'])) {
  $colname_animal = (get_magic_quotes_gpc()) ? $_GET['recordID'] : addslashes($_GET['recordID']);
    
  
}
mysql_select_db($database_woodside, $woodside);
$query_animal = sprintf("SELECT * FROM animal WHERE AnimalID = %s", $colname_animal);
$animal = mysql_query($query_animal, $woodside) or die(mysql_error());
$row_animal = mysql_fetch_assoc($animal);
$totalRows_animal = mysql_num_rows($animal);

mysql_select_db($database_woodside, $woodside);
$query_experience = "SELECT * FROM experience ORDER BY ExpID ASC";
$experience = mysql_query($query_experience, $woodside) or die(mysql_error());
$row_experience = mysql_fetch_assoc($experience);
$totalRows_experience = mysql_num_rows($experience);


$maxRows_animalexperience = 10;
$pageNum_animalexperience = 0;
if (isset($_GET['pageNum_animalexperience'])) {
  $pageNum_animalexperience = $_GET['pageNum_animalexperience'];
}
$startRow_animalexperience = $pageNum_animalexperience * $maxRows_animalexperience;

mysql_select_db($database_woodside, $woodside);
$query_animalexperience = "SELECT * FROM animalexperience";
$query_limit_animalexperience = sprintf("%s LIMIT %d, %d", $query_animalexperience, $startRow_animalexperience, $maxRows_animalexperience);
$animalexperience = mysql_query($query_limit_animalexperience, $woodside) or die(mysql_error());
$row_animalexperience = mysql_fetch_assoc($animalexperience);

if (isset($_GET['totalRows_animalexperience'])) {
  $totalRows_animalexperience = $_GET['totalRows_animalexperience'];
} else {
  $all_animalexperience = mysql_query($query_animalexperience);
  $totalRows_animalexperience = mysql_num_rows($all_animalexperience);
}
$totalPages_animalexperience = ceil($totalRows_animalexperience/$maxRows_animalexperience)-1;

  [b]if(empty($page)){
        $page = 1;
    }   
$limit          = 5;               
    $query_count    = "SELECT count(*) FROM experience";    
    $result_count   = mysql_query($query_count);    
    $totalrows      = mysql_result($result_count, 0, 0); [/b]

mysql_select_db($database_woodside, $woodside); 
[b]$limitvalue = $page * $limit - ($limit);[/b]
$query_test = "SELECT * FROM animalexperience WHERE AnimalID='" . $row_animal['AnimalID'] . "'[b]'$limitvalue, $limit'";[/b]
$test = mysql_query($query_test, $woodside) or die(mysql_error());
$row_test = mysql_fetch_assoc($test);
$totalRows_test = mysql_num_rows($test);

mysql_select_db($database_woodside, $woodside);
$query_experiencelist = "SELECT * FROM experience WHERE ExpID NOT IN (SELECT ExpID FROM animalexperience WHERE AnimalID='" . $row_test['AnimalID'] . "')";
$experiencelist = mysql_query($query_experiencelist, $woodside) or die(mysql_error());
$row_experiencelist = mysql_fetch_assoc($experiencelist);
$totalRows_experiencelist = mysql_num_rows($experiencelist);
?>
<form id="form1" name="form1" method="POST" action="<?php echo $editFormAction; ?>">
  <label>
  <select name="select">
    <?php
do {  
?>
    <option value="<?php echo $row_experiencelist['ExpID']?>"><?php echo $row_experiencelist['Experience']?></option>
    <?php
} while ($row_experiencelist = mysql_fetch_assoc($experiencelist));
  $rows = mysql_num_rows($experiencelist);
  if($rows > 0) {
      mysql_data_seek($experiencelist, 0);
  $row_experiencelist = mysql_fetch_assoc($experiencelist);
  }
?>
  </select>
  </label>
   <p> </p>
   <?php echo $row_test['Experience']?>
   <table width="250" border="0">
<tr>  <td>
   <span class="style12">This Animal has Experience:</span>  </td>
</tr>
  <?php do { ?>
         <tr> <td> </td> </tr>
          
    <?php } while ($row_test = mysql_fetch_assoc($test)); ?>
</table>

   <input name="animalexperienceid" type="hidden" id="animalexperienceid" value="<?php echo $totalRows_animalexperience +1 ?>" />
    <input name="animalid" type="hidden" id="animalid" value="<?php echo $row_animal['AnimalID']; ?>" />
<input type="submit" name="Submit" value="Submit" />
  <input type="hidden" name="MM_insert" value="form1">
  <input name="experience" type="hidden" id="experience" value="<?php echo $row_experiencelist['Experience']?>" />
</form>
<?php 
[b]$pageprev = $page-1;
    if($page != 1){ 
        echo("<a href=\".$_SERVER['PHP_SELF'].?page=$pageprev\">PREV</a> "); 
    }else{
        echo("PREV"." ");
    }

    $numofpages =  ceil($totalrows /$limit);

    for($i = 1; $i <= $numofpages; $i++){
        if($i == $page){
            echo($i." ");
        }else{
            echo("<a href=\".$_SERVER['PHP_SELF'].?page=$i\">$i</a> ");
        } }

$pagenext = $page+1;

//$new = ($limit * $page) - $totalrows; <-- and remove this part
//echo"$new";

    if($page < $numofpages) {
        echo("<a href=\".$_SERVER['PHP_SELF'].?page=$pagenext\">NEXT</a>");
    }else{
        echo("NEXT"); 
    }[/b]

mysql_free_result($test);
mysql_free_result($animal);

mysql_free_result($experience);
mysql_free_result($user_conditional);
mysql_free_result($animalexperience);
?>

 

 

Link to comment
Share on other sites

Hi there,

 

Thanks for the reply, I have tried the changes you suggeted and find i have the same problem. I have removed any non relevant code to try to debug it (please see new code blow)

 

It keeps error mesaging: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING

 

It does this at each point in the code the $_server

[php_Self] ?????
The only time i can get it to work with no error is bu using `` types of speach marks e.g:
 echo('<a href=\'$_SERVER[`PHP_SELF`]?page=$pageprev\'>PREV</a> ');

 

When i do this it doesnt work properly but some of the items are displayed with the NEXT and PREV links. (they dont work though, 404 error on click and also the $i variable appears as $i and not a number?).

 

Please see my new code below it is much smaller, Thank You :)

 

<?php require_once('Connections/woodside.php'); ?><html>
<?php error_reporting(E_ALL);
ini_set('display_errors', '1');

if(empty($page)){
        $page = 1;
    }  

$limit = 3;               
    $query_count    = "SELECT count(*) FROM experience";    
    $result_count   = mysql_query($query_count);    
    $totalrows      = mysql_result($result_count, 0, 0); 

mysql_select_db($database_woodside, $woodside); 
$limitvalue = $page * $limit - ($limit);
$query_test = "SELECT * FROM animalexperience LIMIT $limitvalue, $limit";
$test = mysql_query($query_test, $woodside) or die(mysql_error());
$row_test = mysql_fetch_assoc($test);
$totalRows_test = mysql_num_rows($test);

$pageprev = $page-1;

    if($page != 1){ 
        echo('<a href=\'$_SERVER[`PHP_SELF`]?page=$pageprev\'>PREV</a> '); 
    }else{
        echo("PREV"." ");
    }

    $numofpages =  ceil($totalrows /$limit);

    for($i = 1; $i <= $numofpages; $i++){
        if($i == $page){
            echo($i." ");
        }else{
            echo'<a href=\'$_SERVER[`PHP_SELF`]?page=`$i`\'>$i</a> ';
        }
    }

$pagenext = $page+1;

    if($page < $numofpages) {
        echo'<a href=\'$_SERVER[`PHP_SELF`]?page=$pagenext\'>NEXT</a>';
    }else{
        echo("NEXT"); 
    }
    echo" ";
?>
<?php do { ?>               
	<td><?php echo $row_test['Experience']?>                
    <?php } while ($row_test = mysql_fetch_assoc($test)); ?>	
<?php	 mysql_free_result($test); ?>

Link to comment
Share on other sites

Hi,

 

I managed to get rid of that error by adding and set of "" to the following code:

echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$pageprev\">PREV</a>"; 

 

Still not working entirely right tho, as the PREV link is never hyperlink is just printed (never hyperlinked )and the NEXT link only works too page 2(the number links in between NEXT & PREV is only way to navigate past page 2 ).

 

Also the records that displayed only go to what the limit is (e.g. 1st 3 records) even if NEXT or page number is clicked???

 

Its a little baffling because pagnation is from working codei have used before

Link to comment
Share on other sites

Hi there,

 

Heres a bit of a tickler....I think i know why ultimately pagnation has been such as pain for me....I this could cause a problem then please tell me!!!

 

The query that searches for records (that will be displayed and pagnation added to) is done so thorugh the use of a hyperlink e.g. (Search for all AnimalExperience records that have the same AnimalID). With this in mind, when i come to vie the records with their pagnation it looks fine but ONLY for that 1st page it wont work any further....

 

The browser says: http://localhost/woodside/add_anima_exp1.php?recordID=51

 

But when go page 2 it says: http://localhost/woodside/add_animal_exp1.php?page=2

 

So it has like forgoten the original AnimalID that was 51????

 

I hope im making some sense!!??

 

If anybody knows what im saying and has answer please get back to me.

 

Thanks

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.