Jump to content

get single value from table


Snewzzer

Recommended Posts

Thanks Jacques1, my code(which doesn't work !) for fetching a single value is:-

 

$result= mysql_result(mysql_query("SELECT colname FROM table WHERE players = 'name'"));

 

So if I have to fetch a row, how do I extract the single value that I need?

Link to comment
Share on other sites

I suggest you start with the basics before jumping to any special features. There seems to be a lot of confusion here. You said you used mysqli, you've actually used the old ext/mysql extension, and now you've appearently switched to PDO.

 

If you want to go with PDO, learn how to establish a connection first.

Link to comment
Share on other sites

Just gave the above code example of one of dozens that I have tried, this seemed the simplest to try and convey what I was trying to achieve. I'm only trying PDO on the suggestion of Benanamen, but give me a simpler way if there is one and I will use that. Newbie, 4 years since I last wrote any code.

Link to comment
Share on other sites

What you don't seem to understand is that accessing a database requires a complete library. This isn't just one line of code which you can copy and paste. You have to establish a connection, execute a query (or in your case a prepared statement) and ultimately fetch data from the result set.

 

So the first step is to choose a library. The mysql_* functions you were using previously are hopelessly outdated and have already been removed from the current PHP version. Nowadays were're using PDO or mysqli. PDO is a good choice.

 

Now you need to learn PDO. We can't do that for you. You need to actually read and understand the tutorial referenced by benanamen.

Edited by Jacques1
Link to comment
Share on other sites

I said what I said. Now you need to read and understand it.

 

I know you're in a hurry, and reading longer texts is difficult in the era of 140-character Tweets. But if you want to write any code whatsoever, you have to be able to absorb information. Programming isn't copy-and-paste.

Link to comment
Share on other sites

Jacques1, yes I will do, and thanks for everything. But no, I'm not in a hurry, this is a personal project of no great importance. It was such a simple query that I expected there might be a simple answer. I am returning to coding after a 4 year gap, I was a newbie then and still am now, so will endeavour to learn the current correct methods.

Thanks again.

Edited by Snewzzer
Link to comment
Share on other sites

This isn't about one query, it's about an entire database library. You cannot randomly insert a PDO or mysqli method call in the middle of your code. You choose one library, and then all database operations now and in the future have to be implemented with that library. You may even have to rewrite large parts of your current code.

 

Forget about the single value stuff. This is about all of your queries.

Link to comment
Share on other sites

Jacques1, if I had to rewrite ALL of my code it wouldn't take too long! It consists of only two very short files which I only began a few nights ago. So I can throw everything out and start again... which I am doing now, starting with the php manual. Thanks.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.