反序列化特定列
更新:我删除了一些 print_r &我在循环上方进行了回显测试,并且能够查看数据。
我使用以下查询从表中获取所有内容。
$result = mysql_query("SELECT * FROM campaign_manager ORDER BY 'date'") or die(mysql_error());
我有一个循环,显示表中的所有内容。
while($row = mysql_fetch_array( $result )) {
// echo out the contents of each row into a table
echo "<tr>";
echo '<td>' . $row['campaign_id'] . '</td>';
echo '<td>' . $row['paragraph_id'] . '</td>';
echo '<td>' . $row['que_id'] . '</td>';
echo "</tr>";
}
到目前为止,一切都很简单……这就是棘手的地方。
$row['paragraph_id'] 已序列化。我进行了一项测试,以使数据按照我需要的方式显示,如下所示;
$do = mysql_fetch_array($result);
print_r(implode(", ",unserialize($do['paragraph_id'])));
它完全按照我需要的方式打印出数据。但是我如何将其实现到我的 while 循环中呢?我尝试了几种变体,但都失败了。我尝试保存到循环外部和内部的变量中。我还尝试在每行迭代中进行反序列化。似乎没有任何作用,并且行不会显示在表中。
在反序列化该列时,如何使用 while 循环从该表获取数据进行显示?
UPDATE: I removed some print_r & echo tests I had above the loop and I was able to view the data.
Am fetching everything from a table with the following query.
$result = mysql_query("SELECT * FROM campaign_manager ORDER BY 'date'") or die(mysql_error());
I have a loop that displays everything in a table.
while($row = mysql_fetch_array( $result )) {
// echo out the contents of each row into a table
echo "<tr>";
echo '<td>' . $row['campaign_id'] . '</td>';
echo '<td>' . $row['paragraph_id'] . '</td>';
echo '<td>' . $row['que_id'] . '</td>';
echo "</tr>";
}
So far pretty straight forward so far... Here's where it gets tricky.
The $row['paragraph_id'] is serialized. I ran a test to get the data to appear how I need it to as follows;
$do = mysql_fetch_array($result);
print_r(implode(", ",unserialize($do['paragraph_id'])));
Which prints out the data exactly how I need it to. But how do I implement that into my while loop? I've tried several variations with all being failure. I've tried saving into variables outside and inside the loop. I've also tried deserializing in each row iteration. Nothing seems to work and the rows will not show up in the table.
How can I get the data from that table to display using that while loop while deserializing that one column?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该使用带有选项 true like
或 simple 的print_r
You should use print_r with option true like
or simple