Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Old 01-13-2005, 07:30 PM   PM User | #1
yo_da84
New to the CF scene

 
Join Date: Jan 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
yo_da84 is an unknown quantity at this point
Resource ID#4?

Hi Guys,
im new to PHP and MySQL. im trying to get a very very very simple query from a MySQL db using the following code, but it keeps giving me
"Resource ID#4"

Any ideas?
###########################################
<?php
//Call the MySQL location, user and password from the mysql_db.php file//
require("mysql_db.php")
?>
<?php
$query="SELECT * FROM products";
$results=mysql_query($query)
or die(mysql_error());
echo $results;
?>
###########################################

cheers
Yo_da84
yo_da84 is offline   Reply With Quote
Old 01-13-2005, 07:44 PM   PM User | #2
raf
Master Coder


 
Join Date: Jul 2002
Posts: 6,589
Thanks: 0
Thanked 0 Times in 0 Posts
raf is on a distinguished road
welcome here!

mysql_query() returns a resource-id, which is a handle to get the actual data from the recordset. But you need to us a function like mysql_fetch_assoc() to get the actual date. The traditional code to do this is:
PHP Code:
<?php
//Call the MySQL location, user and password from the mysql_db.php file//
require("mysql_db.php")
$query="SELECT var1, var2, var3 FROM products";
// where var1 etc are the names of your columns. Never use * inside embedded sql
$result=mysql_query($query) or die('Queryproblem: ' mysql_error() . '<br />Executed query: ' $query);
if (
mysql_num_rows($result) >= '1'){
    while (
$row mysql_fetch_assoc($result)){
         echo 
$row['var1']; //to print out the value  of column 'var1' for each record
    
}
}else{
    echo 
'No records found.';
}
?>
__________________
Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html
raf is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:32 AM.

Home - Contact Us - Archives - Link to CF - Resources - Top 

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.