mysql クエリから出力される 2 つの結果ごとにツイートを出力する必要があります。問題のページは、私が達成しようとしていることをよりよく説明するためにここにあります。
これは私がこれまでに使用しているコードですが、機能していません...
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>";
}
}
}
私が間違っているアイデアはありますか?
更新: ツイートを適切な場所に配置することができましたが、表示されているツイートは 1 つだけで、そのツイートの最初の 5 文字がエコーされています。使用したコードは次のとおりです。
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>";
}
}