shaung Posted December 24, 2013 Share Posted December 24, 2013 I want to pull two columns, one from each table, in one sql statement. They have no relation to each other. It is to populate two dropdown lists. How can I make this happen? I keep getting errors. Thanks Quote Link to comment Share on other sites More sharing options...
Barand Posted December 24, 2013 Share Posted December 24, 2013 Use two separate queries in that case Quote Link to comment Share on other sites More sharing options...
shaung Posted December 24, 2013 Author Share Posted December 24, 2013 (edited) Use two separate queries in that case OK, and one more question. I am trying to choose sql queries in an if statement, but mysql doesn't like it. Alternatively, I am putting the PDO stuff into a function and passing the query in, but that isn't working either. Is there a way to do this without having to write separate PDO code for each query? I want to do something like this: try { if(trueOrfalse) { $sql = "SELECT * FROM myTable"; } else{ $sql = "SELECT * FROM someOtherTable"; } $stmt = $dbh->prepare($sql); $stmt->execute(); $arrValues = $stmt->fetchAll(PDO::FETCH_ASSOC); $row = $stmt->fetch(); } catch(PDOException $e) { die($e->getMessage()); } But I keep getting a syntax error message. Apparently sql doesn't like it. Thanks. Edited December 24, 2013 by shaung Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted December 25, 2013 Share Posted December 25, 2013 (edited) Is there a way to do this without having to write separate PDO code for each query? to reuse code, you would write a general purpose function or class method that accepts the input values, runs the necessary code, and returns the expected result back to the calling program. in those cases where you tried something and got errors, you would need to post the code and the error to get help. Edited December 25, 2013 by mac_gyver Quote Link to comment Share on other sites More sharing options...
fenway Posted December 28, 2013 Share Posted December 28, 2013 Assuming it truly goes into the "same dropdown", you might get away with some version of UNION. 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.