2017-04-21 128 views
0

我正在嘗試從數據庫中按順序提取一個id列。我已經寫了這段代碼,但沒有奏效。PHP注意:未定義偏移量1

$connection = mysqli_connect($servername,$username,$password,$dbname); 
if(!$connection) 
    die("Database connection failed: " . mysqli_connect_error()); 

$query = "SELECT ID FROM channel "; 

if($result = mysqli_query($connection,$query)) 
{ 
    $count = mysqli_num_rows($result);// it will start from the first row and continue with others... 
    //fetch one and one row 
    while($row=mysqli_fetch_row($result)) 
    { 
     for($i=0; $i<$count; $i++) 
     echo "<a>$row[$i]</a>"; 
    } 
    //free result set 
    mysqli_free_result($result); 

} 
mysqli_close($connection); 

所以,這個代碼給了我這個錯誤:

注意:未定義抵消:1在C:\ XAMPP \ htdocs中\ GT \在線fetch_channel.php 24

誰能幫助我關於那個 ?

+0

嗨,u能請告訴你已經放在線24 –

回答

0

的問題是:有一個在$行 沒有$ I指數我不知道你想什麼,但我想你想是這樣的:

$connection = mysqli_connect($servername,$username,$password,$dbname); 
if(!$connection) 
    die("Database connection failed: " . mysqli_connect_error()); 

$query = "SELECT ID FROM channel "; 

if($result = mysqli_query($connection,$query)) 
{ 

    //fetch one and one row 
    while($row=mysqli_fetch_row($result)) 
    { 

     echo "<span>".$row['id']."</span><br/>"; 
    } 


} 
mysqli_close($connection); 
+0

謝謝你幫助:) – Serhat

相關問題