Php expert visit here

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Php expert visit here

    id name
    1 john
    2 joe
    3 san
    4 jesus
    5 mark
    6 nike
    7 sam
    8 love
    i am show two rows per page
    Now jesus as fall on 2nd page because i order by id ASC, jesus id is 4.

    MY QUESTION:
    i want to tell people the Jesus is on the 2nd page or the directory.

    Thanks

    #2
    PHP Code:
    $jid mysql_fetch_array(mysql_query("SELECT id FROM table WHERE name='jesus'"));
    echo 
    'Jesus is on page '.ceil($jid[0]/2); 

    if you know there is going to be some rows deleted from your database.....
    eg: say joe and san was deleted
    then you would need to do something like this:
    PHP Code:
    $jid mysql_fetch_array(mysql_query("SELECT id FROM table WHERE name='jesus'"));
    $nor mysql_num_rows(mysql_query("SELECT * FROM table WHERE id<'".$jid[0]."'"));
    echo 
    'Jesus is on page '.ceil($nor/2); 

    or you could use something like this:
    PHP Code:
    $nor mysql_num_rows(mysql_query("SELECT * FROM table WHERE name BETWEEN '' AND 'jesus'"));
    echo 
    'Jesus is on page '.ceil($nor/2); 
    but you would have to go a little careful with it as BETWEEN will include the result jesus on some databases and not on others. if it doesnt include it you would need to add 1 to $nor
    Last edited by something else; 27.10.11, 23:55.

    Comment

    Working...
    X