Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Computer Forums > Programmers Lounge > Programming Discussions » need a hand with my PHP assignment
Closed Thread
Old 07-11-2007, 12:50 AM   #1 (permalink)
 
Newb Techie

Join Date: Jun 2007

Location: Australia

Posts: 10

Scorpion is on a distinguished road

Send a message via MSN to Scorpion Send a message via Skype™ to Scorpion
Angry need a hand with my PHP assignment

Ok, what I'm trying to do is connect to a database and run a simple query, but i keep getting "Resource id #3" printed in the browser. I even simplified the query down to a simple select * from table but the message still comes help. Here is the code:

$link=pg_connect("dbname=msg user=user");

//connect to database

$query="select * from messages";

//selects all from the database where the start date (start_date) is the current date calculated above

$result=pg_exec($link,$query);

//execs the query

print($result);

//displays the results in the browser

Please help as I really need this stupid thing to work.
Scorpion is offline  
Old 07-11-2007, 06:09 PM   #2 (permalink)
 
Monster Techie

Join Date: May 2004

Location: Tucson, AZ, USA

Posts: 1,183

Vormund

Send a message via AIM to Vormund Send a message via MSN to Vormund Send a message via Yahoo to Vormund
Default Re: need a hand with my PHP assignment

Is pg_exec the same as pg_execute? The PHP manual doesn't show pg_exec is why I ask.

Are you sure the connection is being made? A simple check right after it,

if ( !$link ) echo "No connection to the server."

PHP's site also as an example of using the pg_ stuff here, which also uses the pg_prepare. I haven't done anything with PostgreSQL though...:freak:
__________________
Vormund is offline  
Old 07-12-2007, 06:07 AM   #3 (permalink)
 
Newb Techie

Join Date: Jun 2007

Location: Australia

Posts: 10

Scorpion is on a distinguished road

Send a message via MSN to Scorpion Send a message via Skype™ to Scorpion
Default Re: need a hand with my PHP assignment

Our teacher has only taught us about the way I did it. I'll give that a try tomorrow and let you know. Thanks
Scorpion is offline  
Old 07-17-2007, 02:51 PM   #4 (permalink)
 
Ultra Techie

Join Date: Sep 2005

Posts: 638

tommyboy123x is on a distinguished road

Send a message via AIM to tommyboy123x
Default Re: need a hand with my PHP assignment

i had that before but it was with cookies or sessions and not saying session_start() or messing up the quotes

just for future reference try using the right syntax for ur code... meaning capitolize the key words and putting `'s outside of your table name and such

Basically from what i see php says "resource id" when it cannot really display the variable? try saying something more like:

echo $result[0];

it also might be relevent to show the table structure / data inside if it was conflicting with something especially quotes
__________________

Some real (as in actual) surveys that pay money!
tommyboy123x is offline  
Old 07-17-2007, 03:36 PM   #5 (permalink)
mademokid's Avatar
 
Newb Techie

Join Date: Jun 2007

Posts: 28

mademokid is on a distinguished road

Default Re: need a hand with my PHP assignment

Tommyboy is right.

You need to tell the code which row you want the data to come from. Eg. echo $result[0]; will get the data from row 0.


Try:
PHP Code:
$link=pg_connect("dbname=msg user=user");

//connect to database

$query="select * from messages";

//selects all from the database where the start date (start_date) is the current date calculated above

$result=pg_exec($link,$query);

//execs the query

echo $result[0];

//displays the results in the browser 

mademokid is offline  
Old 07-17-2007, 04:48 PM   #6 (permalink)
 
Monster Techie

Join Date: May 2004

Location: Tucson, AZ, USA

Posts: 1,183

Vormund

Send a message via AIM to Vormund Send a message via MSN to Vormund Send a message via Yahoo to Vormund
Default Re: need a hand with my PHP assignment

No you don't. Printing the $result variable will likely say what it is (or should be, in this case) - an Array. Granted that's not useful, but it has nothing to do with his error.

With that comment aside, a nice command to know is print_r: it will neatly print out any given array, or if you don't know what it is, var_dump will spit out whatever it's holding.
__________________
Vormund is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
New Site Project - Flash + PHP + MySQL + CSS theone_trent Web Graphics, Design, Digital Images 2 06-30-2007 01:12 PM
Need a good captcha generating php script surut Windows Operating Systems and Software 1 05-26-2007 09:23 AM
PHP captcha script needed iorgus Programming Discussions 2 05-20-2007 01:33 PM
PHP 2-player game? thejeremy Programming Discussions 4 04-09-2007 06:01 PM
Remote file access w/ IP + PHP? thejeremy Programming Discussions 2 04-04-2007 05:24 PM