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); Link to comment https://forums.phpfreaks.com/topic/77884-solved-array-as-a-temporary-table/ Share on other sites More sharing options...
teng84 Posted November 19, 2007 Share Posted November 19, 2007 what.....? :-\ Link to comment https://forums.phpfreaks.com/topic/77884-solved-array-as-a-temporary-table/#findComment-394229 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 Link to comment https://forums.phpfreaks.com/topic/77884-solved-array-as-a-temporary-table/#findComment-394231 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 Link to comment https://forums.phpfreaks.com/topic/77884-solved-array-as-a-temporary-table/#findComment-394237 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 Link to comment https://forums.phpfreaks.com/topic/77884-solved-array-as-a-temporary-table/#findComment-394240 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. Link to comment https://forums.phpfreaks.com/topic/77884-solved-array-as-a-temporary-table/#findComment-394243 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. Link to comment https://forums.phpfreaks.com/topic/77884-solved-array-as-a-temporary-table/#findComment-394263 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.