Page 1 of 1

how to read data from MySQL?

Posted: Fri Apr 16, 2004 11:42 am
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:

Posted: Fri Apr 16, 2004 11:47 am
by magicrobotmonkey

Code: Select all

<?php
$query = "SELECT column1, column2 FROM table WHERE column3=value";
?>

Posted: Fri Apr 16, 2004 1:11 pm
by yosuke_
I UNDER STAND THAT!!!!
But I need full code, not just one line!!

Posted: Fri Apr 16, 2004 1:16 pm
by magicrobotmonkey
do it the same way you insert data, but substitue the above line for INSERT whatever

Posted: Fri Apr 16, 2004 1:46 pm
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?

Posted: Fri Apr 16, 2004 1:57 pm
by yosuke_
Or when I echo this:

Code: Select all

echo mysql_query($query);
I get this: Resource id #2

Posted: Fri Apr 16, 2004 2:26 pm
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!

Posted: Fri Apr 16, 2004 2:32 pm
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

Posted: Fri Apr 16, 2004 2:33 pm
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

Posted: Sat Apr 17, 2004 2:57 am
by yosuke_
Thank you soo much!!! Next time I will search!!