Web Analytics Made Easy -
StatCounter Little outputting help.. - CodingForum


No announcement yet.

Little outputting help..

  • Filter
  • Time
  • Show
Clear All
new posts

  • Resolved Little outputting help..

    Hi, I run a custom built forum system. When a user views a topic, it records the user's ID and current time into the DB. I did this to know which user has viewed the topic or to know how many users have visited a particular topic.
    Now the query to get those users and time from the DB is -
    PHP Code:
    $sql=mysql_fetch_array(mysql_query("SELECT uid,date FROM topseen WHERE tid='".$tid."' ORDER BY time DESC")); 
    pretty simple..
    the problem is i want to echo the output like this -
    User:$sql[0] viewed the topic at $sql[1]<br/> //First User
    User:$sql[0] viewed the topic at $sql[1]<br/> //Second User
    User:$sql[0] viewed the topic at $sql[1]<br/> //Third User
    and so on..
    But it shows only the top or first entry(Obviously), i want to show all the entries for that particular topic.. how can i echo all the entries? I hope you understand.
    any help will be appreciated.

    Last edited by REY619; Apr 3, 2009, 03:34 PM.

  • #2
    use while...

    PHP Code:
    $result mysql_query("SELECT uid,date FROM topseen WHERE tid='".$tid."' ORDER BY time DESC"
    or die(
    $row mysql_fetch_array$result ){
    // do your echo here!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

    The mysql_fetch_array function gets the next-in-line associative array from a MySQL result. By putting it in a while loop it will continue to fetch the next array until there is no next array to fetch. This function can be called as many times as you want, but it will return FALSE when the last associative array has already been returned.

    By placing this function within the conditional statement of the while loop, we can kill two birds with one stones.
    1. We can retrieve the next associative array from our MySQL Resource, $result, so that we can print out the name and age of that person.
    2. We can tell the while loop to stop printing out information when the MySQL Resource has returned the last array, as False is returned when it reaches the end and this will cause the while loop to halt.


    • #3
      Thanx sea4me very much..


      • #4
        Ur welcome!