how to read data from MySQL?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
yosuke_
Forum Commoner
Posts: 64
Joined: Tue Apr 13, 2004 12:29 pm

how to read data from MySQL?

Post by yosuke_ »

Ok, dont flame me! I know, this is realy stupid question, but I only know how to instert data. can you give me some small code how to read data from database!! thank you! :oops:
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post by magicrobotmonkey »

Code: Select all

<?php
$query = "SELECT column1, column2 FROM table WHERE column3=value";
?>
yosuke_
Forum Commoner
Posts: 64
Joined: Tue Apr 13, 2004 12:29 pm

Post by yosuke_ »

I UNDER STAND THAT!!!!
But I need full code, not just one line!!
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post by magicrobotmonkey »

do it the same way you insert data, but substitue the above line for INSERT whatever
yosuke_
Forum Commoner
Posts: 64
Joined: Tue Apr 13, 2004 12:29 pm

Post by yosuke_ »

Ok, I did as you say and I get 1 in the result!!!
Heres the code!!

Code: Select all

<?
error_reporting(E_ALL); 
$db = mysql_connect('localhost','root','q54fgh546') or die(mysql_error()); 
mysql_select_db("mydatabase") or die(mysql_error()); 
$query = "SELECT firstname FROM users"; 
echo mysql_query($query) or die(mysql_error()); 

mysql_close(); 
?>
whats wrong?
yosuke_
Forum Commoner
Posts: 64
Joined: Tue Apr 13, 2004 12:29 pm

Post by yosuke_ »

Or when I echo this:

Code: Select all

echo mysql_query($query);
I get this: Resource id #2
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post by magicrobotmonkey »

you might want to give this a gander:

http://us2.php.net/manual/en/function.m ... -array.php

and the rest of the docs while you're at it!
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

look at this,

ive just answered it
jesus, theres a topic named resource ID 2 dont you even bother too look
[rant over]

viewtopic.php?t=20999
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

magicrobotmonkey wrote:you might want to give this a gander:

http://us2.php.net/manual/en/function.m ... -array.php

and the rest of the docs while you're at it!
absolutely, its no good me / us telling you what to do, you'll never learn that way, read the docs, they explain everything
yosuke_
Forum Commoner
Posts: 64
Joined: Tue Apr 13, 2004 12:29 pm

Post by yosuke_ »

Thank you soo much!!! Next time I will search!!
Post Reply