Text limit? Next page?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Mr. Tech
Forum Contributor
Posts: 205
Joined: Tue Feb 11, 2003 4:18 pm
Location: Australia

Text limit? Next page?

Post by Mr. Tech »

Hi!

I have an article script. Now what I want to do to it is when there is more then a certain number or words or charaters, it would put the rest of the article on the next page. Understand what I mean?

Thanks for any help!
praveen
Forum Newbie
Posts: 3
Joined: Thu Jan 23, 2003 5:34 am

Post by praveen »

Try to use this kind of query.
select * from article ORDER BY id DESC limit $min,10;

I used the above script to list ten users at a time.
Jim
Forum Contributor
Posts: 238
Joined: Fri Apr 19, 2002 5:26 am
Location: Near Austin, Texas

Post by Jim »

What he's saying is, try something like this:

First, create links like this.

Code: Select all

<a href='index.php?add=0'>   //For articles 1-10
<a href='index.php?add=10'> //For articles 10-20
<a href='index.php?add=20'> //For articles 20-30 
                            
                                           //  Etc., Etc.


// Set $min and add

$add = $_GET['add'];
$min = 0 + $add;

// Select Statement
$sql = "select * from article ORDER BY id DESC limit $min , 10"; 
$act = mysql_query($sql);

/*

Rest of PHP Code

*/
Now to explain it. In the URL, the variable "add" is set. "Add" is added to the variable $min which is then put in the SQL statement.

For the first link, $add = 0. Therefore, $num = 0 + 0 = 0. This will force the SQl statement to pull articles with ids between 0 and 10.

The next link, $add = 10. Therefore, $num = 0 + 10 = 10. This will force the SQL statement to pull articles with ids between 10 and 20.

And this goes on and on and on and on and on. :) Hope that helps!
Mr. Tech
Forum Contributor
Posts: 205
Joined: Tue Feb 11, 2003 4:18 pm
Location: Australia

Post by Mr. Tech »

so in the query this makes it limit the amount of text:

$sql = "select * from article ORDER BY id DESC limit $min , 10";

Thanks

:D
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Mr. Tech wrote:so in the query this makes it limit the amount of text:

$sql = "select * from article ORDER BY id DESC limit $min , 10";
No it doesn't - the suggestions you've had are for limiting the number of results returned not the number of characters of text. To limit characters, take a look at:
http://www.mysql.com/doc/en/String_func ... ml#IDX1185

Mac
Mr. Tech
Forum Contributor
Posts: 205
Joined: Tue Feb 11, 2003 4:18 pm
Location: Australia

Post by Mr. Tech »

Thanks.

This it:

SUBSTRING(str,pos)
Post Reply