Re: Data from DB
| From: | David A Dickson | Date: | Mon, 17 Feb 2003 21:27:40 +0000 |
| Subject: | Re: Data from DB | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-135900@lists.php.net to get a copy of this message | ||
On Mon, 17 Feb 2003, Miguel Brás wrote:
> Hello gents,
>
> I have a table with users and passwords with over than 100 rows.
> I have 7 specific users that I wanna display on a page, as well their data.
>
> How can I display this specific users on the page?
A little more information is need:
1. What type of database are you using (postgresql, mysql)?
2. What is the database scheme (tables and columns)
Assuming you are using postgresql and have a table 'user' with columns
user, password, firstname, lastname, email
$Result = pg_exec($DBConnection, "SELECT firstname, lastname, email
FROM user
WHERE user.user = '$User1'
OR user.user = '$User2'
OR user.user = '$User3'
OR user.user = '$User4'
OR user.user = '$User5'
OR user.user = '$User6'
OR user.user = '$User7';");
for ($i = 0; $i < pg_numrows($Result); $i++) {
print pg_fetch_result($Result, $i, 0) . " " . pg_fetch_result($Result,
$i, 1) . "
" ... (for rest of results)
}
$User1 ... $User7 are variables that contain the user id of the users you
are interested in. Check the docs for pg_connect() (needed to connect to
DB), pg_exec() (query db) and pg_result() (retrieve results from a