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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jan 2013
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Last 7 connections mssql php

    Hi there.

    I'm trying to do a last 7 Connections to the website but when i make it it just appears 1 user ill add here the image also

    here is the code :

    Code:
          <h2 class="title">Ultimas Conecções</h2>
    	  <?php
    	  $q = mysql_query("SELECT user from log_connection ORDER by date DESC");
    	  if (mysql_num_rows($q) < 1 )
    	  {
    	  echo "Theres no last connections.";
    	  }
    	  else
    	  {
    		echo '<nav>
    			<ul>
    			<center><li><strong>'.mysql_result($q, 0, 'user').'</li></strong></center>
    			<center><li><strong>'.mysql_result($q, 0, 'user').'</li></strong></center>
    			<center><li><strong>'.mysql_result($q, 0, 'user').'</li></strong></center>
    			<center><li><strong>'.mysql_result($q, 0, 'user').'</li></strong></center>
    			<center><li><strong>'.mysql_result($q, 0, 'user').'</li></strong></center>
    			<center><li><strong>'.mysql_result($q, 0, 'user').'</li></strong></center>
    			<center><li class="last "><strong>'.mysql_result($q, 0, 'user').'</li></strong></center>
    			</ul>
    			</nav>
    			';
    	  }
    	 ?>
    image :




    If theres no 7 users logs, the <li> will be as "Theres no more users" . any idea on how can i do it?

    Thanks.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    MSSQL or MySQL? You say MSSQL in the title, but you are using the mysql library here. If your using MySQL, you can use the LIMIT on it to pull only the 7 records you need, and in SQLServer you can use the TOP command. This image here shows that you are using MySQL and not MSSQL.

    Using mysql_result would be incorrect here (even when you have records). That second argument is the row, so it would pull the same 'user' column out 7 times. That is best iterated with a while loop and a fetch (mysql_result is very slow).


  •  

    Posting Permissions

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