MySQL
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Tutorialized ForumsDatabasesMySQL

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Tutorialized Forums Sponsor:
  #1  
Old November 7th, 2005, 03:16 PM
wkheathjr wkheathjr is offline
Contributing User
Tutorialized Newbie (0 - 499 posts)
 
Join Date: Oct 2005
Posts: 5 wkheathjr New User: is a brand new recruit and a unknown entity at this point. 
Time spent in forums: < 1 sec
Reputation Power: 0
Fetching data from MySQL

Hello,

I just got login system to work ok. Will go into session later but one step at time. Right now, I am trying to figure out the code that will fetch the information that was input recently into the database.

1st step: You fill out the field
2nd step: You submit and the action will go to process.php
3rd step: On process.php page, I want to show result

Problem: The code seems to show all results instead of one most recently. How do I limit it to one and recently result??

The code I used was:
Code:
<?

	$query = "SELECT * FROM userinfo";
	$result = mysql_query($query);

	while($row = mysql_fetch_array($result))
	{
		echo "First Name: $row[username]";
		echo "Surname: $row[location]";
	}
      


?>


I wasn't sure if I am supposed to use GET_POST script or the one I posted above?

Reply With Quote
  #2  
Old November 8th, 2005, 02:01 PM
jetblacknewyear jetblacknewyear is offline
Contributing User
Tutorialized Newbie (0 - 499 posts)
 
Join Date: Aug 2005
Posts: 36 jetblacknewyear New User: is a brand new recruit and a unknown entity at this point. 
Time spent in forums: < 1 sec
Reputation Power: 0
not sure what you mean, but i'll give an attempt to show you anyways.

if the field they fill out is a Username field

Code:
<? 

  $q = mysql_query("SELECT * FROM userinfo='$username'"); 
  $rows = mysql_num_rows($q)

  if ($q < 1)
  {
    echo "No Results Found";
  }
  else
  {
     while($row = mysql_fetch_array($q)) 
     { 
        echo "First Name: $row[username]"; 
        echo "Surname: $row[location]"; 
     } 
  }
      

?>


try that and tell me if it's what you wanted

Reply With Quote
  #3  
Old April 11th, 2006, 10:36 PM
BigResource BigResource is offline
Contributing User
Tutorialized Newbie (0 - 499 posts)
 
Join Date: Apr 2006
Posts: 3 BigResource New User: is a brand new recruit and a unknown entity at this point. 
Time spent in forums: < 1 sec
Reputation Power: 0
I think you need to modify your query:

$query = "SELECT * FROM userinfo";

to:

Code:
$query = "SELECT * FROM userinfo WHERE start_date>=2006-04-10 AND end_date<=2006-04-12 LIMIT 5"


This way by passing dates you can get the recent results as well using LIMIT you can display any number of results, like the above query will extract only 5 results.[/code]
__________________
BigResource.com
Over 20,000 rated PHP, CGI, ASP, Flash and XML scripts

Reply With Quote
  #4  
Old April 16th, 2006, 01:21 AM
meat meat is offline
Contributing User
Tutorialized Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Location: San Diego
Posts: 157 meat New User: is a brand new recruit and a unknown entity at this point. 
Time spent in forums: 11 m 16 sec
Reputation Power: 0
Send a message via AIM to meat Send a message via Skype to meat
If your using a auto_increment'ed primary for ID's. You could use that to your advantage, example:

$query = "SELECT * FROM users ORDER BY user_id DESC LIMIT 1";

That will show the last thing put in the database.
__________________
Mwahaha, Eat meat!!

Runescape Database

Reply With Quote
Reply

Viewing: Tutorialized ForumsDatabasesMySQL > Fetching data from MySQL


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT