JSHINER Posted May 1, 2007 Share Posted May 1, 2007 I am trying to do the following: If the selection = /index.php?var=ABC&var2=123 It will query table "table_ABC" and select rows with "123" using the follwing function: function GoGet($db, $var= false, $var2= false) { $arr = $db->getArray("SELECT * FROM table_$var WHERE table_$var.var2 = $var2 ORDER BY var2 ASC"); return $arr; } $page['goget'] = GoGet($db, $_GET['var'], $_GET['var2']); However, it is not returning any results. Do I have an error somewhere? Link to comment https://forums.phpfreaks.com/topic/49480-solved-query-table-based-on-user-selection/ Share on other sites More sharing options...
trq Posted May 1, 2007 Share Posted May 1, 2007 $arr = $db->getArray("SELECT * FROM table_$var WHERE $var2 = '$var2' ORDER BY $var2 ASC"); You really ought to put some error handling within that function too. Link to comment https://forums.phpfreaks.com/topic/49480-solved-query-table-based-on-user-selection/#findComment-242514 Share on other sites More sharing options...
JSHINER Posted May 1, 2007 Author Share Posted May 1, 2007 I was just about to edit to explain why I had table_$var.$var2 .. I am using multiple tables - here is the full function: function GoGet($db, $var= false, $var2= false) { $arr = $db->getArray("SELECT * FROM table_$var, View_Member, View_Office WHERE table_$var.FIELD = '$var2' AND table_$var.LIST_AGENT = View_Member.ID AND table_$var.LIST_OFFICE = View_Office.MLS_Number ORDER BY LIST_PRICE ASC"); return $arr; } When I put a table_ABC instead of table_$var that function works fine. Also, what type of error handling would you suggest? Link to comment https://forums.phpfreaks.com/topic/49480-solved-query-table-based-on-user-selection/#findComment-242524 Share on other sites More sharing options...
trq Posted May 1, 2007 Share Posted May 1, 2007 Try wrapping $var with {}. eh {$var}, though it should work without it. Link to comment https://forums.phpfreaks.com/topic/49480-solved-query-table-based-on-user-selection/#findComment-242526 Share on other sites More sharing options...
JSHINER Posted May 1, 2007 Author Share Posted May 1, 2007 Still nothing. Strange thing is, if I put '$var' I get an error - and in the error it says table_'ABC' so it is inserting them correctly, which is why I can not figure out why it is not displaying the results. Link to comment https://forums.phpfreaks.com/topic/49480-solved-query-table-based-on-user-selection/#findComment-242534 Share on other sites More sharing options...
trq Posted May 1, 2007 Share Posted May 1, 2007 Well, like I said, if you put some error handling within the function you may be able to narrow it down some. Something like.... <?php function GoGet($db, $var= false, $var2= false) { $sql = "SELECT * FROM table_$var, View_Member, View_Office WHERE table_$var.FIELD = '$var2' AND table_$var.LIST_AGENT = View_Member.ID AND table_$var.LIST_OFFICE = View_Office.MLS_Number ORDER BY LIST_PRICE ASC"; if ($arr = $db->getArray($sql)) { return $arr; } else { echo "Query failed $sql"; return false; } } ?> Though Im not sure how much we can relie on getArray returning false on error either if this function is anything to go by. Also, how are you calling and tring to display the results? Link to comment https://forums.phpfreaks.com/topic/49480-solved-query-table-based-on-user-selection/#findComment-242543 Share on other sites More sharing options...
JSHINER Posted May 1, 2007 Author Share Posted May 1, 2007 SORRY! Stupid error on my part... require('WRONG_PAGE_IDIOT'); will do it every time! Thanks for the help! Link to comment https://forums.phpfreaks.com/topic/49480-solved-query-table-based-on-user-selection/#findComment-242547 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.