wsantos Posted November 19, 2007 Share Posted November 19, 2007 I'm trying to implement an array as a mysql temporary table. Then do the join based on that array. $qry="SELECT src,uid FROM table WHERE dst LIKE '$myFilter'"; $res=mysql_query($result); while($row=mysql_fetch_array($res, MYSQL_ASSOC)) $daTable[] = $row; mysql_free_result($res); $qry = "SELECT * from lookup_cid JOIN $daTable ON $daTable.uid = lookup_cid.uid"; $res=mysql_query($result); while($row=mysql_fetch_array($res, MYSQL_ASSOC)) $daTable2[] = $row; mysql_free_result($res); Quote Link to comment Share on other sites More sharing options...
teng84 Posted November 19, 2007 Share Posted November 19, 2007 what.....? :-\ Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted November 19, 2007 Share Posted November 19, 2007 you cannot do that maybe the most you can use an array in a in, but logically speaking you cannot merge them in a join them through an array you should join the tables directly in your first select SELECT * from lookup_cid JOIN table ON table.uid = lookup_cid.uid Quote Link to comment Share on other sites More sharing options...
wsantos Posted November 19, 2007 Author Share Posted November 19, 2007 Im trying to implement a subquery on php. Here is my mysql query. DROP TEMPORARY TABLE IF EXISTS tmpMain; CREATE TEMPORARY TABLE tmpMain SELECT src,uid FROM table WHERE dst LIKE 'ABC'; DROP TEMPORARY TABLE IF EXISTS tmpCID; CREATE TEMPORARY TABLE tmpCID SELECT cid FROM lookup_cid lcid JOIN tmpMain ON tmpCID.uid=lcid.uid; DROP TEMPORARY TABLE IF EXISTS tmpCP; CREATE TEMPORARY TABLE tmpCP SELECT app,appdata FROM table3 JOIN tmpCP ON tmpCP.cid=table3.cid; <- SNIP -> SELECT * from tmpFINAL; The above query (replacing the names and removing a couple of filters and a couple more steps) works on mysql. At the moment we are pulling reports using this manual subquery. The reason we used temporary tables was based on the number of tables to be joined (7 to be exact) and number of records of the database. However, it was noted on my previous post that create temporary table ... could not be implemented on php itself. Hence, I was thinking if it is possible to consider an array as a table that we can join with a mysql table. Is there is any other way around this situation? Thank you for pointing me in the right direction Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted November 19, 2007 Share Posted November 19, 2007 I think it would work if you fire the statements seperately mysql_query("DROP TEMPORARY TABLE IF EXISTS tmpMain"); mysql_query("CREATE TEMPORARY TABLE tmpMain SELECT src,uid FROM table WHERE dst LIKE 'ABC'"); and so on then have your select query to select the records Quote Link to comment Share on other sites More sharing options...
wsantos Posted November 19, 2007 Author Share Posted November 19, 2007 Tried that bro but to no avail. It gave me an error that the temporary table does not exist. Quote Link to comment Share on other sites More sharing options...
wsantos Posted November 19, 2007 Author Share Posted November 19, 2007 Aarrggghhhh...Guess have to close this until I come up with another idea. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.