Sort by Username
Moderator: General Moderators
- nickman013
- Forum Regular
- Posts: 764
- Joined: Sun Aug 14, 2005 12:02 am
- Location: Long Island, New York
Sort by Username
Hello,
I have a database for tracking screen names that click my link.
It works.
However I was wondering what the mySQL query would be if I wanted to display just one line for each screen name.
Like right now I am just displaying all the rows and stuff in a html table. I just want to sort it out so It only views one line per screen name.
My database view
------------------------
Nicky
-----
Nicky
-----
Joe
-----
Nicky
-----
Nicky
-----
Nicky
------------------------
I want to make it look like this
------------------------
Nicky
-----
Joe
------------------------
I have a database for tracking screen names that click my link.
It works.
However I was wondering what the mySQL query would be if I wanted to display just one line for each screen name.
Like right now I am just displaying all the rows and stuff in a html table. I just want to sort it out so It only views one line per screen name.
My database view
------------------------
Nicky
-----
Nicky
-----
Joe
-----
Nicky
-----
Nicky
-----
Nicky
------------------------
I want to make it look like this
------------------------
Nicky
-----
Joe
------------------------
- nickman013
- Forum Regular
- Posts: 764
- Joined: Sun Aug 14, 2005 12:02 am
- Location: Long Island, New York
- nickman013
- Forum Regular
- Posts: 764
- Joined: Sun Aug 14, 2005 12:02 am
- Location: Long Island, New York
I actually need one more thing. How would I delete all the username that are "Nicky"
My query I am running now is
My query I am running now is
Code: Select all
$row = $_POST['Screen Name'];
$sql = "DELETE FROM `Tracker` WHERE `Screen Name` = $row;";- raghavan20
- DevNet Resident
- Posts: 1451
- Joined: Sat Jun 11, 2005 6:57 am
- Location: London, UK
- Contact:
you can directly put $_POST variable in the query itself which would save a variable space....nickman013 wrote:I actually need one more thing. How would I delete all the username that are "Nicky"
My query I am running now is
Code: Select all
$row = $_POST['Screen Name']; $sql = "DELETE FROM `Tracker` WHERE `Screen Name` = $row;";
Code: Select all
$sql = "DELETE FROM `Tracker` WHERE `Screen Name` = '{$_POST['Screen Name']}'";Never usually a good idea and should be avoided whenever possible. Its a big security risk.raghavan20 wrote:you can directly put $_POST variable in the query itself which would save a variable space....Code: Select all
$sql = "DELETE FROM `Tracker` WHERE `Screen Name` = '{$_POST['Screen Name']}'";
- raghavan20
- DevNet Resident
- Posts: 1451
- Joined: Sat Jun 11, 2005 6:57 am
- Location: London, UK
- Contact:
you mean to say that I should use like this...Pimptastic wrote:Never usually a good idea and should be avoided whenever possible. Its a big security risk.raghavan20 wrote:you can directly put $_POST variable in the query itself which would save a variable space....Code: Select all
$sql = "DELETE FROM `Tracker` WHERE `Screen Name` = '{$_POST['Screen Name']}'";
Code: Select all
$sql = "DELETE FROM `Tracker` WHERE `Screen Name` = '".mysql_real_escape_string(strip_tags($_POST['Screen Name']))."'";- raghavan20
- DevNet Resident
- Posts: 1451
- Joined: Sat Jun 11, 2005 6:57 am
- Location: London, UK
- Contact:
- nickman013
- Forum Regular
- Posts: 764
- Joined: Sun Aug 14, 2005 12:02 am
- Location: Long Island, New York