simplicity with 2 queries..

From: Date: Mon, 10 Jun 2002 03:35:07 +0000
Subject: simplicity with 2 queries..
Groups: php.general 
Request: Send a blank email to php-general+get-101354@lists.php.net to get a copy of this message
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 jslootbeek@clarku.edu http://blindtheory.cjb.net

« previous php.general (#101354) next »