2015-05-27 27 views
4

我不熟悉SQL和PHP,並且需要以下問題的幫助。使用php和mysql在iFrame V2中顯示特定的URL

我有一個SQL數據庫,例如,「用戶名,密碼,國籍,類」,我想要做的是一個簡單的PHP或SQL查詢,將從數據庫中檢查用戶的類字段並顯示相應的指定的iFrame中的URL(例如,類別爲J1,J2,J3,如果該字段已包含J3,則加載時會顯示相應的URL,而無需任何用戶輸入)(全部將事先決定)

您可以將其視爲學生檔案,一旦學生成功登錄,該查詢將讀取班級字段,並根據它找到的內容,返回具有正確鏈接的可點擊的網址。

This i對於我現在的水平來說,這太困難了,希望有人能夠對我有所瞭解。


這是用戶後的代碼登錄成功。

<!-- NOTIFICATIONS STARTS HERE --> 
<?php 
require_once('connection.php'); 
$id=$_SESSION['SESS_MEMBER_ID']; 
$result3 = mysql_query("SELECT * FROM member where mem_id='$id'"); 
while($row3 = mysql_fetch_array($result3)) 
{ 
$fname=$row3['fname']; 
$country=$row3['country']; 
$class=$row3['class']; 
$headteacher=$row3['headteacher']; 
$attendance=$row3['attendance']; 
$homework=$row3['homework']; 
$messageparents=$row3['messagestudent']; 
} 
?> 
<table width="468" border="0" align="center" cellpadding="0"> 
<tr class="FONTS"> 
<td valign="top"><div align="left" class="FONTS"> 
<table width="468" border="0" align="center" cellpadding="0"> 
<tr> 
<td class="FONTS"><div align="left" class="FONTS"><b>名前:</b></div> 
<?php echo $fname ?></td> 
</tr> 
<tr class="FONTS"> 
<td valign="top"><div align="left" class="FONTS"><b>國:</b></div> 
<?php echo $country ?></td> 
</tr> 
<tr class="FONTS"> 
<td valign="top"><div align="left" class="FONTS"><b>クラス:</b></div> 
<?php echo $class ?></td> 
</tr> 
<tr class="FONTS"> 
<td valign="top"><div align="left" class="FONTS"><b>家庭教師の先生:</b></div> 
<?php echo $headteacher ?></td> 
</tr> 
<tr class="FONTS"> 
<td valign="top"><div align="left" class="FONTS"><b>出席率:</b></div> 
<?php echo $attendance ?></td> 
</tr> 
<tr class="FONTS"> 
<td valign="top"><div align="left" class="FONTS"><b>宿題率:</b></div> 
<?php echo $homework ?></td> 
</tr> 
<tr class="FONTS"> 
<td valign="top"><div align="left" class="FONTS"><b>先生からメッセージ:</b>    
</div> 
<?php echo $messagestudent ?></td> 
</tr> 
</table> 
</div></td> 
</tr> 
</table> 
<p align="center" class="FONTS"><a href="index.php">ログアウト</a></p> 
<!-- NOTIFICATIONS ENDS HERE --> 

如預期,所以我不會改變,除非它完全必要的是已經工作的,我只需要能夠顯示該URL鏈接。

在此先感謝!

+1

如果你剛開始,爲什麼你使用舊的方法? mysql函數現在已經被殺死了一段時間。學習新的東西時,比如PHP,學習更新的指南和教程。你應該使用mysqli或PDO。 –

+0

這是你的完整代碼? – Saty

+0

好吧,它不像現在開始,我很久以前就學習過,只是重新考慮它,但我認爲我的lvl作爲首發, 不,這個代碼只是結果代碼,還有其他3個文件涉及。 –

回答

1
<?php 
if($class=='J1') 
echo "<a href='www.first_url.com'>Click Here</a>"; 
else if($class=='J2') 
echo "<a href='www.second_url.com'>Click Here</a>"; 
.............. 
?> 
0

使用此行代碼在你的頁面

$id=$_SESSION['SESS_MEMBER_ID']; 

,因爲你在你的頁面的頂部

start_session();// at the top of your page 
+0

你好,謝謝你的回答! 這是因爲開始會話在以前的文件中,您輸入用戶名和密碼的文件。 –

0

您應該使用忘記start session您的代碼不工作PDO或MYSQLi_ *,mysql_已被棄用,並且可以運行。

<?php 
start_session(); 

require_once('connection.php'); 

$id=$_SESSION['SESS_MEMBER_ID']; 

$mysqli = new mysqli("myhost","myuser","mypassw","mybd"); 

if (mysqli_connect_errno()) { 

printf("Connect failed: %s\n", mysqli_connect_error()); 

exit(); 

} 

$result3 = $mysqli->query("SELECT * FROM member WHERE mem_id='$id'"); 

while($row3 = mysqli_fetch_array($result3)) 
{ 
    $fname=$row3['fname']; 
    $country=$row3['country']; 

if($row3['class'] == "J1"){ 

    $class='<a href="your link here">Your link info here</a>'; 

} elseif($row3['class'] == "J2") { 

    $class='<a href="your link here">Your link info here</a>'; 

} elseif($row3['class'] == "J3") { 

    $class='<a href="your link here">Your link info here</a>'; 

}else { 

    $class='<a href="your link here">Your link info here</a>'; 

} 
$headteacher=$row3['headteacher']; 
$attendance=$row3['attendance']; 
$homework=$row3['homework']; 
$messageparents=$row3['messagestudent']; 
} 
?> 
<table width="468" border="0" align="center" cellpadding="0"> 
<tr class="FONTS"> 
<td valign="top"><div align="left" class="FONTS"> 
<table width="468" border="0" align="center" cellpadding="0"> 
<tr> 
<td class="FONTS"><div align="left" class="FONTS"><b>名前:</b></div> 
<?php echo $fname ?></td> 
</tr> 
<tr class="FONTS"> 
<td valign="top"><div align="left" class="FONTS"><b>國:</b></div> 
<?php echo $country ?></td> 
</tr> 
<tr class="FONTS"> 
<td valign="top"><div align="left" class="FONTS"><b>クラス:</b></div> 
<?php echo $class ?></td> 
</tr> 
<tr class="FONTS"> 
<td valign="top"><div align="left" class="FONTS"><b>家庭教師の先生:</b></div> 
<?php echo $headteacher ?></td> 
</tr> 
<tr class="FONTS"> 
<td valign="top"><div align="left" class="FONTS"><b>出席率:</b></div> 
<?php echo $attendance ?></td> 
</tr> 
<tr class="FONTS"> 
<td valign="top"><div align="left" class="FONTS"><b>宿題率:</b></div> 
<?php echo $homework ?></td> 
</tr> 
<tr class="FONTS"> 
<td valign="top"><div align="left" class="FONTS"><b>先生からメッセージ:</b>    
</div> 
<?php echo $messagestudent ?></td> 
</tr> 
</table> 
</div></td> 
</tr> 
</table> 
<p align="center" class="FONTS"><a href="index.php">ログアウト</a></p> 
<?php 
mysqli_close($mysqli); 
?> 
+0

感謝您的回答!並花時間把代碼轉換到新的系統,我不知道它改變了,這個腳本至少使用4個文件,而且我可以看到所有使用舊的東西,我會研究你留給我的東西我會嘗試將我的其他文件轉換爲這個新的方案。 非常感謝! –

相關問題