duanjian4150 2016-02-01 13:00
浏览 81

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

I am a pharmacist working on a project where a user can get medicines information from my database. I have made the search results page but I'm unable to make a details page. Here is my search.php page:

<?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>

On the details page I want to include GenericName, BrandName, Dosageform, Strength, indications, interactions, side effect, pregnancy category, pharmacological class, mode of action and manufactured by (all are rows in by drugs table).

  • 写回答

2条回答 默认 最新

  • douji9816 2016-02-01 13:12
    关注
    <html>
        <head><title>results - details</title></head>
        <body>
            <?php
                /* 
                    "mysql_*" - the old mysql functions are deprecated and their use is discouraged
                    You would be wise to take time now to implement mysqli in conjunction with
                    prepared statements to avoid sql injection attacks.
    
                    That said, below semi-pseudo code might help you get started
    
                */
    
                if( $_SERVER['REQUEST_METHOD']=='POST' && !empty( $_GET['id'] ) ){
    
                    $sql='select * from `drugs` where `id`='.$_GET['id'];
                    $res=mysql_query( $sql, $con );
    
                    if( $res ){
                        while( $rs=mysql_fetch_object( $res ) ){
                            echo $rs->GenericName, $rs->BrandName, $rs->Dosageform, $rs->Strength; /* etc */
                        }
                    } else {
                        echo 'no results';
                    }
                    mysql_close( $con );
                }
            ?>
        </body>
    </html>
    
    评论

报告相同问题?

悬赏问题

  • ¥20 怎么在stm32门禁成品上增加记录功能
  • ¥15 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面
  • ¥50 NT4.0系统 STOP:0X0000007B
  • ¥15 想问一下stata17中这段代码哪里有问题呀
  • ¥15 flink cdc无法实时同步mysql数据
  • ¥100 有人会搭建GPT-J-6B框架吗?有偿
  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 解riccati方程组