| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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? |
|
#2
|
|||
|
|||
|
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 |
|
#3
|
|||
|
|||
|
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] |
|
#4
|
|||
|
|||
|
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. |
![]() |
| Viewing: Tutorialized Forums > Databases > MySQL > Fetching data from MySQL |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|