Jump to content

Quick response needed- php noob


jdt05

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/63533-quick-response-needed-php-noob/
Share on other sites

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.

        $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']";

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.