RE: [PHP] simplicity with 2 queries..

From: Date: Mon, 10 Jun 2002 03:37:16 +0000
Subject: RE: [PHP] simplicity with 2 queries..
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-101355@lists.php.net to get a copy of this message
Read the JOIN chapter of the MySQL manual and it'll tell you how to do it. It's not a PHP issue. (watch for line wrapping) http://www.mysql.com/documentation/mysql/bychapter/manual_Reference.html #JOIN ---John Holmes... > -----Original Message----- > From: Jule Slootbeek [mailto:jslootbeek@clarku.edu] > Sent: Sunday, June 09, 2002 11:35 PM > To: php-general > Subject: [PHP] 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 > jslootbeek@clarku.edu > > http://blindtheory.cjb.net > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.general (#101355) next »