jdt05 Posted August 6, 2007 Share Posted August 6, 2007 Hey everybody, been reading for a little bit and I'm very new to PHP but have been coding for quite a while. Was hoping that you guys could give me a hand. Coding a with a postgresql database I'm using the following simple code. $result = pg_query("SELECT question, finished FROM event WHERE eventID='".$eveID."';"); $entry = pg_fetch_array($result); $question = $entry['question']; $finished = $entry['finished']; $result = pg_query("SELECT optionID, optionText FROM options WHERE eventID='".$eveID."';"); $entry = pg_fetch_array($result); print $entry['optionID']; The first query returns values into $question and $finished, i tested this with echo/print. But after the next query the print statement does nothing, there is no data there. BUT I know the relevant data is in the database under those names because I can run the query in pgAdmin and it gives results directly from the database. Thanks for any help, I really appreciate it, its doing my head in! jdt Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted August 6, 2007 Share Posted August 6, 2007 run the query in your db admin app and see if any errors are returned - if not see what the results are... the code looks fine to me so it SHOULD work... you could try leaving out the semi-colon that is in the query string but that should not matter. Quote Link to comment Share on other sites More sharing options...
Crew-Portal Posted August 6, 2007 Share Posted August 6, 2007 $result = pg_query("SELECT question, finished FROM event WHERE eventID='".$eveID."';"); $entry = pg_fetch_array($result); $question = $entry['question']; $finished = $entry['finished']; $result = pg_query("SELECT optionID, optionText FROM options WHERE eventID='".$eveID."';"); $entry = pg_fetch_array('$result'); print "$entry['optionID']"; Quote Link to comment Share on other sites More sharing options...
jdt05 Posted August 6, 2007 Author Share Posted August 6, 2007 Yeah, I've already put it into pgAdmin and I get no errors and it returns the data with the correct names. I have no idea whats going on, I'll have to have a rethink but some things maybe. Thanks, jT Quote Link to comment Share on other sites More sharing options...
AndyB Posted August 6, 2007 Share Posted August 6, 2007 Simplify the code. Change: $result = pg_query("SELECT optionID, optionText FROM options WHERE eventID='".$eveID."';"); $entry = pg_fetch_array($result); print $entry['optionID']; to: $query = "SELECT optionID, optionText FROM options WHERE eventID='".$eveID."'"; echo $query. "<br/>"; // at least you'll know exactly what it is $result = pg_query($query); // add or die, etc error trap $entry = pg_fetch_array($result); print $entry['optionID']; What you think is the query may work; what the query really is isn't working. At least with the above you'll know just what the query was. 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.