Current location: Hot Scripts Forums » Programming Languages » PHP » Receive from Database. WORKS!!!!


Receive from Database. WORKS!!!!

Reply
  #1 (permalink)  
Old 02-27-05, 10:18 PM
mhs12grade1992's Avatar
mhs12grade1992 mhs12grade1992 is offline
Newbie Coder
 
Join Date: Feb 2005
Location: USA
Posts: 84
Thanks: 0
Thanked 0 Times in 0 Posts
Receive from Database. WORKS!!!!

Hello everybody!!

I have discussed some of you about my problems with database. I did INSERT INTO and CREATE TABLE that worked. But I did have problem with SELECT FROM. It always show "Array" using print and echo. Someone from here told me to use print_r($rows); and I could not get it to work. Let me tell you what.... Dummies showed me how to make it work.


$query = 'SELECT * FROM members';
include("./connect.php");
mysql_select_db(DB_NAME) or die(mysql_error());
$result=mysql_query($query);
$rows=mysql_fetch_assoc($result);
print_r($rows['username']);
mysql_close();

You must specific name into $rows['name'] in order to show real array. Otherwise it will show PHP codes.

Trust me. It works!
Now I am through.... !

You know what? Yahooooooooooo!!!!!!!!!!!!!! I am passed! I am A+
__________________
Sincerely,
MHS (Mansfield High School)

Create your own short/long story within few minutes.
Simply fill out the form and it will write the story itself.

Go to: www.storymakerpro.com

Am I rich in million or just my 2 cents poor?
Reply With Quote
  #2 (permalink)  
Old 02-28-05, 12:46 PM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
sorry to tell you, but that's not A+! I'd say D
when you specify $row['field_name'], you don't need to print_r() just echo/print()!
print_r() is used to print all the array elements in the form:
Code:
Array
(
    [filed_name] => value
)
print_r() is used for debugging ..
but we told you to use it since you constantly refused to read tuts before trying to use mysql's function..
also your code (above) only prints the first row and neglicates the others because it doesn't have a loop..
again, you refuse to read tuts to learn how to use MySQL..
no offense, but I am trying to tell you that you should learn before your attempt to use ..
it's like buying a complicated device and attempting to make it work without reading it's manual! it might work with you but it will malfunction for sure..
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Reply With Quote
  #3 (permalink)  
Old 02-28-05, 02:24 PM
mhs12grade1992's Avatar
mhs12grade1992 mhs12grade1992 is offline
Newbie Coder
 
Join Date: Feb 2005
Location: USA
Posts: 84
Thanks: 0
Thanked 0 Times in 0 Posts
Now $rows['username'] is no longer work. I tried echo, print and print_r but won't work on that array. Now I recommend to use $rows[0] as username as first column. You just said to use echo and print. Yup, it works. $rows[0] works better. I don't understand ...... $rows['username'] worked before it died. I follow Dummies book about that but it is wrong.

Look, Nevermind, I did read all through the book and I noticed few parts of the book are wrong. Very few and that author did forget something in PHP book. Now I do know how to solve the problem.

I know Bravenet does not work good. Yahoo! works fine. It is important that I learn MySQL and I have learned and often get them wrong. I read Dummies (Jeff Cogswell) and PHP and MySQL (Larry Ullman) books.

You assumed I refuse to read tutorials but you're wrong.
__________________
Sincerely,
MHS (Mansfield High School)

Create your own short/long story within few minutes.
Simply fill out the form and it will write the story itself.

Go to: www.storymakerpro.com

Am I rich in million or just my 2 cents poor?

Last edited by mhs12grade1992; 02-28-05 at 02:30 PM.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump


All times are GMT -5. The time now is 05:34 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.