2016-05-31 3 views
0

foreach構造体でdivを一度だけ使用したいのは、複数回使用すると見つかったイメージが改行されているためです。私はそれから1つだけ時間を使用するdivを抜粋する方法を知らない。forech構造体からdivを抜粋する方法

<?php 
include('func.php'); 

if(isset($_POST['keywords'])){ 
    $suffix = ""; 
    $keywords = mysql_real_escape_string(htmlentities(trim($_POST['keywords']))); 
    $errors = array(); 
     $results = search_results($keywords); 
     if ($results === false) { 
     echo '<h1>We didn\'t find anything for &quot;'.$keywords.'&quot;</h1>'; 
    } 
    else { 
     $results_num = count($results); 
     $suffix = ($results_num!=1)?'s':''; 
     echo '<h1>',$results_num,' item',$suffix,' For &quot;',$keywords,'&quot;</h1>'; 
     foreach($results as $result){ 
      echo ' 
<div style="background:rgba(50,0,100,1)"> 

<span class="overimage"> 

<a href="',$result['game_url'],'" target="_blank"> 

<span class="hoverimage"> 
<span class="hovertext1line-home">',$result['name'],'</span><img class="onlinegameimage-home" src="',$result['image_url'],'" alt=',$result['alt'],'> 
</span> 

</a> 

</span> 

</div> 

'; 

}}} 

?> 
+0

スパンを繰り返すことができますか?あなたはdivの権利だけを制限したいですか? – Karthikeyani

+0

はい、スパンを繰り返すことができます。 – Catchamouse

+0

私の答えを確認してください – Karthikeyani

答えて

0

ただ、foreachループの外にdivタグを移動:それが壊れていたので、

<?php 
include('func.php'); 

if (isset($_POST['keywords'])) { 
    $suffix = ""; 
    $keywords = mysql_real_escape_string(htmlentities(trim($_POST['keywords']))); 
    $errors = array(); 
     $results = search_results($keywords); 
     if ($results === false) { 
     echo '<h1>We didn\'t find anything for &quot;'.$keywords.'&quot;</h1>'; 
    } else { 
     $results_num = count($results); 
     $suffix = ($results_num!=1)?'s':''; 
     echo '<h1>' . $results_num . ' item' . $suffix . ' For &quot;' . $keywords . '&quot;</h1>'; 
     echo '<div style="background:rgba(50,0,100,1)">'; 
     foreach ($results as $result) { 
      echo '<span class="overimage"> 
       <a href="' . $result['game_url'] . '" target="_blank"> 
        <span class="hoverimage"> 
         <span class="hovertext1line-home">' . $result['name'] . '</span> 
         <img class="onlinegameimage-home" src="' . $result['image_url'] . '" alt="' . $result['alt'] . '" /> 
        </span> 
       </a> 
      </span>'; 
     } 
     echo '</div>'; 
    } 
} 

はまた、このコードの多くを修正しました。

+0

解決済み、ありがとう! – Catchamouse

0

このコードを試してください。また、ドット(。)の代わりにコンマ(、)を使用して変数を連結することにも注意してください。それも変えてください。

$div = '<div style="background:rgba(50,0,100,1)">'; 

foreach($results as $result){ 
    $div .= '<span class="overimage"><a href="'.$result['game_url'].'" target="_blank"><span class="hoverimage"><span class="hovertext1line-home">'.$result['name'].'</span><img class="onlinegameimage-home" src="'.$result['image_url'].'" alt='.$result['alt'].'></span></a></span>'; 
} 

$div .= '</div>'; 
echo $div; 
関連する問題