0
也許標題有點混淆,但讓我試着解釋一下。從multidimentional數組獲取特定值鎖定爲ID
我有一個數據庫(informix),並使用PHP PDO,在該數據庫中有一個包含頁面樣式表的表。 看到這樣的:
特殊ID,完整的樣式表(就像我們在一個CSS文件中)。
此刻,我可以顯示一個多維數組的記錄(見代碼和輸出如下):
$query = $db -> prepare("select alpb_box_id, alpb_style::lvarchar as STYLESHEET
from ao_link_page_boxes WHERE alpb_li_id = 633 AND alpb_lngcode = '031' AND
alpb_pageno = 1");
$query -> execute();
$result = array();
while($row = $query->fetch(PDO::FETCH_ASSOC)) {
$result[] = $row;
}
$db = null;
echo "<pre>";
print_r($result);
echo "</pre>";
和輸出:
Array
(
[0] => Array
(
[ALPB_BOX_ID] => TXT-633-P1B1
[STYLESHEET] => background-attachment:scroll; background-color:rgba(0, 0, 0, 0); background-image:none; background-position:0% 0%; background-repeat:repeat; border-bottom-color:rgb(0, 0, 0); border-bottom-style:none; border-bottom-width:0px; border-collapse:separate; border-left-color:rgb(0, 0, 0); border-left-style:none; border-left-width:0px; border-right-color:rgb(0, 0, 0); border-right-style:none; border-right-width:0px; border-top-color:rgb(0, 0, 0); border-top-style:none; border-top-width:0px; bottom:auto; box-shadow:none; caption-side:top; color:rgb(0, 0, 0); font-family:Swis721 BT; font-size:69px; font-style:normal; font-variant:normal; font-weight:normal; height:75px; left:0px; letter-spacing:normal; line-height:normal; list-style-image:none; list-style-position:outside; list-style-type:disc; margin-bottom:0px; margin-left:0px; margin-right:0px; margin-top:0px; max-height:none; max-width:none; min-height:0px; min-width:0px; overflow-x:hidden; overflow-y:hidden; padding-bottom:0px; padding-left:0px; padding-right:0px; padding-top:0px; position:relative; right:auto; text-align:-webkit-auto; text-decoration:none; text-indent:0px; text-overflow:clip; text-transform:none; top:0px; vertical-align:baseline; white-space:normal; width:793px; word-spacing:0px; z-index:auto;
)
[1] => Array
(
[ALPB_BOX_ID] => TXT-633-P1B2
[STYLESHEET] => background-attachment:scroll; background-color:rgba(0, 0, 0, 0); background-image:none; background-position:0% 0%; background-repeat:repeat; border-bottom-color:rgb(0, 0, 0); border-bottom-style:none; border-bottom-width:0px; border-collapse:separate; border-left-color:rgb(0, 0, 0); border-left-style:none; border-left-width:0px; border-right-color:rgb(0, 0, 0); border-right-style:none; border-right-width:0px; border-top-color:rgb(0, 0, 0); border-top-style:none; border-top-width:0px; bottom:auto; box-shadow:none; caption-side:top; color:rgb(0, 0, 0); font-family:\'Swis721 BT\'; font-size:16px; font-style:italic; font-variant:normal; font-weight:normal; height:197px; left:0px; letter-spacing:normal; line-height:normal; list-style-image:none; list-style-position:outside; list-style-type:disc; margin-bottom:0px; margin-left:0px; margin-right:0px; margin-top:0px; max-height:none; max-width:none; min-height:0px; min-width:0px; overflow-x:hidden; overflow-y:hidden; padding-bottom:0px; padding-left:0px; padding-right:0px; padding-top:0px; position:absolute; right:auto; text-align:-webkit-auto; text-decoration:none; text-indent:0px; text-overflow:clip; text-transform:none; top:75px; vertical-align:baseline; white-space:normal; width:717px; word-spacing:0px; z-index:auto;
)
[2] => Array
(
[ALPB_BOX_ID] => IMG-633-P1B3
[STYLESHEET] => background-attachment:scroll; background-color:rgba(0, 0, 0, 0); background-image:none; background-position:0% 0%; background-repeat:repeat; border-bottom-color:rgb(0, 0, 0); border-bottom-style:none; border-bottom-width:0px; border-collapse:separate; border-left-color:rgb(0, 0, 0); border-left-style:none; border-left-width:0px; border-right-color:rgb(0, 0, 0); border-right-style:none; border-right-width:0px; border-top-color:rgb(0, 0, 0); border-top-style:none; border-top-width:0px; bottom:auto; box-shadow:none; caption-side:top; color:rgb(0, 0, 0); font-family:\'Times New Roman\'; font-size:16px; font-style:normal; font-variant:normal; font-weight:normal; height:188px; left:0px; letter-spacing:normal; line-height:normal; list-style-image:none; list-style-position:outside; list-style-type:disc; margin-bottom:0px; margin-left:0px; margin-right:0px; margin-top:0px; max-height:none; max-width:none; min-height:0px; min-width:0px; overflow-x:visible; overflow-y:visible; padding-bottom:0px; padding-left:0px; padding-right:0px; padding-top:0px; position:relative; right:auto; text-align:-webkit-auto; text-decoration:none; text-indent:0px; text-overflow:clip; text-transform:none; top:207px; vertical-align:baseline; white-space:normal; width:377px; word-spacing:0px; z-index:auto;
)
[3] => Array
(
[ALPB_BOX_ID] => IMG-633-P1B4
[STYLESHEET] => background-attachment:scroll; background-color:rgba(0, 0, 0, 0); background-image:none; background-position:0% 0%; background-repeat:repeat; border-bottom-color:rgb(0, 0, 0); border-bottom-style:none; border-bottom-width:0px; border-collapse:separate; border-left-color:rgb(0, 0, 0); border-left-style:none; border-left-width:0px; border-right-color:rgb(0, 0, 0); border-right-style:none; border-right-width:0px; border-top-color:rgb(0, 0, 0); border-top-style:none; border-top-width:0px; bottom:auto; box-shadow:none; caption-side:top; color:rgb(0, 0, 0); font-family:Times New Roman; font-size:16px; font-style:normal; font-variant:normal; font-weight:normal; height:188px; left:0px; letter-spacing:normal; line-height:normal; list-style-image:none; list-style-position:outside; list-style-type:disc; margin-bottom:0px; margin-left:0px; margin-right:0px; margin-top:0px; max-height:none; max-width:none; min-height:0px; min-width:0px; overflow-x:visible; overflow-y:visible; padding-bottom:0px; padding-left:0px; padding-right:0px; padding-top:0px; position:relative; right:auto; text-align:-webkit-auto; text-decoration:none; text-indent:0px; text-overflow:clip; text-transform:none; top:0px; vertical-align:baseline; white-space:normal; width:377px; word-spacing:0px; z-index:auto;
)
)
現在我嘗試做的是,從每個ID(例如:TXT-633-P1B1)中獲得以下樣式:
height:75px; width:793px; top:0px;和left:0px ;.
並將它們存儲到結果中,以便在需要時可以重複使用並回顯它們。
在這種情況下,我應該得到4個ID的4個樣式項目(包括數量px)。
有沒有人有一個想法如何做到這一點。 我希望我解釋我的問題是正確的。
感謝
感謝,這是非常有益的,我有一個問題。
如何將這些值添加到預製的div中。 例如:
<div id="TXT-633-P1B1" style="height:75px; width:793px; top:0px; left:0px;"></div>
而這對於每個ID,它是該陣列英寸
謝謝,我真的很感激。
感謝,這是非常有益的,我有一個問題。 如何將這些值添加到預製的div中。例如: '
' 而這個數組中的每個ID都是如此。 謝謝,我真的很感激。 – udigital@ user999221我在回答中添加了更多 – ghbarratt
謝謝,我親近了自己。我還有最後一個問題。當我想要的值,例如,就像上面的數組的順序: 'value [1]' 'value [2]' 'value [3]' '.....' This與div風格無關,因爲它們很好用,這是別的。 我希望你抓住我的想法? 再次感謝。 – udigital