使用php創建一個字符串,使用通過表單使用post的submited數據。如何爲div提供唯一的id,因爲它們是用php書寫的頁面
這是PHP:
if ($carrier== "DL") {
$front = '<tr><td><div onclick="selectText(this)">EZE*#$*IET';
$center = '/O$'.$FOP.'/RB'.$differencePos.'X0.00P'.$fee.'AT0.00/OIECP'.$orIssue.'111062789#MCRV*/MA'.$MCOamt;
$end = '</div></td></tr>';
echo $front,$guest1Ticket,'X*A',$guest1Con,$center,'#N1.1',$end;
if($guest2Ticket) echo $front,$guest2Ticket,'X*A',$guest2Con,$center,'#N2.1',$end;
if($guest3Ticket) echo $front,$guest3Ticket,'X*A',$guest3Con,$center,'#N3.1',$end;
if($guest4Ticket) echo $front,$guest4Ticket,'X*A',$guest4Con,$center,'#N4.1',$end;
if($guest5Ticket) echo $front,$guest5Ticket,'X*A',$guest5Con,$center,'#N5.1',$end;
if($guest6Ticket) echo $front,$guest6Ticket,'X*A',$guest6Con,$center,'#N6.1',$end;
if($guest7Ticket) echo $front,$guest7Ticket,'X*A',$guest7Con,$center,'#N7.1',$end;
if($guest8Ticket) echo $front,$guest8Ticket,'X*A',$guest8Con,$center,'#N8.1',$end;
if($guest9Ticket) echo $front,$guest9Ticket,'X*A',$guest9Con,$center,'#N9.1',$end;
} //if ($airline == "DL")
這將創建一個看起來像這樣的字符串: EZE*#$*IET8388623729002X*A/O$CA/RB71.02X0.00P50.00AT0.00/OIECP01AUG111062789#MCRV*/MA21.02#N1.1
EZE*#$*IET8388623729003X*A/O$CA/RB71.02X0.00P50.00AT0.00/OIECP01AUG111062789#MCRV*/MA21.02#N2.1
EZE*#$*IET8388623729004X*A/O$CA/RB71.02X0.00P50.00AT0.00/OIECP01AUG111062789#MCRV*/MA21.02#N3.1
....
每條線之間的唯一區別是IET 份和N 1.1部件上的字符串本身的端部。
我使用$front
和$end
子字符串來包裝div和table元素中的實際字符串用於佈局。
什麼是最好的方式給每個div得到echo'd一個唯一的ID,所以我的onclick="selectText(this)"
將工作?
我知道我可以打破$front
分成幾個子,只是這樣做
if($guest2Ticket) echo $front1,'id="div2"',$front2,$guest2Ticket,'X*A',$guest2Con,$center,'#N2.1',$end;
,但有沒有更好的辦法?
添加空格前的onclick – 2013-03-16 13:49:52
@AndersLindén感謝。 – Sean 2013-03-16 13:53:25
顯然,我的代碼比上面顯示的還多。 (我實際上有一堆這樣的「字符串製造商」)這種方法更適合我的特殊用途。非常感謝肖恩! – DelightedD0D 2013-03-17 06:03:24