大家好,我正在玩PHP。我有一个html页面,其中有一个已经在div等样式的食谱列表。然后我有一个php页面,我希望返回相同的div与应用的样式。到目前为止,我所要做的就是返回普通文本。
正常的HTMl是: Example
我的php搜索代码:
我确信它在这一行var result = DbContext.Data.Select(x=> x...).Join(y=> y...) .. new { id = x.id... y.name.. }
中,我想改变div,但我已经尝试了一切并且遇到了错误。对此的任何帮助都会很棒。
再次让人们承诺。这个小提琴的例子是我想要它重新打造时的样子。到目前为止,它看起来像普通文本。我只需要了解如何调用div
答案 0 :(得分:4)
只需应用你拥有的相同div,并在while块中应用获取的值。
必要时连接值:
<?php
$output = '';
if(isset($_POST['search'])){
$searchq = $_POST['search'];
$searchq = preg_replace("#[^0-9a-z]#i","",$searchq);
$query = mysql_query("SELECT * FROM recipe WHERE recipeName LIKE '%$searchq%' OR recipe_ing1 LIKE '%$searchq%' ") or die("Could not search.");
$count = mysql_num_rows($query);
if($count == 0) {
$output = 'There was mo match!';
} else {
while($row = mysql_fetch_array($query)){
$rN = $row['recipeName'];
$output .= '
<div class="panel panel-default">
<div class="panel-heading"><b>' . htmlentities($rN, ENT_QUOTES) . '</b></div>
</div>
';
}
}
}
?>
<form action = "search.php" method = "post">
<input type = "text" name = "search" placeholder = "Search for recipes..."/>
<input type = "submit" value = ">>" />
</form>
<?php echo $output; ?>
答案 1 :(得分:1)
只需在div中添加一个类。然后,您可以在任何元素上重用此类以使用相同的样式。
foreach ($data as $result) {
$day = explode(",", $result['day']);
//changes these two line
$day_flip = array_flip($day);
sort($day);
$status = explode(",", $result['status']);
echo "<tr>";
echo "<td>" . $result['member_login_name'] . "</td>";
for ($d = 1; $d <= date('t'); $d++) {
if ($d <= date('d')){
/************* changes start ****************/
$day_key = array_search($d, $day);
if($day_key > -1){
$key = array_search($d, $day_flip);
$key = $day_flip[$d];
@$status[$key] == 0 ? $class = "attend" : ($status[$key] == 1 ? $class = "leave" : ($status[$key]== 2 ? $class = "absent": $class= "half"));
echo "<td class='$class'></td>";
}
else
echo "<td class='nothing'>--</td>";
/************* changes end ****************/
}
else{
echo "<td class='nothing'>--</td>"; //day above today date
}
}
echo "</tr>";
}