我需要从 mysql 查询输出的每两个结果输出一条推文。有问题的页面是为了更好地解释我想要实现的目标。
这是我到目前为止使用的代码,它不起作用......
foreach($multi_array as $key => $value ){
// start tweet output for loop. twitter authentication is before this foreach loop
?>
<div id="masonry-container">
<?php
$dbleads = new mysqli('localhost','****','*****','******');
$query = mysqli_query($dbleads, "SELECT * FROM plugin_blog ORDER BY date_added DESC LIMIT 0,10");
$i = 0;
$j = 0;
while ($row=mysqli_fetch_array($query)){
preg_match('/(<img[^>]+>)/i', $row['html'], $matches);
$img = $matches[1];
++$i;
++$j;
if ($i%2 == 0){
if($j%10==0){
echo "<div class='masonryImage tweets' style='width:300px; height:175px;'><div class='tweet-content'>" . $value['text'] . "</div></div>";
}
}
else{
echo "<div class='masonryImage blogImage' style='width: 300px; height:250px;'>" . $img . " </div>";
}
}
}
有什么想法我哪里出错了吗?
更新:现在设法将推文放在正确的位置,但是,只显示一条推文,它与该推文的前五个字母相呼应,这是我使用的代码:
foreach($multi_array as $key => $value ){
// printing each tweet wrapped in a <li> tag
$tweets = $value['text'];
}
$dbleads = new mysqli('********','***********','**********','************');
$query = mysqli_query($dbleads, "SELECT * FROM plugin_blog WHERE published = 1 ORDER BY date_added DESC LIMIT 0,10");
$i = 0;
$j=-1;
while ($row=mysqli_fetch_array($query)){
preg_match('/(<img[^>]+>)/i', $row['html'], $matches);
$img = $matches[1];
++$i;
if ($i%2 == 0){
++$j;
echo "<div class='masonryImage tweets' style='width:300px; height:175px;'><div class='tweet-content'>" . $tweets[$j] . "</div></div>";
echo $j; // here only for debugging, checking the counter works
}
else{
echo "<div class='masonryImage blogImage' style='width: 300px; height:200px;'>" . $img . " </div>";
}
}