Avatar of PSTCAT
PSTCATFlag for United Kingdom of Great Britain and Northern Ireland

asked on 

Retrieving user information from database - help

Right, my code that I have written will retrieve the records from the database table containing the users
but I only want to display the details of the user logged in rather than all of the users.

I can't seem to work out how to change it so it only displays the logged in user.

<?php
include("database.php");

$query = "SELECT * FROM user ";
$result = mysql_query($query);
$num = mysql_num_rows ($result);
mysql_close();

if ($num > 0 ) {
$i=0;
while ($i < $num) {
$FirstName = mysql_result($result,$i,"FirstName");
$Surname = mysql_result($result,$i,"Surname");
$DOB = mysql_result($result,$i,"DOB");
$City = mysql_result($result,$i,"City");
$Postcode = mysql_result($result,$i,"Postcode");
$WebAddress = mysql_result($result,$i,"WebAddress");
$USER_ID = mysql_result($result,$i,"USER_ID");

echo "<b>First Name:</b> $FirstName<br>";
echo "<b>Surname:</b> $Surname<br>";
echo "<b>Date of Birth:</b> $DOB<br>";
echo "<b>City:</b> $City<br>";
echo "<b>Postcode:</b> $Postcode<br>";
echo "<b>Website:</b> $WebAddress<br>";
echo "<a href=\"account_save.php?id=$USER_ID\">Update</a>";
echo "<br><br>";

++$i; } } else { echo "The database is empty"; }

?>

Open in new window


Your help is much appreciated.
Thank you.
Scripting Languages

Avatar of undefined
Last Comment
PSTCAT
ASKER CERTIFIED SOLUTION
Avatar of maeltar
maeltar
Flag of United Kingdom of Great Britain and Northern Ireland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of maeltar
maeltar
Flag of United Kingdom of Great Britain and Northern Ireland image

NOTE  Line 3 should read
while ( $row = mysql_fetch_array($result) )

Open in new window

Avatar of PSTCAT
PSTCAT
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

Hi,

Thanks for your reply,

That code works for displaying the user's information
but I am still getting the other users in the table being displayed on the page.

Avatar of maeltar
maeltar
Flag of United Kingdom of Great Britain and Northern Ireland image

how do you know what user is logged in ?
As in is there a variable set to a value ?
SOLUTION
Avatar of maeltar
maeltar
Flag of United Kingdom of Great Britain and Northern Ireland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of PSTCAT
PSTCAT
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

I see where you are going with that.

Thank you.
Scripting Languages
Scripting Languages

A scripting language is a programming language that supports scripts, programs written for a special run-time environment that automate the execution of tasks that could alternatively be executed one-by-one by a human operator. Scripting languages are often interpreted (rather than compiled). Primitives are usually the elementary tasks or API calls, and the language allows them to be combined into more complex programs. Environments that can be automated through scripting include software applications, web pages within a web browser, the shells of operating systems (OS), embedded systems, as well as numerous games. A scripting language can be viewed as a domain-specific language for a particular environment; in the case of scripting an application, this is also known as an extension language.

30K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo