2011-01-12 104 views
0

我忙於製作一個小型搜索引擎,它可以從我的數據庫中獲取信息。接下來的事情是,每個搜索到的記錄都有編輯它的選項。所以我必須爲每個記錄提供一個具有唯一名稱的提交按鈕。這工作正常,直到我按下按鈕。然後每個按鈕都有相同的名稱。PHP多個提交按鈕的唯一名稱失敗

create form:" 
<form sutff> 
$t=0; 
while(){<br/> 
$t+=1;<br/> 
input type="Submit" name="$t"/><br/> 
}</form> 

一個按下按鈕:

while($_POST[$t]>0){ 
    if (isset($_POST[$t])) { 
    do stuff 
    } 
    else{ 
    $_POST[$t]-=1; 
    } 
} 

不要擔心榮譽 '' 和 「」。我會自己修復它。

+4

你需要發佈你的實際代碼。目前,我們無法理解這一點。 – BoltClock 2011-01-12 10:12:06

回答

1

一個JavaScript的方法是這樣的:

<form name="form1" method="post"> 
<input type="hidden" name="item_id" value=""> 
<input type="submit" value="submit this" onclick="document.form1.item_id.value = '<?php echo 16; ?>';"> 
<input type="submit" value="submit this" onclick="document.form1.item_id.value = '<?php echo 32; ?>';"> 
<input type="submit" value="submit this" onclick="document.form1.item_id.value = '<?php echo 48; ?>';"> 
</form> 

在服務器端:

另一種選擇,也許是因爲它的100%HTML + CSS更好的解決方案,是一起做這些事行:

<style type="text/css"> 
.submit-button { 
    .submit-button { 
     /* WARNING: works only in standards compliance mode */ 
     text-indent: -1000px; /* this hides the button label */ 
     background: url("edit.gif") no-repeat; /* this places an icon inside the button */ 
     margin: 0; /* rest makes the button look CoOl */ 
     border: 1px solid; 
     border-color: buttonhighlight buttonshadow buttonshadow buttonhighlight; 
     padding: 0; 
     width: 18px; 
     height: 18px; 
    } 
</style> 

<form name="form1" method="post"> 
<input type="submit" name="item_id" value="<?php echo 16; ?>" class="submit-button"> 
<input type="submit" name="item_id" value="<?php echo 32; ?>" class="submit-button"> 
<input type="submit" name="item_id" value="<?php echo 64; ?>" class="submit-button"> 
</form> 

在服務器端:

1

你可以爲每一行使用一個單獨的表單,這樣你可以隱藏數據的字段。

另一種解決方案是在繼續提交之前,使用submit按鈕上的onclick事件來設置隱藏字段。

命名submitbutton應該可以工作。

第三個選擇是不使用提交,而是去一個普通的按鈕,並使用onclick來打開一個url。

第四個選項是用帶有鏈接的圖像來僞造按鈕。

但有了更多的信息,我們可能會有更多的想法。

+0

其中兩個選項在我的回答中顯示:) – 2011-01-12 10:30:07

0

林不知道你在問什麼

你可以設置一個值提交按鈕,並閱讀

<input type='submit' name='sub' value='edit' /> 
<input type='submit' name='sub' value='search' /> 

然後在PHP中,你可以做

if ($_POST['sub'] == "edit") { 
    //Do edits 
} 
else if ($_POST['sub'] == "search"){ 
    //Do searching 
} 
else{ 
    //Run Away.... 
} 

希望這幫助!

0

爲什麼它需要是一個提交按鈕,甚至是一個按鈕?

<a href="edit.php?id=1">Edit item 1</a> 
<a href="edit.php?id=2">Edit item 2</a> 
<a href="edit.php?id=3">Edit item 3</a> 
<a href="edit.php?id=4">Edit item 4</a>