|
-
May 7th, 2002, 05:46 PM
#1
Thread Starter
Hyperactive Member
MySql (do not echo all)
In this code:
$Sql = "select * from $TableName where BankID>=1 order by Date DESC";
$Result = mysql_query($Sql);
while ($Row = mysql_fetch_array($Result))
{
echo "$Row[Member]";
}
it will print all member.
How can I let it print 5 recodrs only. from recode 1 to 5?
How can I let it print 5 recodrs only. from recode 6 to 10?
How can I print the last 3 recodrs, if I do not know the number of records?
-
May 8th, 2002, 06:15 AM
#2
Addicted Member
do a for loop along with the mysql_result function
$Sql = "select * from $TableName where BankID>=1 order by Date DESC";
$Result = mysql_query($Sql);
for ($x = 0; $x < 5; $x++)
{
$tempVal = mysql_result($Result, $x, 'tablename.fieldname');
echo($tempVal);
}
This will go through and print the first five records of a field. For more fields just do the mysql_result function with a different value in the tablename.fieldname field.
-
May 8th, 2002, 08:36 AM
#3
Thread Starter
Hyperactive Member
Yes But
I know that...
But I ask if there is another way by using SQL
for example:
I need code like this error code
$Sql = "select * from $TableName FromRecord=6 ToRecord=10 where BankID>=1 order by Date DESC";
-
May 8th, 2002, 08:51 AM
#4
PowerPoster
check out the LIMIT clause for Mysql
-
May 8th, 2002, 09:35 AM
#5
Thread Starter
Hyperactive Member
Example
LIMIT !!!!! ????
Can you give me an example , please ?
-
May 8th, 2002, 09:49 AM
#6
The LIMIT clause can be used to constrain the number of rows returned by the SELECT statement. LIMIT takes one or two numeric arguments. The arguments must be integer constants. If two arguments are given, the first specifies the offset of the first row to return, the second specifies the maximum number of rows to return. The offset of the initial row is 0 (not 1):
mysql> SELECT * FROM table LIMIT 5,10; # Retrieve rows 6-15
If one argument is given, it indicates the maximum number of rows to return:
mysql> SELECT * FROM table LIMIT 5; # Retrieve first 5 rows
In other words, LIMIT n is equivalent to LIMIT 0,n.
man don't you read anything?????
http://www.mysql.com/documentation/m...oc.html#SELECT
and trhen scroll down a bit
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|