If ($result = mysql_query("SELECT * FROM $table_user, $table_quiz
WHERE
$table_quiz.user_id=$table_user.user_id
AND username='$valid_user'
AND password='$valid_password'"))
{ if ($array = mysql_fetch_array($result))
{ $quiz_id = $array["quiz_id"];
} else
{ // log in failed
}
}
I think you need to spend a bit of time on basic sql and structure
your code a bit if you want the desired result.
Tim Ward
www.chessish.com <http://www.chessish.com>
[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
----------
From: Jule Slootbeek [SMTP:[EMAIL PROTECTED]]
Sent: 10 June 2002 04:35
To: php-general
Subject: simplicity with 2 queries..
Hey guys and gals,
I have the following function which accesses the following tables,
now i want to
know if there is a way to get the quiz_id from table quiz without
runnning both
these queries...
thanks,
Jule
--tables--
mysql> describe user;
+------------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra
|
+------------+------------------+------+-----+---------+----------------+
| user_id | int(10) unsigned | | PRI | NULL |
auto_increment |
| first_name | varchar(10) | | | |
|
| last_name | varchar(20) | | | |
|
| email | varchar(100) | | | |
|
| username | varchar(16) | | | |
|
| password | varchar(32) | | | |
|
+------------+------------------+------+-----+---------+----------------+
mysql> describe quiz;
+---------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra
|
+---------+------------------+------+-----+---------+----------------+
| quiz_id | int(10) unsigned | | PRI | NULL | auto_increment
|
| user_id | int(10) unsigned | | | 0 |
|
| title | varchar(255) | | | |
|
| noa | tinyint(2) | | | 0 |
|
+---------+------------------+------+-----+---------+----------------+
--function--
function addquiz_get_quiz_id() {
global $valid_user, $valid_password;
mysql_select_db($db_glob, $link_glob);
$table_user = "user";
$table_quiz = "quiz";
$query = "SELECT * FROM $table_user WHERE
username='$valid_user' AND
password='$valid_password'";
$result = mysql_query($query);
$user_info = mysql_fetch_array($result);
$user_id = $user_info[user_id];
$query = "SELECT * FROM $table_quiz WHERE
user_id='$user_id'";
$result = mysql_query($query);
$user_info = mysql_fetch_array($result);
$quiz_id = $user_info[quiz_id];
mysql_close($link_glob);
return $quiz_id;
}
--
Jule Slootbeek
[EMAIL PROTECTED]
http://blindtheory.cjb.net
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php