2014-09-27 21 views
0

我試圖從存儲SQL數據庫($演示)變量($ Q11),但我得到的錯誤注意:不明指標:俠諾在C:\ XAMPP htdocs中,

注意:不明指標:俠諾在C:\ XAMPP \ htdocs中\,......

請這個錯誤一些人給解決

<?php 
$connect = mysql_connect("localhost","root","") 
or die(mysql_error()); 
$sel=mysql_select_db("demo"); 

$query1 = mysql_query("SELECT * FROM `linuxq` ORDER BY RAND() LIMIT 10 "); 

echo "<h4 align='Center'><u>Linux Questions</u><br></h4>"; 

$rows11 = mysql_fetch_array($query1); 
$q11 = $rows11['QNo']; 
$qus11 = $rows11['Question']; 
$a = $rows11['Opt1']; 
$b = $rows11['Opt2']; 
$c = $rows11['Opt3']; 
$d = $rows11['Opt4']; 
$ans11 = $rows11['Ans']; 


echo " <b>Question:-<br></b>$qus11 <br>"; 
echo " <input type=radio name = 'answer$q11' value = '$a'></input>$a &nbsp &nbsp"; 
echo " <input type=radio name = 'answer$q11' value = '$b'></input>$b &nbsp &nbsp"; 
echo " <input type=radio name = 'answer$q11' value = '$c'></input>$c &nbsp &nbsp "; 
echo " <input type=radio name = 'answer$q11' value = '$d'></input>$d <br><br> "; 
+1

使用while循環來打印數據,因爲你從數據庫中獲取10條記錄 – Khushboo 2014-09-27 10:48:25

+0

http://siliconstation.com/how-fix-php-notice-undefined-index/ – mahen3d 2014-09-27 10:49:22

+1

@Khushboo更多的if語句,如果他只喜歡一行... – bwoebi 2014-09-27 10:49:22

回答

0

無論如何,以避免不必要的錯誤信息在你的情況,你應該檢查記錄計數查詢通過添加例如:

... 
$query1 = mysql_query("SELECT * FROM `linuxq` ORDER BY RAND() LIMIT 10 "); 
echo "<h4 align='Center'><u>Linux Questions</u><br></h4>"; 

if(mysql_num_rows($query1)>0) {  
    $rows11 = mysql_fetch_array($query1); 
    $q11 = $rows11['QNo']; 
    $qus11 = $rows11['Question']; 
    $a = $rows11['Opt1']; 
    $b = $rows11['Opt2']; 
    $c = $rows11['Opt3']; 
    $d = $rows11['Opt4']; 
    $ans11 = $rows11['Ans']; 

    echo " <b>Question:-<br></b>$qus11 <br>"; 
    echo " <input type=radio name = 'answer$q11' value = '$a'></input>$a &nbsp &nbsp"; 
    echo " <input type=radio name = 'answer$q11' value = '$b'></input>$b &nbsp &nbsp"; 
    echo " <input type=radio name = 'answer$q11' value = '$c'></input>$c &nbsp &nbsp "; 
    echo " <input type=radio name = 'answer$q11' value = '$d'></input>$d <br><br> "; 
} 
... 

而且我想你對你的表的幾個問題,但我沒有看到任何環路,也許你忘了發佈它...

0

嘗試以下: -

$q11 = $rows11[0]['QNo']; 
$qus11 = $rows11[0]['Question']; 
$a = $rows11[0]['Opt1']; 
$b = $rows11[0]['Opt2']; 
$c = $rows11[0]['Opt3']; 
$d = $rows11[0]['Opt4']; 
$ans11 = $rows11[0]['Ans']; 
+0

咦?它是mysql_fetch_array(),而不是PDO_Stmt :: fetchAll()... – bwoebi 2014-09-27 10:59:22

+0

但是,這也將打印值 – Khushboo 2014-09-27 11:01:25

+0

警告C:\\ xampp \ htdocs \中的非法字符串偏移'QNo', – Redsun 2014-09-27 11:04:05

相關問題