how to read data from MySQL?
Moderator: General Moderators
how to read data from MySQL?
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! 
-
magicrobotmonkey
- Forum Regular
- Posts: 888
- Joined: Sun Mar 21, 2004 1:09 pm
- Location: Cambridge, MA
Code: Select all
<?php
$query = "SELECT column1, column2 FROM table WHERE column3=value";
?>-
magicrobotmonkey
- Forum Regular
- Posts: 888
- Joined: Sun Mar 21, 2004 1:09 pm
- Location: Cambridge, MA
Ok, I did as you say and I get 1 in the result!!!
Heres the code!!
whats wrong?
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();
?>Or when I echo this:
I get this: Resource id #2
Code: Select all
echo mysql_query($query);-
magicrobotmonkey
- Forum Regular
- Posts: 888
- Joined: Sun Mar 21, 2004 1:09 pm
- Location: Cambridge, MA
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!
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
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
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
absolutely, its no good me / us telling you what to do, you'll never learn that way, read the docs, they explain everythingmagicrobotmonkey 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!