Nevershow2016
Nevershow2016

Reputation: 570

How to style an output command in php

Hi guys so i am playing around with PHP. i hae a html page which has a list of recipes which have been styled in a div etc. I then have anther page which is a php page which i would like to return the same div with the styles applied. So far all i have manged to do is return normal text.

The normal HTMl is : Example

My php search code :

I am sure its in this line $output .= '<div>'.$rN.'</div>'; where i am suppose to change the divs but i have tried everything and is getting errors. Any help on this would be great.

Again just so people undertand. The fiddle example is what i want it look like when its retruned. So far those it just looks like normal text. I just need to understand how to call the divs

Upvotes: 2

Views: 118

Answers (2)

ngearing
ngearing

Reputation: 1365

Just add a class to the div. You can then reuse this class on any element to use the same style.

$output .= '<div class="your-style-class">'.$rN.'</div>';

Upvotes: 1

Kevin
Kevin

Reputation: 41903

Just apply the same div that you have and apply the fetched values doing it inside the while block.

Concatenate the values when necessary:

<?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; ?>

Upvotes: 4

Related Questions