5 Replies - 352 Views - Last Post: 04 May 2010 - 08:19 AM Rate Topic: -----

#1 Guest_All Marx*


Reputation:

Retrieve Single Data

Posted 04 May 2010 - 07:56 AM

Hi!

I often use this command to retrieve data from mySQL

$x = mysql_query("SELECT * FROM member WHERE member='John'");
$y = mysql_fetch_array($x, MYSQL_BOTH);
echo $y[1];


The problem now is, I want to fetch only one data from a single column. it can be done using this:

$x = mysql_query("SELECT memid FROM member WHERE member='John'");
echo $x;


the problem is, when i print the result, it just show the Resource ID. How to fetch the data into a variable?

Is This A Good Question/Topic? 0

Replies To: Retrieve Single Data

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5669
  • View blog
  • Posts: 22,517
  • Joined: 23-August 08

Re: Retrieve Single Data

Posted 04 May 2010 - 08:08 AM

You still need to use a fetch!
Was This Post Helpful? 1
  • +
  • -

#3 RPGonzo  Icon User is offline

  • // Note to self: hmphh .... I forgot
  • member icon

Reputation: 150
  • View blog
  • Posts: 954
  • Joined: 16-March 09

Re: Retrieve Single Data

Posted 04 May 2010 - 08:09 AM

Your answer lies in your first code block ... in the second code block you didn't use the mysql_fetch_array function to put it into a array

$results = mysql_query("SELECT memid FROM member WHERE member='John'");
$data_array = mysql_fetch_array($results, MYSQL_BOTH);
print_r($data_array);




edit: Jack is too fast :P

This post has been edited by RPGonzo: 04 May 2010 - 08:10 AM

Was This Post Helpful? 0
  • +
  • -

#4 Guest_All Marx*


Reputation:

Re: Retrieve Single Data

Posted 04 May 2010 - 08:11 AM

hmmm... is there any better command? i mean, the one which is specific to use to fetch only one data... if i use fetch array, it'll fetch into an array... i don't think i need that~

View PostJackOfAllTrades, on 04 May 2010 - 07:08 AM, said:

You still need to use a fetch!

Was This Post Helpful? 0

#5 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5669
  • View blog
  • Posts: 22,517
  • Joined: 23-August 08

Re: Retrieve Single Data

Posted 04 May 2010 - 08:16 AM

Pick one.
Was This Post Helpful? 0
  • +
  • -

#6 Guest_All Marx*


Reputation:

Re: Retrieve Single Data

Posted 04 May 2010 - 08:19 AM

hahahaha... wokey~! i understand wt u mean :P

btw, thanks a lot for your help :)

View PostJackOfAllTrades, on 04 May 2010 - 07:16 AM, said:


Was This Post Helpful? 0

Page 1 of 1