www.webdeveloper.com
Results 1 to 8 of 8

Thread: Row id[0] to echo as '1'

  1. #1
    Join Date
    Nov 2009
    Posts
    268

    Question Row id[0] to echo as '1'

    Hey guy's, I know this has to be simple but I can't figure out how to echo every $row['id'] incremented by +1 so that [0] is replaced by '1' and [1] is replaced by '2' etc.
    I need it to setup javascript pagination onclick of spans.
    Eg.
    PHP Code:
    echo "<p class='backforward'>";
    echo 
    "<span class='row' >".$row['id']."</span>";
    //tried ".$row['id'+1]." threw error
    //".$row['id']+1." threw error
    //maybe ".$row['id+1']." ????
    echo "/";
    echo 
    "<span class='rowsfound' >".$rowsfound."</span>";
    echo 
    "</p>";
    //$row[0] produces 0/20
    //should be 1/20, 2/20, 3/20 etc. 
    In any case I'd like to know the words used to express what I''m trying to do as it isn't increment $row['id'] by 1 as that would call the next row instead of incrementing the echoed result by one? I'm guessing 'Increment the echoed result Id by 1 so that zero isn't the result. Thanks for any help. Maybe like javascript array.indexOf($row[i])???

  2. #2
    Join Date
    Apr 2010
    Posts
    227
    PHP Code:

    $x 
    $row['id']+=1;
    echo 
    "<span class='row' >$x</span>"
    Why am i getting the feeling that you are unhappy with mysql auto increment beginning with 1 instead of a desired 2 say?

  3. #3
    Join Date
    Aug 2011
    Location
    Worthing, West Sussex
    Posts
    96
    Some people.
    Titanium Web Designs Ltd - Bespoke websites and online systems

  4. #4
    Join Date
    Nov 2009
    Posts
    268

    Thumbs up Row id[0] to echo as '1'

    Belrick, right on, I ended up doing it client side I just couldn't express the php language properly to get the web search with that answer. Muchos mas gracias para te. It's more like javascript than I thought.
    dangerousprince, MY MOTHER HAD SOME OF THEM

  5. #5
    Join Date
    Apr 2010
    Posts
    227
    PHP is the language of gods not mortal men.

    I love it, so superior to read, fault find, MAC etc i just find myself tearing up in joy.

    Ok maybe i exaggerate.

    Glad i could help so easily.

    FYI; MYSQL provides for you the ability to set the number auto increments begins at. Just saying.

  6. #6
    Join Date
    Nov 2009
    Posts
    268

    Thumbs up Row id[0] to echo as '1'

    This was the Javascript I used to do the same thing

    Code:
    function incrementitem()
    {
    var rows=document.getElementsByClassName('row');
    for(var i=0; i<rows.length; i++)
    {
    rows[i].innerHTML=Number(rows[i].innerHTML)+1;
    }
    }
    Nice that the echoed span className = row became redundant having the className but might facilitate some other manipulation of the span.

  7. #7
    Join Date
    Nov 2009
    Posts
    268
    Belrick, hey that var $x doesn't work on every row? It sets every row id to 1. You hinted that sql php admin can have the first row set as 1 not 0? Autoincremet by 1 normaly starts with 0 and I'm pritty sure I tried starting the row id's with 1 and ended up getting sql errors but of course I could be 'micing' if not 'rating'. Please steer me in the right direction.

  8. #8
    Join Date
    Nov 2009
    Posts
    268

    Unhappy Row id[0] to echo as '1'

    Quote Originally Posted by Belrick View Post
    FYI; MYSQL provides for you the ability to set the number auto increments begins at. Just saying.
    are you talking about the query string in the Get .php page or myphpadmin? I just changed the shortest table, 2 rows with 'id as primary key' row 0 to row 1 and row 1 to row 2. Row 0 still gets echoed as blank and rows 1 and 2 are eched fine so I'm guessing you are talking about the query string. Without the $x var working in the server then client side increment would be the only way to go to avoid blank rows in all tables?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles