2017-02-28 59 views
0
if ($result->num_rows > 0) { 

while($row = $result->fetch_assoc()) { 
    $name = $row['name']; 
    $contents = $row['contents']; 
    array_push($allnotes,"<b>",$name,":","</b>",$contents,"<br> <form action='notes/delete-note.php' method='post'> <input type='hidden' name='removenote' value='",$name,"'> <button type='submit'  class='notedelete'>Delete ",$name,"</button> </form>"); 
} 
} else { 
array_push($allnotes,"No avaliable notes!"); 
} 

我遇到的問題是上面的代碼(這裏 - > value ='「,$ name,''>)是添加空格,反過來打破它,因爲我的其他代碼不能正確閱讀關於如何阻止這些空間的任何想法。由於PHP Spaces正在自動放入

+1

這代碼絕對不會添加空格。這些僅僅是'array_push()的一系列參數''但是我知道你真的想要實現什麼? – Rizier123

+0

在你的變量上使用'trim()'來殺死空白。但正如@ Rizier123所說,這段代碼沒有添加任何空格。 – WillardSolutions

+2

我想你想連接這些字符串,而不是將它們作爲單獨的數組項目推送到'$ allnotes'。如果是這樣,請使用點而不是逗號。 –

回答

0

你正在做的方式是一樣的:

$allnotes[] = "<b>"; 
$allnotes[] = $name; 
$allnotes[] = ":"; 
$allnotes[] = "</b>"; 
$allnotes[] = $contents; 
$allnotes[] = "<br> <form action='notes/delete-note.php' method='post'> <input type='hidden' name='removenote' value='"; 
$allnotes[] = $name; 
$allnotes[] = "'> <button type='submit'  class='notedelete'>Delete "; 
$allnotes[] = $name; 
$allnotes[] = "</button> </form>"; 

在我看來,這就是你所真正想要的是..(注意點運算符)

$allnotes[] = "<b>".$name.":"."</b>".$contents."<br> <form action='notes/delete-note.php' method='post'> <input type='hidden' name='removenote' value='".$name."'> <button type='submit'  class='notedelete'>Delete ".$name."</button> </form>";