Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-16-2013, 06:05 PM   PM User | #1
paulocoré
New to the CF scene

 
Join Date: Jan 2013
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
paulocoré is an unknown quantity at this point
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.
paulocoré is offline   Reply With Quote
Old 01-16-2013, 06:11 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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).
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:29 PM.


Advertisement
Log in to turn off these ads.