Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    4
    Thanks
    3
    Thanked 0 Times in 0 Posts

    I get one entries when I want the last 5

    Hi, I need some help. My code works and I get the last input. Now what to do if I want the 5 last inputs?

    PHP Code:
    <?PHP

    //inställningar-----------------------------------------------------------------------------

    $antal_dagar 1;  //Hur många dagar ska meddelandet visas
    $reklamtext "Inga bud ännu!";

    //------------------------------------------------------------------------------------------



    $dbh=mysql_connect ("localhost""xxxx","xxxxx") or die('Cannot connect to the database because: ' mysql_error());
    mysql_select_db ("xxxxxx");



    $result mysql_query("SELECT caller FROM samtal ORDER BY id DESC LIMIT 10");

    $r mysql_fetch_row($result);
    if(
    $r[0]=="")
    print 
    $reklamtext;
    else 
    print 
    $r[0];

    ?>

  • #2
    Senior Coder
    Join Date
    Apr 2007
    Location
    Quakertown PA USA
    Posts
    1,028
    Thanks
    1
    Thanked 125 Times in 123 Posts

    Macintosh

    You will have to loop through the results from your query. ie:

    Instead of:
    PHP Code:
    $result mysql_query("SELECT caller FROM samtal ORDER BY id DESC LIMIT 10");

    $r mysql_fetch_row($result);
    if(
    $r[0]=="")
    print 
    $reklamtext;
    else 
    print 
    $r[0];

    ?> 
    try
    PHP Code:
    $result mysql_query("SELECT caller FROM samtal ORDER BY id DESC LIMIT 10");

    while (
    $r mysql_fetch_row($result))
    {
       if(
    $r[0]=="")
       print 
    $reklamtext;
       else 
       print 
    $r[0];

    John

  • Users who have thanked PappaJohn for this post:

    Goran (03-18-2009)

  • #3
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    4
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Thank you so very much, Now I have 5 but I get them in a line. I want to see them like

    123123
    123123
    123123
    123123
    123123

    Goran
    also called PappaGoran

  • #4
    New Coder
    Join Date
    Mar 2009
    Location
    Chicago, IL
    Posts
    69
    Thanks
    0
    Thanked 15 Times in 15 Posts
    Just add line break after printing each result:

    PHP Code:
    while ($r mysql_fetch_row($result))
    {
       if(
    $r[0]=="")
       print 
    $reklamtext;
       else 
       print 
    $r[0] .'<br>';


  • Users who have thanked steelaz for this post:

    Goran (03-18-2009)

  • #5
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    4
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Great. Thank you. One more thing. I How to do if I now only want to show
    the last 5 figures in every line like:

    xxxx23123
    xxxx23123
    xxxx23123
    xxxx23123
    xxxx23123

    Goran

  • #6
    New Coder
    Join Date
    Mar 2009
    Location
    Chicago, IL
    Posts
    69
    Thanks
    0
    Thanked 15 Times in 15 Posts
    To get last characters of the string you can use substr() function:

    PHP Code:
    print substr($r[0], -55) .'<br>'
    Last edited by steelaz; 03-18-2009 at 07:44 PM.

  • Users who have thanked steelaz for this post:

    Goran (03-18-2009)

  • #7
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    4
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Thank you. It made my day


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •