note 21993 deleted from function.mysql-fetch-array by betz
| From: | betz@php.net | Date: | Sat, 10 Aug 2002 16:42:19 +0000 |
| Subject: | note 21993 deleted from function.mysql-fetch-array by betz | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-34743@lists.php.net to get a copy of this message | ||
Hi All, Just ripping my hair out. I have a piece of PHp that allows a user to login to a page. I can
then print the rest of that users details no probs. However the last column in the table is a
number. This is associated to a name/address/loaction in another table. Got the mysql query kinda
working. But i want the php to link to the other table. Heres what ive done
Log-in
<?php
$auth = false; // Assume user is not authenticated
if (isset( $PHP_AUTH_USER ) && isset($PHP_AUTH_PW)) {
// Connect to MySQL
mysql_connect( 'localhost', 'root', 'pass' )
or die ( 'Unable to connect to server.' );
// Select database on MySQL server
mysql_select_db( 'sk_orders' )
or die ( 'Unable to select database.' );
// Formulate the query
$sql = "SELECT * FROM users WHERE
username = '$PHP_AUTH_USER' AND
pass = '$PHP_AUTH_PW'";
// Execute the query and put results in $result
$result = mysql_query( $sql )
or die ( 'Unable to execute query.' );
// Get number of rows in $result.
$num = mysql_numrows( $result );
if ( $num != 0 ) {
// A matching row was found - the user is authenticated.
$auth = true;
}
}
if ( ! $auth ) {
header( 'WWW-Authenticate: Basic realm="Storage King Secure Orders"' );
header( 'HTTP/1.0 401 Unauthorized' );
echo 'Authorization Required.';
exit;
} else {
echo '<P>You are authorized!</P>';
}
?>
No Probs.
write out the rest of the table info
<?php
$myrow = mysql_fetch_array($result);
echo "<br>Name: ".$myrow["name"];
echo "<br>Date Joined: ".$myrow["date"];
echo "<br>username: ".$myrow["username"];
echo "<br>Facility: ".$myrow["facility"];
no probs
Here is where im unstuck
$facility = "select us.name, fac.facname, fac.address
from users us, facility fac
where fac.id = us.facility ";
while ($where = db_fetch_object($facility)) {
echo "<br>Facility: ".$where["facname"];
echo "<br>Facility: ".$where["address"];
I think i have to reference the user. Is that my problem. I know this is sorta easy, but i just cant
get my head around it.
Any suggestions