-4

I currently have a php file displaying a list of unique VARCHAR items in a table on a SQL server like this:

echo "<b><center>Strain List</center></b><br><br>";

$i=0;
$priorstrain='NULL';
while ($i < $num) {
    $strain=mysql_result($result,$i,"Strain");

    if ($strain!=$priorstrain) {

        echo "<a href=result.php><b>$strain</b></a>";
    }
    $priorstrain=$strain;
    $i++;
}

I would like all items that matches $strain to display on the next page. For example, say the list displays:

CAT DOG MOUSE

and when someone clicks on DOG I want the page to redirect to a page that shows:

STRAIN OWNER DOB      COLOR 
DOG    JOHN  9/9/2015 BROWN
DOG    JEFF  10/04/2013 BLACK

What is the best way to accomplish this?

Thanks in advance!

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
Tony Ito
  • 111
  • 5
  • Don't use the deprecated `mysql_*`-functions. They are deprecated since PHP 5.5 and completely removed in PHP 7. Use MySQLi or PDO instead. Then you can also use Prepared Statements, which protects you from SQL Injections, among other things. – M. Eriksson Sep 22 '16 at 22:34
  • 2
    tack the search term on the end of each url and then access it as a GET variable on the next page. Use the GET variable to recreate the table – bassxzero Sep 22 '16 at 22:34
  • Possible duplicate of [Why shouldn't I use mysql\_\* functions in PHP?](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) – The SE I loved is dead Sep 23 '16 at 00:45

1 Answers1

2

You can use GET variables as @bassxzero said, to do this you can do like this in your code :-

if ($strain!=$priorstrain) {

        echo "<a href='result.php?strain='$strain><b>$strain</b></a>";
    } 

result.php

if(isset($_GET['strain'])) {
    //I am not doing but make sure you validate this variable first :)
    $stname = $_GET['strain'];
    //SOME CODE HERE LIKE 
    // SELECT QUERY TO SHOW ALL RESULT LIKE OWNER'S NAME, DETAILS, ETC.    
   }

Hope this will help you :)

Sunny
  • 402
  • 4
  • 15