PHP SQL Select From Where


I am having some difficulty running some SQL code.

What I am trying to do is, find a row that contains the correct username, and then get a value from that correct row.

This is my SQL in the php:

mysql_query("SELECT * FROM users WHERE joined='$username' GET name")

As you can see, it looks for a username in users and then once found, it must GET a value from the correct row.

How do I do that?


You need some additional PHP code (a call to mysql_fetch_array) to process the result resource returned by MySQL.

$result = mysql_query("SELECT name FROM users WHERE joined='$username'"); $row = mysql_fetch_array($result); echo $row['name'];


mysql_query("SELECT `name` FROM users WHERE joined='$username' ")

Just select the right column in your 'select clause' like above.

Edit: If you are just starting out though, you might want to follow a tutorial like this <a href="http://www.phpeveryday.com/articles/PHP-Data-Object/PDO-Tutorial-P842.html" rel="nofollow">one</a> which should take you through a nice step by step (and more importantly up to date functions) that will get you started.


mysql_query("SELECT name FROM users WHERE joined='$username'")


$q = mysql_query("SELECT * FROM users WHERE joined='$username'"); $r = mysql_fetch_array($q); $name = $r['user_name']; // replace user_name with the column name of your table


mysql_query("SELECT name FROM users WHERE joined='$username' ")

Read documentation : <a href="http://dev.mysql.com/doc/refman/5.0/en/select.html" rel="nofollow">http://dev.mysql.com/doc/refman/5.0/en/select.html</a>


  • Are there any possible ways to ignore all paths of JPA Example Matcher
  • sql query Update INNER JOINED table
  • Executing merge statement via C# SqlCommand not working
  • PyQt - Load SQL in QAbstractTableModel (QTableView) using pandas DataFrame - editing datas in a GUI
  • output json array in php
  • Storing data from SQL in array
  • ckeditor and jquery UI dialog not working
  • Most efficient way to move table rows from one table to another
  • Add dynamic data to line chart from mysql database with highcharts
  • MYSQ & MVC3 SQL connection error \\ ProviderManifestToken but I am using MySQL
  • Get specific string
  • How does this usort cmp function actually work?
  • How does document.ready work with angular element directives?
  • Stop Bash Script if Hive Fails
  • How to add git credentials to the build so it would be able to be used within a shell code?
  • How can I sort a a table with VBA with given text condition?
  • Moving mysql files across servers
  • Lost migrations and Azure database is now out of sync
  • How to check if every primary key value is being referenced as foreign key in another table
  • MySQL WHERE-condition in procedure ignored
  • Display Images one by one with next and previous functionality
  • Upload files with Ajax and Jquery
  • ORA-29908: missing primary invocation for ancillary operator
  • Do I've to free mysql result after storing it?
  • How to get next/previous record number?
  • php design question - will a Helper help here?
  • Comma separated Values
  • A cron job substitute?
  • json Serialization in asp
  • AngularJs get employee from factory
  • How do you join a server to an Active Directory (domain)?
  • Understanding cpu registers
  • How do I configure my settings file to work with unit tests?
  • Change div Background jquery
  • How does Linux kernel interrupt the application?
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • Authorize attributes not working in MVC 4
  • Busy indicator not showing up in wpf window [duplicate]
  • Why do underscore prefixed variables exist?
  • How do I use LINQ to get all the Items that have a particular SubItem?