Welcome to WebmasterWorld Guest from 54.204.74.171

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Mysql Select from db Problem

I am having problem getting a "select from db" to work.

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

10+ Year Member



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?

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

WebmasterWorld Senior Member 10+ Year Member



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

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

10+ Year Member



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!

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

10+ Year Member



It still doesn't work. Any other suggestions?
2:02 pm on Mar 14, 2004 (gmt 0)

10+ Year Member



Try adding or die (mysql_error()) to your query to see if it is working.
10:21 pm on Mar 14, 2004 (gmt 0)

10+ Year Member



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

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

10+ Year Member



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

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

10+ Year Member



Change it to

where active= '1'";