justlukeyou Posted June 5, 2012 Share Posted June 5, 2012 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>"; Quote Link to comment Share on other sites More sharing options...
trq Posted June 5, 2012 Share Posted June 5, 2012 Sorry, what exactly is the problem? Quote Link to comment Share on other sites More sharing options...
justlukeyou Posted June 5, 2012 Author Share Posted June 5, 2012 Hi, I cant fit any CSS around this code so I am trying to simplify so I can just echo the columns inside their own PHP tags. Quote Link to comment Share on other sites More sharing options...
trq Posted June 5, 2012 Share Posted June 5, 2012 Still, I have no idea what your talking about. Quote Link to comment Share on other sites More sharing options...
justlukeyou Posted June 5, 2012 Author Share Posted June 5, 2012 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> Quote Link to comment Share on other sites More sharing options...
trq Posted June 5, 2012 Share Posted June 5, 2012 Is it possible to do it like this... You just did. Quote Link to comment Share on other sites More sharing options...
justlukeyou Posted June 5, 2012 Author Share Posted June 5, 2012 But that doesn't work because it is only echo the row, not the result. How do I say echo $result['product_id'] because that doesn't work. Quote Link to comment Share on other sites More sharing options...
trq Posted June 5, 2012 Share Posted June 5, 2012 I DO NOT UNDERSTAND YOUR ISSUE. Quote Link to comment Share on other sites More sharing options...
justlukeyou Posted June 5, 2012 Author Share Posted June 5, 2012 I cant fit CSS around this code because it has these tag "' '" I cant pit the result inside its own PHP tags. hp?product_id='".$result['product_id']."><img src='".$res Quote Link to comment Share on other sites More sharing options...
litebearer Posted June 5, 2012 Share Posted June 5, 2012 show us the code where are you creating the $result[] array Quote Link to comment Share on other sites More sharing options...
justlukeyou Posted June 5, 2012 Author Share Posted June 5, 2012 <?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; } } ?> Quote Link to comment Share on other sites More sharing options...
Mahngiel Posted June 5, 2012 Share Posted June 5, 2012 Do you know what CSS is? Quote Link to comment Share on other sites More sharing options...
justlukeyou Posted June 5, 2012 Author Share Posted June 5, 2012 What is that supposed to mean? Does anyone know how to make this easier to use? Quote Link to comment Share on other sites More sharing options...
floridaflatlander Posted June 5, 2012 Share Posted June 5, 2012 How do I say echo $result['product_id'] because that doesn't work. $result['product_id'] isn't returning a value? So you have a php problem not a css problem .... ?? Quote Link to comment Share on other sites More sharing options...
justlukeyou Posted June 5, 2012 Author Share Posted June 5, 2012 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> Quote Link to comment Share on other sites More sharing options...
justlukeyou Posted June 5, 2012 Author Share Posted June 5, 2012 Hi, Does anyone have any suggestions on what I can do. On it's own the PHP code works fine but I am unable to seperate it out so I can style it. The stress is almost making me ill! Quote Link to comment Share on other sites More sharing options...
Mahngiel Posted June 6, 2012 Share Posted June 6, 2012 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. Quote Link to comment Share on other sites More sharing options...
justlukeyou Posted June 6, 2012 Author Share Posted June 6, 2012 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. Quote Link to comment Share on other sites More sharing options...
trq Posted June 6, 2012 Share Posted June 6, 2012 Why not post your code that isn't working then? Quote Link to comment Share on other sites More sharing options...
Jessica Posted June 6, 2012 Share Posted June 6, 2012 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. Quote Link to comment Share on other sites More sharing options...
justlukeyou Posted June 6, 2012 Author Share Posted June 6, 2012 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 Quote Link to comment Share on other sites More sharing options...
ignace Posted June 24, 2012 Share Posted June 24, 2012 You can't get the CSS around it? You know that CSS is: body { font-family: Arial; } right? Quote Link to comment Share on other sites More sharing options...
ignace Posted June 24, 2012 Share Posted June 24, 2012 nevermind Quote Link to comment Share on other sites More sharing options...
ignace Posted June 24, 2012 Share Posted June 24, 2012 If someone told me 4 weeks ago I am wher I am now I would have ripped their hand off. No wonder people do not encourage you! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.