On Tuesday, January 15, 2002, at 02:18  PM, Phil Schwarzmann wrote:

> Dumb question: How do I query results from a MySQL that I've already
> queried once before in the same page?

Look, buddy, *I* ask the dumb questions around here!

> Here is my code:
>
> // querying the database for the first time.
> $query  = "select * from table where thingA = $searchA";
> $result = mysql_query ($query);
>
> // now I want to query my results I just made.

Here's how I do it:

First of all, don't forget the second argument to mysql_query().  It 
should be a variable that contains your database connection info (see 
mysql_connect() in the function list).

Your variable "$result" is now a container for the query you just made.  
The results of the query are returned as an array stored inside this 
container ("$result").  So you need to use any of the functions which 
act on that array -- they typically begin with "mysql_fetch_".

mysql_fetch_row() -- you can use this function to grab results based on 
their numeric index.
mysql_fetch_assoc() -- you can use this function to grab results based 
on their associative index.
mysql_fetch_array() -- you can use this function to grab results using 
either the numeric or the associative index.  This one's my favorite, 
since it's flexible like that.

So how do you do it?  Here's what I do:

$query = "SELECT * FROM table WHERE thingA='$searchA'";
$result = mysql_query($query, $db);

while ($row = mysql_fetch_array($result)) {
        $thingA = $row['thingA'];   // the associative index is the column name

      print $thingA;
}


Erik


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to