dprichard
12-06-2010, 03:22 AM
Okay, I am not 100% sure what I am looking to do is called, but I could really use some help. First of all I am pulling from two different systems which is why I don't just do a join or a sub query for what I am doing. One is Sybase Advantage the other is MySQL so I am trying to accomplish this in PHP.
I am querying the first database and returning the results using odbc_fetch_array. My first query looks something like this.
$sql1="SELECT ticketname, locationid FROM tickets WHERE custid = '$custid'"
$rs1=odbc_exec($conn,$sql1);
I then loop through the information using the following:
while($row_rs1 = odbc_fetch_array($rs1)) {}
I need to get the name from the MySQL database for each locationid from the first query.
$locations = mysql_query("SELECT locationname FROM locations WHERE locationid = (locationid from first query)
I know that I can do a query in the loop for each location to find the location name that is stored in the mysql database, but I want to keep the load down on the server since this page gets a lot of traffic. Instead of running a query to the MySQL database each time it loops through I was wondering if there was a way to do the MySQL query once before the loop then based on the locationid from the first query looping through, get the location name from the second query that was saved into an array.
I am not sure what I am trying do is called or if it's possible, but I would really appreciate some help / direction.
Thanks so much for any help.
I am querying the first database and returning the results using odbc_fetch_array. My first query looks something like this.
$sql1="SELECT ticketname, locationid FROM tickets WHERE custid = '$custid'"
$rs1=odbc_exec($conn,$sql1);
I then loop through the information using the following:
while($row_rs1 = odbc_fetch_array($rs1)) {}
I need to get the name from the MySQL database for each locationid from the first query.
$locations = mysql_query("SELECT locationname FROM locations WHERE locationid = (locationid from first query)
I know that I can do a query in the loop for each location to find the location name that is stored in the mysql database, but I want to keep the load down on the server since this page gets a lot of traffic. Instead of running a query to the MySQL database each time it loops through I was wondering if there was a way to do the MySQL query once before the loop then based on the locationid from the first query looping through, get the location name from the second query that was saved into an array.
I am not sure what I am trying do is called or if it's possible, but I would really appreciate some help / direction.
Thanks so much for any help.