Re: simplicity with 2 queries..

From: Date: Mon, 10 Jun 2002 03:36:52 +0000
Subject: Re: simplicity with 2 queries..
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-101356@lists.php.net to get a copy of this message
SELECT quiz_id FROM $table_quiz AS q, $table_user AS u WHERE q.user_id=u.user_id AND u.username='$valid_user' AND u.password='$valid_password'"; Bogdan Jule Slootbeek wrote:
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;   }


« previous php.general (#101356) next »