# Using variable in SQL query

**URL:** <https://forum.kirupa.com/t/using-variable-in-sql-query/76815>\
**Category:** programming\
**Created:** [January 21, 2005, 7:44pm UTC](https://forum.kirupa.com/t/using-variable-in-sql-query/76815 "2005-01-21T19:44:43Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thinker2501](https://avatars.discourse-cdn.com/v4/letter/t/e0b2c6/32.png) [@Thinker2501](https://forum.kirupa.com/u/Thinker2501)\
**Post date:** [January 21, 2005, 7:44pm UTC](https://forum.kirupa.com/t/using-variable-in-sql-query/76815/1 "2005-01-21T19:44:43Z")

</div>

I have a database with 2 tables. I can query the first table and pull all the rows out and then are formating them into a table, similar to the tut here on kirupa. Now what I want to do is take the variable created by the first query and use it to do a second query. So I have $result\_ar[‘broker\_last\_1’] and I want to do:

$broker = mysql\_query(SELECT \* FROM brokers WHERE lastname = $result\_ar[‘broker\_last\_1’]);

I hope I explained this well and someone could show me how to write the query. thanks in advance
