0

I have a table which contains:

transaction_id | the_pet | name_of_the_owners
    1               dog        shiela
    2               dog         ben
    3               dog         alice
    4               cat         jonathan

and on my query:

$query="select * from table ORDER BY name_of_the_owner limit 5";
$r=mysqli_query($query);
    while ($row=mysqli_fetch_array($r)) {

     echo "<tr>";
     echo "<td><a href='../php/ownersname.php?the_pet=".$row['the_pet']."'>".$row['the_pet']."</a></td>";
     echo "</tr>";
   }

However, when I use the $query, it shows all the data from the table. What I need is this:

     the_pet
  dog (hyperlink)
  cat (hyperlink)

So whenever I click on the hyperlink, the name_of_the owners will be shown in another page

for the dog when clicked

name_of_the_owners
    shiela
    ben
    alice

I already used

$query = "SELECT MAX(transaction_id) as transaction_id, the_pet GROUP BY the_pet, name_of_the_owners;

but when I clicked on the hyperlink, it doesn't show the owners. :(

1
  • @Fred: yes.but when i use the select max the hyperlink does not function :( which is my problem Commented Jan 14, 2014 at 1:41

1 Answer 1

1

so if I understand it right you dont want to show duplicates right ?

I think the best way to do this, is to change your select query to

$query = "SELECT DISTINCT the_pet FROM table";

and if you dont want to do that you could filter a array for duplicates

like so:

$arr = array('php','jsp','asp','php','asp');
$unique = array_unique($arr);
print_r($dups);

both will do the trick!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.