如何将两个搜索结果语句作为一个,并在查询时获得不同的结果

时间:2013-11-19 14:42:40

标签: php mysql variables

我需要将这两个单独的语句作为一个语句使用条件ifelseif,或者甚至是任何其他条件语句来执行任何两个查询并呈现结果。

<?php
require ($_SERVER["DOCUMENT_ROOT"]."/medikconfig/db_medicpharm.php");

$connection = @mysql_connect($db_host, $db_user, $db_password) or die("error connecting");

mysql_select_db($db_name, $connection);

$doctor     = $_GET["txt_doctor"];
$len        = strlen($doctor);
$states     = $_GET["txt_state"];
$specialize = $_GET["txt_specialize"];

if ($len > 0) 
{
    $email    = $_GET["txt_email"];
    $hospital = $_GET["txt_hospital"];
    $state    = $_GET["txt_state"];
    $org      = $_GET["txt_org"];
    $link     = $_GET["txt_web"];

    $query = "INSERT INTO doctor_locator (autoID, `Name of Doctor`, `Email`, `Hospital of Practise`,`State`,`Specialization`, `Professional Organization`, `webpage`)
                    VALUES (NULL,'$doctor','$email','$hospital','$state','$specialize','$org', '$link')";

    mysql_query($query, $connection) or die (mysql_error());
}
?>

第一个声明

<?php

$specialize = $_GET["txt_specialize"]; 
$states     = $_GET["txt_state"]; 
$link       = $_GET["txt_web"];


$sql = "SELECT `autoID`, `Name of Doctor`, `Email`, `Hospital of Practise`, `State`, 
               `Specialization`, `Professional Organization`, `webpage` 
        FROM   `doctor_locator`
        WHERE   state = '$states' AND 
                specialization = '$specialize' ";

$retval = mysql_query( $sql);

if (!$retval) {
    die('Could not get data: ' . mysql_error());
}

while($row = mysql_fetch_array($retval))
{
    echo "{$row['autoID']}.  ".
    "Name of Doctor: <a href = \"{$row['webpage']}\">{$row['Name of Doctor']} </a><br>"
    ."Email: {$row['Email']} <br>". 
    "Hospital of Practise: {$row['Hospital of Practise']}
    <br>". 
    "State:  {$row['State']} <br>" . 
    "Specialization: {$row['Specialization']} <br> ";
}

mysql_free_result($retval);

echo "Fetched data successfully\n.<br/>"; 
echo "<a href=home.php>go back to homepage</a>";

mysql_close($connection);

?>

第二个声明

<?

$specialize = $_GET["txt_specialize"]; 
$states     = $_GET["txt_state"]; 
$link       = $_GET["txt_web"];


$sqldoc = "SELECT `autoID`, `Name of Doctor`, `Email`, `Hospital of Practise`, `State`,
                  `Specialization`, `Professional Organization`, `webpage` 
            FROM  `doctor_locator`
            WHERE `name of doctor` LIKE 'Dr%' AND state = '$states'";


$retvaldoc = mysql_query( $sqldoc);

if (!$retvaldoc)
{
    die('Could not get data: ' . mysql_error());
}

while($row = mysql_fetch_array($retvaldoc))
{
    echo "{$row['autoID']}.  "."Name of Doctor: <a href = \"{$row['webpage']}\">{$row['Name of Doctor']} </a><br>"
    ."Email: {$row['Email']} <br>". "Hospital of Practise: {$row['Hospital of Practise']}
    <br>". "State:  {$row['State']} <br>" . "Specialization: {$row['Specialization']} <br> ";
}

mysql_free_result($retvaldoc);

echo "Fetched data successfully\n.<br/>"; 
echo "<a href=home.php>go back to homepage</a>";

mysql_close($connection);

?>

0 个答案:

没有答案