Jump to content

justlukeyou

Members
  • Posts

    957
  • Joined

  • Last visited

Everything posted by justlukeyou

  1. Okay thanks. I think I have a solution which no one has suggested. I shall try it and let you know.
  2. What should I be doing then. There must be a way to do this. Every example I have seen involves storing code in the database.
  3. Hi, There is something seriously wrong with echoing the code from the database. I put this simple test on my page which echoes toad. $test = toad; echo $test; ?> But when I try it in echoing it from my database it doesn't display anything. The issue is echoing the code from the database. $test = toad; echo $test; ?>
  4. Could you explain the logic and what I am supposed to do with it.
  5. I'm trying to echo the following code from a database. I'm not sure how I can explain it any easier. <?php $query = mysql_query(" SELECT name, linkname, product_id, price, discount, image_link FROM productdbase p INNER JOIN furniture_groups f ON f.id = p.id WHERE linkname LIKE '%coffee%' LIMIT 15"); while ($query_row = mysql_fetch_assoc($query)) { ?> <div class="productrangeborder"> <div class="productsdetailsborder"> <a href="http://website.co.uk/products/product/<?php echo $query_row['product_id']; ?>" class='productlink' rel="nofollow" ><?php echo $query_row['name']; ?> </a> </div> <div class="productimageborder"> <a href="http://website.co.uk/products/product/<?php echo $query_row['product_id']; ?>" rel="nofollow"><img src="<?php echo $query_row['image_link']; ?>" alt="<?php echo $query_row['name']; ?>" /></a> </div> <div class="priceborder">Price £<?php echo $query_row['price']; ?><br /></div><div class="discountborder">Save <?php echo $query_row['discount']; ?>%<br /> </div></div> <?php } ?> I dont know what this code is supposed to do. All it does is echo the title of the blog. $original = "This is some test about {{foo}}, and how good it is"; $text = preg_replace_callback( '/\{(.*?)\}/', function() { // some logic to return "foo" from the database } , $original ); echo $text;
  6. This echoes title of the blog post regardless of whether I include the $original variable or not. Are you suggesting your code goes after my code and your code echoes the existing code I readly have?
  7. I want to echo products from a database in the middle of certain blog posts. So if Im writing about Mario Console games I can echo "Mario" from my database into a product outlay. It works on a standard page but I need echo it on specific blog posts which are stored in my database.
  8. Thanks, How can I echo a 'widget' onto a pirticular blog post?
  9. Hi, I am trying add a widget to certain blog post so that it display products. Just like an image would appear. The code works fine when I paste onto a standard page but when I try to echo it from a database it displays the second peice of PHP code as it was standard text. Any suggestions please? <?php echo $query_row['name']; ?> <?php $query = mysql_query(" SELECT name, linkname, product_id, price, discount, image_link FROM productdbase p INNER JOIN furniture_groups f ON f.id = p.id WHERE linkname LIKE '%coffee%' LIMIT 15"); while ($query_row = mysql_fetch_assoc($query)) { ?> <div class="productrangeborder"> <div class="productsdetailsborder"> <a href="http://website.co.uk/products/product/<?php echo $query_row['product_id']; ?>" class='productlink' rel="nofollow" ><?php echo $query_row['name']; ?> </a> </div> <div class="productimageborder"> <a href="http://website.co.uk/products/product/<?php echo $query_row['product_id']; ?>" rel="nofollow"><img src="<?php echo $query_row['image_link']; ?>" alt="<?php echo $query_row['name']; ?>" /></a> </div> <div class="priceborder">Price £<?php echo $query_row['price']; ?><br /></div><div class="discountborder">Save <?php echo $query_row['discount']; ?>%<br /> </div></div> <?php } ?>
  10. Hi, I have the following code which should insert information into two tables "productdbase" and "furniture_groups". However the code inserts more lines into productdbase than what it does into furniture_groups. For example products 1-10 will be inserted into productdbase but only 1,3,4,7 and 9 will be inserted into furniture_groups. However there appears to be nothing different between lines 2 and 3 or 6 and 7. Is it possible to create a code as to why something wont insert into a table? $fp = $zip->getStream("datafeed_98057.xml"); //file inside archive if(!$fp) die("Error: can't get stream to zipped file"); $buf = ""; ob_start(); while (!feof($fp)) $buf .= fread($fp, 2048); $s = ob_get_contents(); ob_end_clean(); if(stripos($s, "CRC error") != FALSE) die('CRC32 mismatch'); fclose($fp); $zip->close(); $ax = strocc($buf, '<prod', '</prod>'); echo '<pre>'; for($i=0; $i<sizeof($ax); $i++) { $arr = $ax[$i]; echo strpp($arr, '<pId>', '</pId>') ."<br />"; echo strpp($arr, '<mCat>', '</mCat>') ."<br />"; echo strpp($arr, '<awCat>', '</awCat>') ."<br />"; $desc = ''; if(strpos($ax[$i], '<desc>')!==FALSE) { $desc = safe_string_escape(strpp($ax[$i], '<desc>', '</desc>')); } $discount = 0; if(floatval(strpp($arr, '<rrp>', '</rrp>'))!=0) $discount = 100 - (floatval(strpp($arr, '<buynow>', '</buynow>')) / floatval(strpp($arr, '<rrp>', '</rrp>')) * 100); mysql_query("insert into productdbase SET image_link = '" .safe_string_escape(strpp($arr, '<awImage>', '</awImage>')) ."', link = '" .safe_string_escape(strpp($arr, '<awTrack>', '</awTrack>')) ."', name = '" .safe_string_escape(strpp($arr, '<name>', '</name>')) ."', linkname = '" .str_replace("---", "-", str_replace(" ", "-", safe_string_escape(strpp($arr, '<name>', '</name>')))) ."', fulldescription = '$desc', merchant_category = '" .safe_string_escape(strpp($arr, '<mCat>', '</mCat>')) ."', price = '" .safe_string_escape(strpp($arr, '<buynow>', '</buynow>')) ."', discount = '$discount', merchant = '" .safe_string_escape(strpp($arr, 'name="', '"')) ."', promotional_text = '$desc', id = '" .strpp($arr, '<pId>', '</pId>') ."'"); mysql_query("insert into furniture_groups SET long_name = '" .safe_string_escape(strpp($arr, '<mCat>', '</mCat>')) ."', short_name = '" .safe_string_escape(strpp($arr, '<awCat>', '</awCat>')) ."', id = '" .strpp($arr, '<pId>', '</pId>') ."'"); //echo mysql_error(); } } else echo "zip not found"; unlink($file); function strocc($str, $pos1, $pos2) { $pos=0; $occ=array(); while(strpos($str, $pos1, $pos) && strpos($str, $pos2, strpos($str, $pos1, $pos))) { array_push($occ, strpp($str, $pos1, $pos2, $pos)); $pos = strpos($str, $pos2, strpos($str, $pos1, $pos)); } return ($occ); } function strpp($str, $pos1, $pos2, $startoffset=0) { return substr($str, (strpos($str, $pos1, $startoffset)+strlen($pos1)), strpos($str, $pos2, strpos($str, $pos1, $startoffset)+strlen($pos1))-(strpos($str, $pos1, $startoffset)+strlen($pos1))); } function mysqlinit($user, $pass, $db, $host='localhost') { $link = mysql_connect($host, $user, $pass); if (!$link) { echo('Cant connect to MySQL : ' .mysql_error()); return 0; } $db_selected = mysql_select_db($db, $link); if (!$db_selected) { echo('Cant use database ' .$db .': ' .mysql_error()); return 0; } return 1; } function safe_string_escape($str) { $len=strlen($str); $escapeCount=0; $targetString=''; for($offset=0;$offset<$len;$offset++) { switch($c=$str{$offset}) { case "'": if($escapeCount % 2 == 0) $targetString.="\\"; $escapeCount=0; $targetString.=$c; break; case '"': if($escapeCount % 2 == 0) $targetString.="\\"; $escapeCount=0; $targetString.=$c; break; case '\\': $escapeCount++; $targetString.=$c; break; default: $escapeCount=0; $targetString.=$c; } } return $targetString; }
  11. Hi, I have the following code which should insert information into two tables "productdbase" and "furniture_groups". However the code inserts more lines into productdbase than what it does into furniture_groups. For example products 1-10 will be inserted into productdbase but only 1,3,4,7 and 9 will be inserted into furniture_groups. However there appears to be nothing different between lines 2 and 3 or 6 and 7. Is it possible to create a code as to why something wont insert into a table? $fp = $zip->getStream("datafeed_98057.xml"); //file inside archive if(!$fp) die("Error: can't get stream to zipped file"); $buf = ""; ob_start(); while (!feof($fp)) $buf .= fread($fp, 2048); $s = ob_get_contents(); ob_end_clean(); if(stripos($s, "CRC error") != FALSE) die('CRC32 mismatch'); fclose($fp); $zip->close(); $ax = strocc($buf, '<prod', '</prod>'); echo '<pre>'; for($i=0; $i<sizeof($ax); $i++) { $arr = $ax[$i]; echo strpp($arr, '<pId>', '</pId>') ."<br />"; echo strpp($arr, '<mCat>', '</mCat>') ."<br />"; echo strpp($arr, '<awCat>', '</awCat>') ."<br />"; $desc = ''; if(strpos($ax[$i], '<desc>')!==FALSE) { $desc = safe_string_escape(strpp($ax[$i], '<desc>', '</desc>')); } $discount = 0; if(floatval(strpp($arr, '<rrp>', '</rrp>'))!=0) $discount = 100 - (floatval(strpp($arr, '<buynow>', '</buynow>')) / floatval(strpp($arr, '<rrp>', '</rrp>')) * 100); mysql_query("insert into productdbase SET image_link = '" .safe_string_escape(strpp($arr, '<awImage>', '</awImage>')) ."', link = '" .safe_string_escape(strpp($arr, '<awTrack>', '</awTrack>')) ."', name = '" .safe_string_escape(strpp($arr, '<name>', '</name>')) ."', linkname = '" .str_replace("---", "-", str_replace(" ", "-", safe_string_escape(strpp($arr, '<name>', '</name>')))) ."', fulldescription = '$desc', merchant_category = '" .safe_string_escape(strpp($arr, '<mCat>', '</mCat>')) ."', price = '" .safe_string_escape(strpp($arr, '<buynow>', '</buynow>')) ."', discount = '$discount', merchant = '" .safe_string_escape(strpp($arr, 'name="', '"')) ."', promotional_text = '$desc', id = '" .strpp($arr, '<pId>', '</pId>') ."'"); mysql_query("insert into furniture_groups SET long_name = '" .safe_string_escape(strpp($arr, '<mCat>', '</mCat>')) ."', short_name = '" .safe_string_escape(strpp($arr, '<awCat>', '</awCat>')) ."', id = '" .strpp($arr, '<pId>', '</pId>') ."'"); //echo mysql_error(); } } else echo "zip not found"; unlink($file); function strocc($str, $pos1, $pos2) { $pos=0; $occ=array(); while(strpos($str, $pos1, $pos) && strpos($str, $pos2, strpos($str, $pos1, $pos))) { array_push($occ, strpp($str, $pos1, $pos2, $pos)); $pos = strpos($str, $pos2, strpos($str, $pos1, $pos)); } return ($occ); } function strpp($str, $pos1, $pos2, $startoffset=0) { return substr($str, (strpos($str, $pos1, $startoffset)+strlen($pos1)), strpos($str, $pos2, strpos($str, $pos1, $startoffset)+strlen($pos1))-(strpos($str, $pos1, $startoffset)+strlen($pos1))); } function mysqlinit($user, $pass, $db, $host='localhost') { $link = mysql_connect($host, $user, $pass); if (!$link) { echo('Cant connect to MySQL : ' .mysql_error()); return 0; } $db_selected = mysql_select_db($db, $link); if (!$db_selected) { echo('Cant use database ' .$db .': ' .mysql_error()); return 0; } return 1; } function safe_string_escape($str) { $len=strlen($str); $escapeCount=0; $targetString=''; for($offset=0;$offset<$len;$offset++) { switch($c=$str{$offset}) { case "'": if($escapeCount % 2 == 0) $targetString.="\\"; $escapeCount=0; $targetString.=$c; break; case '"': if($escapeCount % 2 == 0) $targetString.="\\"; $escapeCount=0; $targetString.=$c; break; case '\\': $escapeCount++; $targetString.=$c; break; default: $escapeCount=0; $targetString.=$c; } } return $targetString; } Quick reply to this message Reply Reply With Quote Reply With Quote Multi-Quote This Message
  12. Hi, I have been trying my hand at MySQLi but I have noticed a frustrating space appears after the echo. The below code adds a space between the discount and the percentage sign so it appears as 32 % instead of 32%. I have tried removing all the spaces in the code but it still appears. Can anyone advise how to remove this space? Save <?php printf("%s\n",$row["discount"]);?>%<br />
  13. Hi, I have by means of complete fluke managed to build a MySQLi join query. However I cant figure out how to echo the results inside HTML. I have echoed $long_name and $name here: /* check connection */ if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } $room = mysql_real_escape_string($_GET['room']); echo $room; $query = "SELECT long_name, name FROM furniture_groups a INNER JOIN productdbase b ON a.id = b.product_id WHERE `room` = '$room' LIMIT 15 "; if ($result = $mysqli->query($query)) { while ($row = $result->fetch_assoc()) { printf ("%s (%s)\n", $row["long_name"], $row["name"]); ?>But I would like to echo it here inside the HTML. <div class="productrangeborder"> <div class="productsdetailsborder"> <a href="http://domain.co.uk/products/product/<?php echo $query_row['long_name']; ?>" class='productlink' rel="nofollow" ><?php echo $query_row['name']; ?> </a> </div> </div></div> <?php } } ?>
  14. Apologies Kevin for getting your name wrong. Got the code working. Many thanks for everyones help. I wish I had $80 to regularly spend on code. I have a full time job but haven't had a pay rise in 4 years. I have been flipping books on Amazon which has been going for the last 4 weeks. Hopefully thay will continue to grow.
  15. Hi Keith, I agree that I have to pay and if I am getting value I dont mind, however: 1. I have already paid for the original code 2. I have had this code working before so I know it works 3. An experienced coder can do this in 3 minutes flat so why would I pay $80.00
  16. Couldn't agree with you more. As soon I can finish coding the better.
  17. Hi, I also tried this. Can run two queries together? mysql_connect($host, $username, $password); mysql_select_db($database); $query = mysql_query("SELECT * FROM furniture_groups "); while($row = mysql_fetch_array($query)) { echo $row['long_name']; $query = mysql_query('UPDATE `furniture_groups` SET `room` = CASE WHEN `long_name` LIKE \'%kitchen%\' THEN \'Kitchen\'
  18. Many thanks, I got this working. I reloaded the Javascript files and that sorted it but I cant remember changing the first files I uploaded. I have also found this same code on a site that is trying to sell it. Looks like they stole some free code to make money from it. Naughty.
  19. Hi, Now the page just displays four rows of the images. I notice that you have js/modernizr but I thought it would /js/mo... <script src="js/modernizr.custom.63321.js"></script> I also don't understand how "main" can be be in the HTML but not in the CSS file. The same with "container".
  20. There is one thing I dont understand. These two divs aren't in the CSS code but are in the HTML source code for the demo. <div class="container"> <div class="main">
  21. Bloody hell, I previously copied any posted the CSS but uploaded the original CSS and still no impact. Do you have the code working I could look at? I cant see what Im doing wrong.
  22. Hi, I have tried to slim it down the bare minimum. The two links to the .js files work and I have uploaded the image but there is no functionality on the page. <head> <link rel="stylesheet" href="/stylesheet.css" type="text/css" /> <script src="/products/modernizr.custom.63321.js"></script> </head> <body> <div class="container"> <div class="main"> <div id="mi-slider" class="mi-slider"> <ul> <li><a href="#"><img src="/images/1.jpg" alt="img01"><h4>Boots</h4></a></li> <li><a href="#"><img src="/images/2.jpg" alt="img02"><h4>Oxfords</h4></a></li> <li><a href="#"><img src="/images/3.jpg" alt="img03"><h4>Loafers</h4></a></li> <li><a href="#"><img src="/images/4.jpg" alt="img04"><h4>Sneakers</h4></a></li> </ul> <ul> <li><a href="#"><img src="/images/1.jpg" alt="img01"><h4>Boots</h4></a></li> <li><a href="#"><img src="/images/2.jpg" alt="img02"><h4>Oxfords</h4></a></li> <li><a href="#"><img src="/images/3.jpg" alt="img03"><h4>Loafers</h4></a></li> <li><a href="#"><img src="/images/4.jpg" alt="img04"><h4>Sneakers</h4></a></li> </ul> <ul> <li><a href="#"><img src="/images/1.jpg" alt="img01"><h4>Boots</h4></a></li> <li><a href="#"><img src="/images/2.jpg" alt="img02"><h4>Oxfords</h4></a></li> <li><a href="#"><img src="/images/3.jpg" alt="img03"><h4>Loafers</h4></a></li> <li><a href="#"><img src="/images/4.jpg" alt="img04"><h4>Sneakers</h4></a></li> </ul> <ul> <li><a href="#"><img src="/images/1.jpg" alt="img01"><h4>Boots</h4></a></li> <li><a href="#"><img src="/images/2.jpg" alt="img02"><h4>Oxfords</h4></a></li> <li><a href="#"><img src="/images/3.jpg" alt="img03"><h4>Loafers</h4></a></li> <li><a href="#"><img src="/images/4.jpg" alt="img04"><h4>Sneakers</h4></a></li> </ul> <nav> <a href="#">Shoes</a> <a href="#">Accessories</a> <a href="#">Watches</a> <a href="#">Bags</a> </nav> </div> </div> </div><!-- /container --> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> <script src="/products/jquery.catslider.js"></script> <script> $(function() { $( '#mi-slider' ).catslider(); }); </script> </body> </html>
×
×
  • 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.