Page 1 of 1
Sort by Username
Posted: Thu Feb 09, 2006 11:23 pm
by nickman013
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
------------------------
Posted: Thu Feb 09, 2006 11:24 pm
by feyd
look into GROUP BY or SELECT DISTINCT
Posted: Thu Feb 09, 2006 11:28 pm
by nickman013
Thank You!
Posted: Thu Feb 09, 2006 11:38 pm
by nickman013
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;";
Posted: Fri Feb 10, 2006 12:04 am
by feyd
you need to quote $row, at a minimum. Pass it through input filtering is ideal.
Posted: Fri Feb 10, 2006 5:03 am
by raghavan20
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;";
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']}'";
Posted: Fri Feb 10, 2006 5:11 am
by JayBird
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']}'";
Never usually a good idea and should be avoided whenever possible. Its a big security risk.
Posted: Fri Feb 10, 2006 5:19 am
by raghavan20
Pimptastic wrote: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']}'";
Never usually a good idea and should be avoided whenever possible. Its a big security risk.
you mean to say that I should use like this...
Code: Select all
$sql = "DELETE FROM `Tracker` WHERE `Screen Name` = '".mysql_real_escape_string(strip_tags($_POST['Screen Name']))."'";
Posted: Fri Feb 10, 2006 5:24 am
by JayBird
probably not like that...but i would sanitize all input at some point before putting that data in my query
Posted: Fri Feb 10, 2006 5:35 am
by raghavan20
Pimptastic wrote:probably not like that...but i would sanitize all input at some point before putting that data in my query
can you post me an example sometime later when you are free on how you clean up unwanted add ons with the input...

Posted: Fri Feb 10, 2006 11:28 am
by nickman013
Thank you all for resonding. Feyd you were right I justed needed to single quotes.