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
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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.