Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pass query result into a variable and use it in additional query?

Status
Not open for further replies.

Apollo6

Technical User
Jan 27, 2000
418
US
I have the following query that is using a variable from a previous page (User Input AS $ss_num):

$query1 = "SELECT Emp_hed.emph_emp_code
FROM Emp_hed
WHERE ((Emp_hed.emph_ssc_nbr)='$ss_num')";

$result1 = odbc_exec($connect, $query1);

The results will be a SINGLE record, Employee#. I then want to use the results to execute an additional query:

$query2 = "SELECT whatever...
FROM table...
WHERE field='$result1'";

I am not returning any results from my second query??? I can echo $result1 and it is getting the data but when used in the second query, it seems as if it is empty???

Thanks in advance for any help.
 
The general order of operations for database access in PHP is:[ol][li]Connect to the database, getting a database handle.[/li][li]Issue a query into the database handle, getting a resource handle.[/li][li]Fetch data from the resource handle.[/li][/ol]

$result1 is not data from the query -- it is a handle to the result set. You haven't actually fetched any data.

Take a look at odbc_fetch_row() ( Want the best answers? Ask the best questions: TANSTAAFL!
 
sleipnir214:

That was the ticket!!!

Still learning...Thanks for the help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top