Results 1 to 6 of 6

Thread: MySql (do not echo all)

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    259

    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?

  2. #2
    Addicted Member TheGoldenShogun's Avatar
    Join Date
    Mar 2001
    Location
    VA/MD... anywhere around the beltway
    Posts
    236
    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.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    259

    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";

  4. #4
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923
    check out the LIMIT clause for Mysql

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    259

    Example

    LIMIT !!!!! ????

    Can you give me an example , please ?

  6. #6
    scoutt
    Guest
    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
  •  



Click Here to Expand Forum to Full Width