search problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • huda89
    New Member
    • Oct 2012
    • 31

    search problem

    Hi,
    I do the search function, when enter the search keyword and click button find, the lists of item display.
    But the problem is i would like to do something like this, when i click one of the list items, it will redirect to another page that display details of the clicked items.
    Can someone help me please? Thank you :)

    Below the code that i had done so far
    Code:
    <?php
    mysql_connect ("localhost", "root","")  or die (mysql_error());
    mysql_select_db ("ware1");
     
    $term = $_POST['term'];
     
    $sql = mysql_query("select * from equip_ments where serial_num like '%$term%' or component_1 like '%$term%'");
     
    while ($row = mysql_fetch_array($sql)){
    ?>
    
    <?php
        $id=$row[ 'product_id'];
        $component =$row['component_1'];
    	$serialnum=$row['serial_num'];
    	$ID=$row['product_id'];
        //echo 'Product ID: '.$ID;
        //echo '<br/> Serial Number: '.$row['serial_num'];
        //echo '<br/> Item: '.$row['item_1'];
        //echo '<br/> Date In: '.$row['date_in'];
    	//echo '<br></br>';
    	//echo "<ul>\n"; 
    echo "<li>" . "<a href=\"search1.php?id=$id\">"  .$id . " " . $serialnum . "</a></li>\n";
    echo "</ul>";
        }
    	
    	
    if(isset($_GET['id'])){
    $contactid=$_GET['id'];
    
    //connect to the database
    $db=mysql_connect ("localhost", "root",  "") or die ('I cannot connect to the database because: ' . mysql_error()); 
    
    //-select the database to use
    $mydb=mysql_select_db("ware1");
    
    //-query the database table
    $sql="SELECT * FROM equip_ments WHERE product_id=" . $contactid;
    
    
    //-run the query against the mysql query function
    $result=mysql_query($sql); 
    
    //-create while loop and loop through result set
    while($row=mysql_fetch_array($result)){
    
      $component =$row['component_1'];
    	 $serialnum=$row['serial_num'];
    	 $ID=$row['product_id'];
    	//$Email=$row['Email'];
    
    //-display the result of the array
    
    echo "<ul>\n"; 
    echo "<li>" . $component . " " . $serialnum . "</li>\n";
    echo "<li>" . $ID . "</li>\n";
    //echo "<li>" . "<a href=mailto:" . $Email . ">" . $Email . "</a></li>\n";
    echo "</ul>";
    }
    }
    
    ?>
  • omerbutt
    Contributor
    • Nov 2006
    • 638

    #2
    you need to create another oage that browses the record fromt he database for the item that is clicked , and for the current condition you must wrap all the items listed inside the list into a anchor tag and pass the variable say item_id by concatinating it with the opage name and then get it by using $_GET['item_name'] on the detail page and then display all the detail for that item
    Code:
     echo "<ul>\n"; 
      echo "<li><a href='detail.php?item_id=".$ID."'>" . $component . " " . $serialnum . "</a></li>\n";
    echo "</ul>";
    regards,
    Omer Aslam

    Comment

    • huda89
      New Member
      • Oct 2012
      • 31

      #3
      Thank You omerbutt, i got it. =)

      Comment

      • omerbutt
        Contributor
        • Nov 2006
        • 638

        #4
        good to see it solved your problem , please do select the right answer for the question so that if someone else come across with the same problem he could get to the right solution
        regards,
        Omer Aslam

        Comment

        Working...