Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP Mysql retrieve data and process 1

Status
Not open for further replies.

iainm2

IS-IT--Management
Jun 13, 2002
38
GB
Hi
I am attempting to get the data from one column of a mySQL database back to php and use implode to arrange it into a string to insert into a script. The script part runs perfectly when the info is input manually but I am unable to get the mySQL to PHP bit working. The code is as follows:

$db = mysql_connect("localhost", "root", "irnbru");

mysql_select_db("helpdesk_calls",$db);

$query = 'SELECT calls FROM Yr2004';

$r = mysql_query($query);

$string = implode (", ", $r);

Many thanks.

mySQL, PHP and Abyss web server running on a Windows 2000 platform.
 
mysql_query() does not return the data from the database. It returns a handle to the data. You need to use one of the mysql_fetch_*() functions to fetch the data through the handle.

See the PHP online manual entries for mysql_fetch_array(), mysql_fetch_assoc() or mysql_fetch_object() for example code.



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Thanks sleipnir214
I have tried using mysql_fetch_array but I didn't understand how to make it work properly I guess. I could only get the first row returned twice. Sorry to be a pain but I have read the PHP online and am none the wiser.
 
I have a FAQ about this topic: faq434-3850
 
It's difficult to advise you without knowing what it was you tried to do.

As all the PHP manual pages state, each of the mysql_fetch_* functions fetches one row from the result set created by your SELECT query.

All of the mysql_fetch_* functions will either return a data structure containing data from a one row of a result set or will return FALSE.

If you look at the example code on all the pages I specified, you will notice that all of the example code fetches multiple rows through the use of a while loop.





Want the best answers? Ask the best questions!

TANSTAAFL!!
 
use:
Code:
$r = mysql_query($query);
$date = mysql_result($r, 0, "column_name_for_data_you_need");
 
Thanks to you all - the FAQ was just the ticket - I now have the result I was hoping for.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top