Jump to content


  • Posts

  • Joined

  • Last visited

Posts posted by chibineku

  1. I think the problem is the chained .next() methods. Try splitting it into two statements, or try using .end() to reset the chain to $(this):


  2. If your page has a width set, in %, px or whatever, then you can give it margin: 0 auto; to center it. Apply this to either the body or a containing element. It's with setting a width - most pages don't look good edge to edge.

  3. I liked this joke about programmers vs. engineers:

    A programmer and an engineer agree to a psychological experiment.The programmmer is put in a chair in a large empty room and abeautiful naked woman is placed on a bed at the other end of the room.The psychologist explains, "You are to remain in your chair. Everyfive minutes, I will move your chair to a position halfway between itscurrent location and the woman on the bed." The programmer looksat the psychologist in disgust. "What? I'm not going to go throughthis. You know I'll never reach the bed!" And he gets up and stormsout. The psychologist makes a note on his clipboard and ushers theengineer in. He explains the situation, and the engineer's eyeslight up and he starts drooling. The psychologist is a bit confused."Don't you realize that you'll never reach her?" The engineer smilesand replies, "Of course! But I'll get close enough for all practicalpurposes!"
    Note: I :) ed for the exact wording and found that this joke has also been used as a mathematician vs. physicist joke, but it works exactly the same.
  4. The first step is to check if your page validates - both as XHTML 1.1 and CSS. The CSS is fine, but there are a number of problems with the XHTML, the first being that there is an error in your doctype:

    Warning Mismatch between Public and System identifiers in the DOCTYPE declarationThis document uses an inconsistent DOCTYPE declaration. The Public Identifier -//W3C//DTD XHTML 1.0 Strict//EN declares the XHTML 1.0 Strict document type, but the associated System Identifier http://www.w3.org/TR/xhtml2/DTD/xhtml1-strict.dtd does not match this document type.The recommended System Identifier for XHTML 1.0 Strict is http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd.
    Fixing that might sort out some of your problems, since with an invalid doctype the page will probably revert to quirks mode.
  5. The array $a holds a list of words that can be used to provide an auto complete hint. The first loops works through each character of the query string $q and compares it to the elements in $a. If the two match, then $hint is set to the full entry in the suggestion array $a. As $q gets longer, the comparison can be made more accurately, so it will appear to refine the $hint. That might not have been the clearest explanation, but I hope it helped somewhat. Perhaps an example.If I type 'a', then $q == 'a'.The loop finds an entry from $a that starts with 'a' - let's say aardvark - and returns the hint $hint == 'aardvark'.Then I type 'ab', so the loops finds any entries starting with 'ab' and returns that - say 'abba'.Next I type 'aby' and the only word in the dictionary is 'abyss', so that is what $hint becomes. It's a constant refinement until the only viable option becomes apparent.

  6. There are errors on most complicated and sophisticated websites. Amazon has nearly 1000 errors and half again as many warnings. Some things work on some browsers and some things don't; some things affect the content and some don't. There are errors you can live with and those you can't. But validation is a factor in SEO, so it's a definite boon to a small website to validate. For the bigger sites that everyone knows by name and have already earned the top slot on google, it's not an issue anymore so they sacrifice standards for solutions. If you have a huge team of developers and content editors, there will be clashes and maintaining standards is probably nearly impossible all the time.

  7. The different DTDs determine which set of HTML elements are valid and how they're used and displayed. A strict DTD tends to get greater consistently across browsers and your CSS will be more robust. For example, if I use a strict DTD and change the padding of a div, the space around the content of the div increases, but the div stays the same size. If I increase the margin, the space around the div increases, but the size is the same. If I use a transitional doctype and change the padding of an element, it gets wider and taller by as much as the padding increase. If I change the margin, the div gets narrower. At least, that happens sometimes in IE - in other browsers, what happens when I make these changes is unpredictable. As a general rule, using a strict doctype, particularly XHTML 1.1 is the best practice. Your CSS changes will be easier because the results are predictable. Your site will look the same pretty much anywhere. I spent a frustrating hour trying to make simple changes to the layout of an ExpressionWeb template the other day until I checked the DTD and saw the evil word - transitional. I changed it to strict and had the page looking as I wanted it in 20 minutes.

  8. A final note:Adding the AJAX to the complete function of the animate method was the key, but because I was using .each() to fade in 4 elements, the AJAX fired 4 times, making the animation juddery. I changed the PHP to return the elements wrapped in a div and faded it in and out, and the result is smooth as the proverbial baby's bum.

  9. Okay, actually it isn't working right. It still skips to the fade in. I tried changing the position of the fade in to before the AJAX call, to after. Sometimes it hangs for a sec if positioned before the AJAX call. Here is what I'm using now:

    $(document).ready(function() {   setTimeout("getTestimonial()", 10000);});   function getTestimonial() {	 var counter = $('#products #cart-widget .counter').html();		$('#products #cart-widget p > span').each(function(index) {		   if($(this).is('.counter')) {		   } else {			  $(this).animate({opacity: 0}, 1000, function(){});		   }		});	$.get("testimonials_include.php5", {'counter':counter}, function(data) {	   $('#products #cart-widget p').replaceWith(data);	   $('#products #cart-widget p').children().css("opacity",0);$('#products #cart-widget p > span').each(function(index) {   if($(this).is('.counter')) {   } else {	  $(this).animate({opacity: 1}, 1000, function(){});   }});	});	setTimeout("getTestimonial()", 10000);   }

    You can see it here: testimonial box on right

  10. I have an AJAX function that cycles through testimonials and fades the new one in, but for some reason the fadeOut() method won't work, despite the syntax being the same.Here is the function:

    $(document).ready(function() {   setTimeout("getTestimonial()", 10000);});   function getTestimonial() {	 var counter = $('#products #cart-widget .counter').html();	$.get("testimonials_include.php5", {'counter':counter}, function(data) {	   $('#products #cart-widget p > span').each(function(index) {	   if($(this).is('.counter')) {		 } else {	   $(this).fadeOut('slow', function() {});		 }	   });	   $('#products #cart-widget p').replaceWith(data);	   $('#products #cart-widget p').children().css("display","none");	   $('#products #cart-widget p > span').each(function(index) {		 if($(this).is('.counter')) {		 } else {	   $(this).fadeIn('slow', function() {});		 }	   });	});	setTimeout("getTestimonial()", 10000);   }

    I wasn't able to get the fadeIn to work until I had set the display of the new elements to none. I tried specifically setting the display of the existing elements to block before the fadeOut and still nothing.

  11. That's a good idea, DD, and I tried it, setting counter=1. As with the live page, the script seems to ignore the counter parameter and just delivers me a random result, which can have the same id as the counter parameter. Echoing $not made me realise that my ternary operator assignment wasn't working for some reason, but I changed it for a basic if and it works great now. I can't see what was wrong with the ternary statement, but anyhoo.Many thanks for the sound advice - I don't know why I don't already do these things, like echoing variables, as soon as I have a problem. I should know better by now.

  12. I have a PHP script which selects a random row from a database and echoes a formatted string. This is used at page load to display a random testimonial and the same script is used in an AJAX function to swap the testimonial every 5 seconds. I don't want to get the same testimonial twice in a row, so as part of the output there is a hidden span containing the id of the result row. I send this as a parameter in my AJAX function and want to exclude this id from the next select statement.Here is my current PHP script, with SELECT statement:

    <?phpinclude_once("db_include.php5");doDB();$not = (isset($_GET["counter"]))?"":"WHERE id NOT IN (".$_GET['counter'].")";$rand_sql = "SELECT * FROM edhypTestimonials $not ORDER BY RAND() LIMIT 1";$rand_res = mysqli_query($mysqli, $rand_sql) or error_log(mysqli_error($mysqli)."\r\n");$info = mysqli_fetch_array($rand_res);	  $search_res = '';		$id = $info["id"];		$name = $info["name"];		$testimony = $info["testimony"];		$search_res.= "<p><span class='counter' style='display: none;'>$id</span><span class='quote'>\"</span>$testimony<span class='quote'>\"</span><span class='name'>-$name</span></p>";echo $search_res;?>

    And here is the AJAX:

    $(document).ready(function() {   setTimeout("getTestimonial()", 5000);});   function getTestimonial() {	 var counter = $('#products #cart-widget .counter').html();	$.get("testimonials_include.php5", {'counter':counter}, function(data) {	   $('#products #cart-widget p').replaceWith(data);	});	setTimeout("getTestimonial()", 5000);   }

    I am watching the console in Firebug and can see that the counter parameter is sent, but there must be something wrong with the SELECT as the same testimonial sometimes comes up several times in a row (there are only two entries in the database at present, just placeholders).I'm not good at making SQL queries but it doesn't seem like it should be any more complicated than that. Can anyone point me in the right direction?Additionally, the first time the script runs, as an include, it doesn't properly fetch a result, only once it's called by the jQuery function.

  13. I said the above code was the problem, and it's true that the logic seems to fail, but I preceded that code with:

    foreach($_COOKIE as $k => $v) { echo $k.": ".$v."<br />";}

    And it STILL didn't find the cookie I was looking for. It's most unusual.

  • Create New...