Jump to content

Simplify To Add CSS


justlukeyou

Recommended Posts

My site is almost ready but I cant fit CSS to this code.  Is there anyway I can simplify it.

 

Something like this would be great.

 

<div class="discountborder">Save <?php echo $row['discount']; ?>%<br /></div></div>

 

 

foreach($results as $result){
echo "<p><a href='/products/product.php?product_id=".$result['product_id']." 'class='productlink'' 'rel='nofollow''>".$result['name']."</a> 
<a href='/products/product.php?product_id='".$result['product_id']."><img src='".$result['image_link']."'/> </a>
<br>£".$result['rrp']."
<br>Save ".$result['discount']."%
</p>";

Link to comment
Share on other sites

I cant add CSS to the above code.  Is it possible to do it like this...

 

 

<div class="productrangeborder">

<div class="productsdetailsborder"><a href="product.php?product_id=<?php echo $row['product_id']; ?>" class='productlink' rel="nofollow" ><?php echo $row['name']; ?></a></div>


<div class="productimageborder"><a href="product.php?product_id=<?php echo $row['product_id']; ?>" rel="nofollow"><img src="<?php echo $row['image_link']; ?>"/></a></div>



<div class="priceborder">Price £<?php echo $row['rrp']; ?><br /></div><div class="discountborder">Save <?php echo $row['discount']; ?>%<br /></div></div>

Link to comment
Share on other sites

 

 

 

<?php
if (isset($_POST['keywords'])){
$keywords = mysql_real_escape_string (htmlentities(trim($_POST['keywords'])));
}

$errors = array();

$results = null;

if (empty($keywords)) {
$errors[] = 'Please enter a search term';
} else if (strlen($keywords)<3) {
$errors[] = 'Your search must be three or more characters';
} else if (($results = search_results($keywords)) === false) {
$errors[] = 'Your search for "'.$keywords.'" returned no results.  Please enter another search.';
}

if (empty($errors))  {
foreach($errors as $error) {
echo $error, '</br>';
}

$results = search_results($keywords);
$results_num = count($results);

echo '<p>Your search for <strong>', $keywords, '</strong> returned <strong>', $results_num, '</strong> results.</p>';

foreach($results as $result){
echo "<p><a href='/products/product.php?product_id=".$result['product_id']." 'class='productlink'' 'rel='nofollow''>".$result['name']."</a> 
<a href='/products/product.php?product_id='".$result['product_id']."><img src='".$result['image_link']."'/> </a>
<br>£".$result['rrp']."
<br>Save ".$result['discount']."%
</p>";

}

} else {
foreach($errors as $error) {
echo $error, '</br>';
}
}
    ?>

<?php
function search_results ($keywords) {
$returned_results = array();
$where = "";

$keywords = preg_split('/[\s]+/', $keywords);
$total_keywords = count($keywords);

foreach($keywords as $key=>$keyword) {
$where .= "`name` LIKE '%$keyword%'";
if ($key != ($total_keywords - 1)) {
$where .= " AND ";

}
}

$results = "SELECT `name`, `description`, `product_id`, `rrp`, `discount`, `image_link`  FROM `productdbase` WHERE $where";



$results_num = ($results = mysql_query($results)) ? mysql_num_rows($results) : 0;


if ($results_num === 0) {
return false;
}else{

while ($results_row = mysql_fetch_assoc($results)) {

$returned_results[] = array(
                    'product_id' => $results_row['product_id'],
		        'image_link' => $results_row['image_link'],
				'rrp' => $results_row['rrp'],
			    'name' => $results_row['name'],
			    'discount' => $results_row['discount'],
                                   'description' => $results_row['description'],
);

}

return $returned_results;

}
}
?>

Link to comment
Share on other sites

It is returning a Value.  I am trying to add CSS to display it better.

 

But I cant get the CSS around it.  I need to simply the code so it works something like this.

 

<div class="discountborder"> <?php echo '".$result['product_id']."; ?></div>

 

CSS is for stylizing your HTML.  PHP produces HTML.  You can style every element (to a degree) of HTML, usually with an external stylesheet called a... (wait for it) .CSS file - or inline inside <style></style> deliminators.

 

If you want to style that snippet above, you'd style it by either the <DIV> or the class (.discountborder).

 

And there's no reason to do what you're doing to that output. 

<?php echo $result['product_id']; ?>

 

You've a lot to learn, young Jedi - primarily how to ask a question.

Link to comment
Share on other sites

But when I try to seperate it out like it doesn't work. I have other code as above I have separated out and it works fine but with this whenever I place it in it's PHP tags and introduce CSS it reads the CSS as interfering.

 

Is their a correct way to seperate it out.  I've tried using different variations of curly tags but it still reads the CSS.

Link to comment
Share on other sites

This may be the most hysterical thread I've read in a while.

 

<?php 
echo '<div class="discountborder">'.$result['product_id'].'</div>'; 
?>

 

Look at this and figure out WHY it works before just copying and pasting it into your code.

Link to comment
Share on other sites

Sorted thanks.

 

Now I can see how it works its much easier to understand.

 

At the end of the day Im delighted how things have gone, in almost 4 weeks Ive made a convincing database driven sales website.

 

If someone told me 4 weeks ago I am wher I am now I would have ripped their hand off.

 

Now I just have some pieces to finish off and I should be there :)

Link to comment
Share on other sites

  • 3 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.