[英]How to echo single string values from mysql database separately?
如何分隔單個字符串值?
這是數據庫中的字符串:Small:4,Medium:2,Large:5,X-Large:4
我想分別顯示尺寸和數量。 例如,我有2個列表“大小和數量”。
<table>
<thead>
<th>Sizes</th>
<th>Quantity</th>
</thead>
<tbody>
<tr>
<td><?=“echo sizes here";?></td>
<td><?=“echo quantity here";?></td>
<tr>
</tbody>
那么,如何從數據庫中的單個字符串分別回顯大小和數量呢?
這是數據庫中的字符串:Small:4,Medium:2,Large:5,X-Large:4
嗯,這不是有效使用數據庫的方式。
您正在使用數據庫,然后請使用將數據存儲在行和列中的強大功能和便利性。
制作兩個具有屬性(product_ID,size_ID,quantity)
和(size_ID, size)
,並使用size_ID
屬性進行映射。
如果您仍然希望對數據庫中的給定字符串執行此操作,則可以使用類似以下內容的方法:
算法printXYZ:
Scan the string and keep appending characters to an array.
if char = ':', print the characters scanned till now and empty/deallocate the array.
Then print the next character and stop at char=','.
現在您看到它效率低下又難看嗎?
我想分別顯示尺寸和數量。
您必須首先將它們分別存儲 。
通過添加具有所有大小類型的另一張表和具有product id
, size id
和數量的一個交叉表來更改數據庫結構。
然后只需從該表中選擇屬於特定產品的所有行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.