-1

Problem solved

The answer was

$query = "SELECT manager FROM tablename WHERE manager='$manager'";

Subtle difference, but removing the dots before and after $manager was the answer.

Credit to PHPFreaks.com

I had this;

<?php include 'dbdetails.php';  

$id = mysql_real_escape_string($_GET['id']);  

$query = 'SELECT `column` FROM `tablename` WHERE `id` = '.$id.' ';  

$result = mysql_query($query);  

$row = mysql_fetch_array($result);  

echo $row['column'];  

?>

(taken from here)

This works fine if I am solely working with an ID, however I have repeated values in the column I need to work with so ID will not work for what I am trying to achieve.

Essentially I am trying to create pages on the fly using the Manager column as the query as opposed to the ID.

What would be the correct way to achieve this? I presume DISTINCT comes into play?

I am aiming for;

<a href="sitename.com/?manager=Micky Adams">Micky Adams</a>

as my structure, where it fetches all instances of Micky Adams or whichever manager name is set up as the anchor.

Community
  • 1
  • 1
  • $id = mysql_real_escape_string($_GET['id']); why you use escape for int? Use casting or intval($id); And quit mysql_* functions they are depracated! You should use column that is your primary key. – Robert May 10 '13 at 10:37
  • Hi Robert thanks for your answer, the code was taken from a different [link](http://stackoverflow.com/questions/5175588/how-do-i-create-a-unique-php-page-for-each-row-in-a-mysql-database) thread, I am not proficient at PHP or the attributes of the queries – Safcblogger May 10 '13 at 10:41
  • 1
    i dont get your problem, just change id to manager in sql query,but this time you have more results so loop over them? – Bojan Kovacevic May 10 '13 at 10:42
  • Hi Bojan, I am still very much a newb when it comes to MySQL and only working with what I find elsewhere for reference. What I am trying to achieve is distinct results from the column using pages on the fly using a different column other than ID as referenced in the linked thread in my question. Thanks – Safcblogger May 10 '13 at 10:49
  • 1
    to get you started, learn about [PDO](http://wiki.hashphp.org/PDO_Tutorial_for_MySQL_Developers) or [Mysqli](http://codular.com/php-mysqli) so you dont use deprecated function. All basic stuff are there,including looping through resultset. – Bojan Kovacevic May 10 '13 at 10:52
  • Thanks Bojan for taking the time to link that up, I will read through and learn from those resources, very much appreciated. – Safcblogger May 10 '13 at 10:57
  • i still dont get what you want? all columns from table where manager is "Micky Adams"? all different managers (if that is the case,you dont need where), ... How does you table structure looks like? Put that here,and example of resultset you want. – Bojan Kovacevic May 10 '13 at 10:58

1 Answers1

0

If you changed it to:

$manager = $_GET['manager'];  
$query = 'SELECT `column` FROM `tablename` WHERE `manager` = '.$manager.' ';

Wouldn't that achieve what you want? If you had more than one instance of the manager DISTINCT only partly helps depending how your data is actually stored.

Ian
  • 1,622
  • 11
  • 16