如何使用PHP制作搜索结果详细信息页面

时间:2016-02-01 13:00:21

标签: php mysql search detailsview

我是一名药剂师,致力于一个项目,用户可以从我的数据库中获取药物信息。我已经创建了搜索结果页面,但我无法创建详细信息页面。这是我的search.php页面:

<?php
$db_hostname = 'localhost';
$db_username = 'root';
$db_password = '';
$db_database = 'drug';

// Database Connection String
$con = mysql_connect($db_hostname,$db_username,$db_password);
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db($db_database, $con);
?>

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title></title>
    </head>
    <body>
<div>

  <?php
if (!empty($_REQUEST['term'])) {

$term = mysql_real_escape_string($_REQUEST['term']);     

$sql = "SELECT * FROM drugs WHERE GenericName LIKE '%".$term."%' OR     BrandName LIKE '%".$term."%' OR Pharmacologicalclass LIKE '%".$term."%' OR     ManufacturedBy LIKE '%".$term."%'"; 
$r_query = mysql_query($sql); 

while ($row = mysql_fetch_array($r_query)){ 
echo '<a href="results.php?id='.$row['GenericName'].'">        <h4>'.$row['BrandName'].'</h4></a>'; 
echo '<br />Generic Name: ' .$row['GenericName'];  

echo '<br /> Dosage Form: '.$row['Dosage form'];  
echo '<br /> Pharmacological Class: '.$row['Pharmacologicalclass'];  
echo '<br /> Indications: '.$row['Indications']; 
echo '<br /> Manufactured By: '.$row['ManufacturedBy'];   
}  

}
?>
</div>
    </body>
</html>

在详细信息页面上,我想要包括GenericName,BrandName,Dosageform,力量,适应症,相互作用,副作用,怀孕类别,药理类别,作用方式和制造方式(所有都是药物表中的行)。

2 个答案:

答案 0 :(得分:0)

StaleElementReferenceException

答案 1 :(得分:0)

我能够做到。这是我的代码,以防一个人有同样的问题。 search.php中
    

// Database Connection String
$con = mysql_connect($db_hostname,$db_username,$db_password);
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db($db_database, $con);
?>
 <form action="search.php" method="post">


<input type="text" class="form-control" name="term" placeholder="Search" /> 

<input type="submit" value="Submit" />  
</form> 
</div></div>
<div>

  <div class="container">
     <section class="col-xs-12 col-sm-6 col-md-12">

    <article class="search-result row">

  <?php
if (!empty($_REQUEST['term'])) {

$term = mysql_real_escape_string($_REQUEST['term']);     

$sql = "SELECT * FROM drugs WHERE GenericName LIKE '%".$term."%' OR     BrandName LIKE '%".$term."%' OR Pharmacologicalclass LIKE '%".$term."%' OR     ManufacturedBy LIKE '%".$term."%' "; 
?>

<div style="">
      Results for: <font color="blue" style="font:bold 20px 'Aleo';"><?php     echo     $term;?></font>
      </div>
      <?php $r_query = mysql_query($sql); 

while ($row = mysql_fetch_array($r_query)){

echo '<a href="results.php?id='.$row['id'].'"><h4>'.$row['BrandName']. ":".     $row['GenericName']. " ".$row['Dosageform']. " ".$row['Strength'].'</h4></a>';     //links to results.php by id since id is unique    
echo ' '.$row['Pharmacologicalclass'];  
echo '<br /> uses: '.$row['Indications'];    
}  

}
?>

这里是results.php

<?php
$connect = mysqli_connect("localhost","root","mypassword","drug");
?>
<?php
if(isset($_GET['id'])){ // checks if id was posted

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

$query_fetch = mysqli_query($connect,"SELECT * FROM drugs WHERE ID = $id");    // id that was posted by search.php

 while($show = mysqli_fetch_array($query_fetch)){ 
  echo  " ".$show['BrandName']. ": &nbsp;" . $show['GenericName']. "      &nbsp;".$show['Strength']." <br></a>";

echo '<br /> <h3> <h3>Indications:</h3>'.$show['Indications'];  // these     rows are displayed to the user
echo '<br /> <h3> Pharmacological Class:</h3> '.$show['Precautions'];  
echo '<br /> <h3> Drug interactions:</h3> '.$show['Interactions']; 
echo '<br /> <h3> Undesirable effects:</h3> '.$show['SideEffects'];
echo '<br /> <h3> Use in pregnacy:</h3> '.$show['PREGNANCYcategory'];  
echo '<br /> <h3> Pharmacological Class:</h3>     '.$show['Pharmacologicalclass'];  
echo '<br /> <h3> Mode of action:</h3> '.$show['ModeOfAction']; 
echo '<br /> <h3> Manufactured By:</h3> '.$show['ManufacturedBy'];   
}  

}
?>