2014-04-05 39 views
0

我創建學生信息的教育結果頁面。我基本上有2查詢從SQL用輥一次搜索沒有第二個是從名稱搜索。我有單獨創建它,當我在一個頁面上結合它它顯示兩個結果,但我想只有一個結果我的編碼是下選擇查詢運行並顯示結果

<?php 
include 'form.html'; 
$r1=$_GET["r"]; 
$n1=$_GET["n"]; 
$con=mysqli_connect(localhost,chumspai_tlss,Tls121,chumspai_tlsResult); 

if (mysqli_connect_errno()) 
    { 
    echo "Failed to connect to MySQL: " . mysqli_connect_error(); 
    } 
$result = mysqli_query($con,"SELECT * FROM nursery_blue_ WHERE sr_='$r1'"); 

while($row = mysqli_fetch_array($result)) 


{ 
     echo'<table width="100%" cellpadding="10" cellspacing="0" border="0">'; 
     echo'<tr>'; 
     echo'<td class="heading grey" width="30%">'.RNO.'</td>'; 
     echo'<td>'. $row['sr_']."</td>"; 
     echo'</tr>'; 
    echo'<tr>'; 
     echo'<td class="heading grey">'.NAME.'</td>'; 
    echo'<td class="shade">'. $row['students_names'].'</td>'; 
     echo'</tr>'; 
     echo'</table>'; 
     echo'<table width="100%" cellpadding="10" cellspacing="0" border="0">'; 
     echo'<tr>'; 
     echo'<tr class="grey">'; 
     echo'<td rowspan="2" class="heading">'.Sr_no.'</td>'; 
     echo'<td rowspan="2" class="heading">'.Subject.'</td>'; 
     echo'<td rowspan="2" class="heading">'.Total_Marks.'</td>'; 
     echo'<td rowspan="2" class="heading">'.Marks_Obtained.'</td>'; 
     echo'</tr>'; 
     echo'<tr>'; 
     echo'<td>'._.'</td>'; 
     echo'</tr>'; 
     echo'<tr>'; 
     echo'<td>'.(1).'</td>'; 
     echo'<td>'. English."</td>"; 
     echo'<td>'.(50).'</td>'; 
     echo'<td>'. $row['2']."</td>"; 
     echo'</tr>'; 
    echo'<tr>'; 
     echo'<td>'.(2).'</td>'; 
    echo'<td>'. Urdu.'</td>'; 
    echo'<td>'.(50).'</td>'; 
     echo'<td>'. $row['3']."</td>"; 
     echo'</tr>'; 
     echo'<tr>'; 
     echo'<td>'.(3).'</td>'; 
    echo'<td>'. Math.'</td>'; 
    echo'<td>'.(50).'</td>'; 
     echo'<td>'. $row['4']."</td>"; 
     echo'</tr>'; 
     echo'<tr>'; 
     echo'<td>'.(4).'</td>'; 
    echo'<td>'. G_know.'</td>'; 
    echo'<td>'.(50).'</td>'; 
     echo'<td>'. $row['5']."</td>"; 
     echo'</tr>'; 
     echo'<tr>'; 
     echo'<td>'.(5).'</td>'; 
    echo'<td>'. Act_Con.'</td>'; 
    echo'<td>'.(30).'</td>'; 
     echo'<td>'. $row['6']."</td>"; 
     echo'</tr>'; 
     echo'<tr>'; 
     echo'<td>'.(6).'</td>'; 
    echo'<td>'. Islamiat.'</td>'; 
    echo'<td>'.(20).'</td>'; 
     echo'<td>'. $row['7']."</td>"; 
     echo'</tr>'; 
     echo'<tr>'; 
     echo'<td>'.(7).'</td>'; 
    echo'<td>'. Quran.'</td>'; 
    echo'<td>'.(25).'</td>'; 
     echo'<td>'. $row['8']."</td>"; 
     echo'</tr>'; 
    echo'<tr>'; 
    echo'<td colspan="2" class="heading grey">'.TOTAL.'</td>'; 
    echo'<td colspan="1" class="heading">'.$row['10'].'</td>'; 
    echo'<td colspan="1" class="heading">'.$row['9'].'</td>'; 
     echo'</tr>'; 
     echo'<tr>'; 
     echo'<td colspan="3" class="heading grey">'.Persantage.'</td>'; 
     echo'<td colspan="1" class="heading">'.$row['11'].'</td>'; 
     echo'</tr>'; 
     echo'<tr>'; 
     echo'<td colspan="3" class="heading grey">'.Grade.'</td>'; 
     echo'<td colspan="1" class="heading">'.$row['12'].'</td>'; 
     echo'</tr>'; 
     echo'<tr>'; 
     echo'<td colspan="3" class="heading grey">'.Lecture_Delivered.'</td>'; 
     echo'<td colspan="1" class="heading">'.$row['13'].'</td>'; 
     echo'</tr>'; 
     echo'<tr>'; 
     echo'<td colspan="3" class="heading grey">'.Attendence.'</td>'; 
     echo'<td colspan="1" class="heading">'.$row['14'].'</td>'; 
     echo'</tr>'; 
    echo'<tr>'; 
     echo'<td colspan="7" class="heading grey">'."(i) This provisional result intimation is issued as a notice only. Errors and omissions are excepted.".'</td>'; 
     echo'</tr>'; 

     echo'</table>'; 
    } 
$result1 = mysqli_query($con,"SELECT * FROM nursery_blue_ WHERE students_names like '%$n1%'"); 

while($row1 = mysqli_fetch_array($result1)) 
{ 
echo '<pre>'; 
    echo "<a href='http://www.tlss.edu.pk/result/index.php?r=".$row1['sr_']."'>".$row1['sr_'].'.'.$row1['students_names']."</a>"; 
    echo '</pre>'; 
    }  


?> 

請幫幫忙!

+0

你能證明你有什麼預期的結果 –

+0

你會如何想他們顯示出來呢?在我看來,兩個$ _GET變量同時出現在URL中。 – witherwind

+0

但我想只有一個變量存在的時間 – user2740125

回答

1

,如果你想顯示一個結果你的頁面..同時通一個查詢字符串PARM上設置。 這樣http://yoursite.com/result.php?n=john OR http://yoursite.com/result.php?r=5566 ,改變你的代碼這一點。

(代碼未測試)

<?php 
include 'form.html'; 
$con=mysqli_connect(localhost,username,password,database); 

if (mysqli_connect_errno()) 
    { 
    exit("Failed to connect to MySQL: " . mysqli_connect_error()); 
    } 

if(isset($_GET['r'])) { 
    // You must filter the User input .. to stop SQL injection attack's 
$r1 = mysql_real_escape_string($_GET['r']); 
$query = "SELECT * FROM nursery_blue_ WHERE sr_='$r1'"; 
$result = mysqli_query($con , $query); 
// Proccess Loop 
while($row = mysqli_fetch_array($result)) 

{ 
     echo'<table width="100%" cellpadding="10" cellspacing="0" border="0">'; 
     echo'<tr>'; 
     echo'<td class="heading grey" width="30%">'.RNO.'</td>'; 
     echo'<td>'. $row['sr_']."</td>"; 
     echo'</tr>'; 
    echo'<tr>'; 
     echo'<td class="heading grey">'.NAME.'</td>'; 
    echo'<td class="shade">'. $row['students_names'].'</td>'; 
     echo'</tr>'; 
     echo'</table>'; 
     echo'<table width="100%" cellpadding="10" cellspacing="0" border="0">'; 
     echo'<tr>'; 
     echo'<tr class="grey">'; 
     echo'<td rowspan="2" class="heading">'.Sr_no.'</td>'; 
     echo'<td rowspan="2" class="heading">'.Subject.'</td>'; 
     echo'<td rowspan="2" class="heading">'.Total_Marks.'</td>'; 
     echo'<td rowspan="2" class="heading">'.Marks_Obtained.'</td>'; 
     echo'</tr>'; 
     echo'<tr>'; 
     echo'<td>'._.'</td>'; 
     echo'</tr>'; 
     echo'<tr>'; 
     echo'<td>'.(1).'</td>'; 
     echo'<td>'. English."</td>"; 
     echo'<td>'.(50).'</td>'; 
     echo'<td>'. $row['2']."</td>"; 
     echo'</tr>'; 
    echo'<tr>'; 
     echo'<td>'.(2).'</td>'; 
    echo'<td>'. Urdu.'</td>'; 
    echo'<td>'.(50).'</td>'; 
     echo'<td>'. $row['3']."</td>"; 
     echo'</tr>'; 
     echo'<tr>'; 
     echo'<td>'.(3).'</td>'; 
    echo'<td>'. Math.'</td>'; 
    echo'<td>'.(50).'</td>'; 
     echo'<td>'. $row['4']."</td>"; 
     echo'</tr>'; 
     echo'<tr>'; 
     echo'<td>'.(4).'</td>'; 
    echo'<td>'. G_know.'</td>'; 
    echo'<td>'.(50).'</td>'; 
     echo'<td>'. $row['5']."</td>"; 
     echo'</tr>'; 
     echo'<tr>'; 
     echo'<td>'.(5).'</td>'; 
    echo'<td>'. Act_Con.'</td>'; 
    echo'<td>'.(30).'</td>'; 
     echo'<td>'. $row['6']."</td>"; 
     echo'</tr>'; 
     echo'<tr>'; 
     echo'<td>'.(6).'</td>'; 
    echo'<td>'. Islamiat.'</td>'; 
    echo'<td>'.(20).'</td>'; 
     echo'<td>'. $row['7']."</td>"; 
     echo'</tr>'; 
     echo'<tr>'; 
     echo'<td>'.(7).'</td>'; 
    echo'<td>'. Quran.'</td>'; 
    echo'<td>'.(25).'</td>'; 
     echo'<td>'. $row['8']."</td>"; 
     echo'</tr>'; 
    echo'<tr>'; 
    echo'<td colspan="2" class="heading grey">'.TOTAL.'</td>'; 
    echo'<td colspan="1" class="heading">'.$row['10'].'</td>'; 
    echo'<td colspan="1" class="heading">'.$row['9'].'</td>'; 
     echo'</tr>'; 
     echo'<tr>'; 
     echo'<td colspan="3" class="heading grey">'.Persantage.'</td>'; 
     echo'<td colspan="1" class="heading">'.$row['11'].'</td>'; 
     echo'</tr>'; 
     echo'<tr>'; 
     echo'<td colspan="3" class="heading grey">'.Grade.'</td>'; 
     echo'<td colspan="1" class="heading">'.$row['12'].'</td>'; 
     echo'</tr>'; 
     echo'<tr>'; 
     echo'<td colspan="3" class="heading grey">'.Lecture_Delivered.'</td>'; 
     echo'<td colspan="1" class="heading">'.$row['13'].'</td>'; 
     echo'</tr>'; 
     echo'<tr>'; 
     echo'<td colspan="3" class="heading grey">'.Attendence.'</td>'; 
     echo'<td colspan="1" class="heading">'.$row['14'].'</td>'; 
     echo'</tr>'; 
    echo'<tr>'; 
     echo'<td colspan="7" class="heading grey">'."(i) This provisional result intimation is issued as a notice only. Errors and omissions are excepted.".'</td>'; 
     echo'</tr>'; 

     echo'</table>'; 
    } 




} else if(isset($_GET['n'])){ 
$n1 = mysql_real_escape_string($_GET['n']); 
$query = "SELECT * FROM nursery_blue_ WHERE students_names like '%$n1%'"; 
$result = mysqli_query($con , $query); 


while($row1 = mysqli_fetch_array($result1)) 
{ 
echo '<pre>'; 
    echo "<a href='http://www.tlss.edu.pk/result/index.php?r=".$row1['sr_']."'>".$row1['sr_'].'.'.$row1['students_names']."</a>"; 
    echo '</pre>'; 
    } 


} else { 
    exit(); 
} 

?> 
+0

它不工作沒有結果表明 – user2740125

+0

我想的一樣,你說,但它顯示了沒事的時候我就可以告訴我..從URL查詢字符串中使用此代碼 – user2740125

+0

? –