View Single Post
Old 12-31-2005   #1 (permalink)
racerfrank
Registered User
 
Join Date: Dec 2005
Posts: 1

Prob getting Scrowler's PHP tutorial working.

Hi,
I'm trying to adapt Scrowler's "Limiting MySQL Query Results (With Pagination)" to my website.

I keep getting this error:

Parse error: parse error, unexpected ':' in /xxx/xxx/xxx/xxx/mypage.php on line 40

This is the portion of the code the error message is referring to:

PHP Code:
if($_GET[&#8216;page’] < 0){
header(&#8220;Location: index.php?page=0&limit=”.$limit);

I copy/pasted the entire script and added it to my website.

The only things I changed were substituting the OurTable" with the name of my table and "OurData" with the column name from my table, which has the text I want to display, but limited. I also added my Server and DB connect code.

I'm not sure why the start variable would ever be negative. When would that ever happen?

Actually all I wanted to do is just limit the length of the text so I tried to comment that code that gave me the error and try the script without it. I ended up with another error further down, so I gave up and put it back in.

I've only been learning PHP for a short while so I probably did something dumb, I've spent a couple hours going over this and can't figure it out.

I don't know what is in the include config.php file, I made some assumptions and I don't have a problem connecting to my database.

I have a terrible work-around in place at the moment. I placed my overly long paragraphs in 25px x 400px html paragraphs with a CSS overflow value of "hidden". Only the first line of each paragraph is displayed. I'd really like to do this correctly!

Here is the page:


PHP Code:
<html>
<head>
<title>test page</title>
</head>
<body>

<?php
$sql_host     
'localhost';
$sql_username ' MyUserName';
$sql_password ' MyPassword ';
$sql_database ' MyDB ';

$dbcnx = @mysql_connect($sql_host,$sql_username,$sql_password);
if (!
$dbcnx) {
  exit(
'<p>Unable to connect to the ' .
      
'database server at this time.</p>');
}
if (!@
mysql_select_db($sql_database)) {
  exit(
'<p>Unable to locate the database at this time.</p>');
}

if ( 
$_GET[&#8216;number’] == NULL ){
$limit 10;
} else {
$limit $_GET[&#8216;number’];
}

if (
$_GET[&#8216;page’]==NULL){
$start 0;
} else {
$start $_GET[&#8216;page’];
}

// the if above, states that if the variable in the URL named page has a value, $start will be set to it, otherwise by default it is set to 0, meaning that it will start at the beginning of the table by default.

if($_GET[&#8216;page’] < 0){
header(&#8220;Location: index.php?page=0&limit=”.$limit);
}

// this if above checks that the start variable isn’t negative, because if it is, our script will screw up. If it finds that it is, it redirects to the default page where the start is 0.

$query mysql_query(&#8220;SELECT * FROM joke LIMIT ‘$start’, ‘$limit’”) or die(mysql_error());

// the query above now has the [a] and [b] operators incorporated, making our script paginated. All we need to do now is add the next and previous links.

while ($row mysql_fetch_array ($query) ) {
echo &
#8216;<p>’.$row[‘joketext’].’</p>’;
}

$previous $start $limit;
$next $start $limit;
echo 
'<a href="index.php?start='.$previous.'">Previous Page</a> - ';
echo 
'<a href="index.php?start='.$next.'">Next Page</a>';

// the set of statements above displays the previous and next page links
?>
</body>
</html>

Last edited by racerfrank; 12-31-2005 at 06:48 AM..
racerfrank is offline