homepage Welcome to WebmasterWorld Guest from 54.166.100.8
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Mysql Select from db Problem
I am having problem getting a "select from db" to work.
Farmernate




msg:1254998
 11:34 pm on Mar 13, 2004 (gmt 0)

Hi, I'm writing a guestbook and I got stuck on the part of the script that selects the posts from the database (mysql) and prints it to the page. The code is below:

$result = mysql_query("SELECT * FROM table_name WHERE active ='1'");
$row = mysql_fetch_array($result);
print "$row";

This is a very basic script, I'll add the bells and whistles later but first I need to get this part to work. When I go to this page with my browser, I get the meta title tag but nothing in the body of the browser (I just get a blank screen).
Questions:
1. Yes, I have included the database information in an include.
2. Yes, there is a post in the db with active set to 1.

Any suggestions?

 

justageek




msg:1254999
 11:53 pm on Mar 13, 2004 (gmt 0)

Is active a character field? If not then remove the quotes.

Also your print is trying to print an array and not a value. It should be something like:

print $row['whatever_field_name'];

My guess though is that the query is failing or you probably would have seen the word 'array' on the output.

JAG

Farmernate




msg:1255000
 2:57 am on Mar 14, 2004 (gmt 0)

Thanks for the help! Tomorrow afternoon, I'll try to test the following code:

$result = mysql_query("SELECT * FROM table_name WHERE active = 1");
$row = mysql_fetch_array($result);
print $row['whatever_field_name'];

Thanks again!

Farmernate




msg:1255001
 1:38 pm on Mar 14, 2004 (gmt 0)

It still doesn't work. Any other suggestions?

Paul in South Africa




msg:1255002
 2:02 pm on Mar 14, 2004 (gmt 0)

Try adding or die (mysql_error()) to your query to see if it is working.

Farmernate




msg:1255003
 10:21 pm on Mar 14, 2004 (gmt 0)

Okay, I tried

$result = mysql_query("SELECT * FROM table_name WHERE active = 1") or die (mysql_error());
$row = mysql_fetch_array($result);
print $row['whatever_field_name'];

But it still didn't print anything...

Farmernate




msg:1255004
 10:30 pm on Mar 14, 2004 (gmt 0)

Hey... Wait... I took off the "where active = 1" part and it works. Let me check the MySQL Database...

Ah, yes... when I changed active to 1, it didn't "take". It works with the active part now. Sorry about that and thanks for the help!

Now I'm off to try to make a script that will generate an html table with this information in it... Shouldn't be too hard...

bobnew32




msg:1255005
 11:18 pm on Mar 14, 2004 (gmt 0)

Change it to

where active= '1'";

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved