Jump to content
Larry Ullman's Book Forums

Max

Members
  • Content Count

    101
  • Joined

  • Last visited

Community Reputation

2 Neutral

About Max

  • Rank
    Advanced Member
  1. OK, have just got it. There is no need to use YEAR() function as the Date column will accept SELECT * FROM Timeline WHERE Date LIKE '%$i%' SORT BY Date ASC All working now. www.gssr.es/timeline.php Adios!
  2. Hi Larry and everyone, I have really painted myself into a corner with this one. Above is the database that I created for a timeline. The issue is that not all of the dates at my disposition have days and months. Some are just years. Hence, I had to make a separate column for years only. What I want to do is create a timeline using tables so that any year that has either a YYYY date and/or a YYYY-MM-DD date appears in chronological order. I tried it with a for loop starting at $i = 1700 - 2000 which works for the first year but the while ($enquiry3 = @mysqli_fetch_array($enquiry2)) { will only iterate once and then stops. The alternative is to use MySQL such as: for($i = 1700; $i <= 2000; i++) { $enquiry = "SELECT * from Timeline WHERE Year = $i ORDER BY Year ASC" } which works OK for getting the year only files. Then we need to get the full date files so we try: for($i = 1700; $i <= 2000; i++) { $enquiry = " SELECT * from Timeline WHERE Date = YEAR($i, %Y) ORDER BY Date ASC" } ....but the date function doesn't seem to work. Any ideas??? Regards Max
  3. Hi all, Well, finally solved it. What really complicated matters was that my browser was converting the (correct) answer from php back to html entities! This led me to believe that php wasn't actually doing anything. So, it has all come down to two lines of code:.... $search = trim($_POST['Search']); $search = htmlentities($search); Now, php can do the MySQL search and now finds matches. To get round the problem on the test script I added as the first line: header('Content-Type: text/plain'); .....so now my test script works as well. Best regards and thank you, Larry. Max
  4. Hi Larry, html : <meta charset="utf-8"> <!--[if lt IE 9]> <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> MySQL: Collation on all relevant columns and tables are utf-8_unicode_ci When I use phpMyAdmin the accented characters show as ASCII entities (i.e. á = &aacute;), which is what I want. It all works fine: Inauguraci&oacute;n. Bendici&oacute;n de las locomotoras - &Aacute;guilas. Marzo 1890. - from phpMyAdmin becomes..... Inauguración. Bendición de las locomotoras - Águilas. Marzo 1890. The entities in MySQL have been converted to accented text as wanted. The problem seems to be that php isn't recognising the accented characters and thus not converting them to ASCII entities for the search engine that I am trying to create. Thanks as always for your time and help.
  5. I have come across htmlentities and htmlspecialchars but neither seems to work. Here is a Q&D test: <?php if(isset($_POST['char'])) { $char = $_POST['char']; $char2 = htmlentities($char); echo 'Answer: ' . $char . '<br /><br />'; echo $char2; } echo '<form action = "char_test.php" method = "post"> <input type = "text" name = "char" size = "6"> <input type = "submit" name = "submit" value = "Search!" /> </form>'; if I entered á then I would expect the answer to be: Answer: á &aacute; but I get: Answer: á á This goes for all of the characters that I have tried. Surely php wouldn't put something in their manual that doesn't work?
  6. Hi Larry and everyone, I'm still using your book as php is still reducing me to tears. Here is the problem: I have created a large database in English and Spanish. In spite of setting the MySQL db to UTF-8 it still returns nonsense characters with eg accented 'a', so I have been entering all of the text with accents as for example á = &aacute;, Ú = &Uacute;, ñ = &ntilde; as the only way to guarantee that they print correctly when called. The problem is that when a Spaniosh speaker does a search, then they will search for eg 'Estación' not 'Estaci&oacute;n. The php if conditional doesn't recognise accented characters so I need to parse each word letter by letter and convert any accented character to its ASCII decimal to then convert it to the ASCII entity i.e. 'á' => &225; => &aacute; to present to MySQL. I can't find a converter in the turgid php manual so am stuck. I have re-read your chapter 'Making Universal Sites' but have now resorted to coming home to daddy. Thanks Max
  7. The words are fact. I will look at including regular exressions in the glob(). Regards Max
  8. Further to the above comment, I have stumbled across something called 'imagick' which is part of the PHP domain. The PHP manual says something like this: bool Imagick::resizeImage ( int $columns , int $rows , int $filter , float $blur [, bool $bestfit = false ] ) ..and gives examples like this: <?php function resizeImage($imagePath, $width, $height, $filterType, $blur, $bestFit, $cropZoom) { //The blur factor where > 1 is blurry, < 1 is sharp. $imagick = new \Imagick(realpath($imagePath)); $imagick->resizeImage($width, $height, $filterType, $blur, $bestFit); $cropWidth = $imagick->getImageWidth(); $cropHeight = $imagick->getImageHeight(); if ($cropZoom) { $newWidth = $cropWidth / 2; $newHeight = $cropHeight / 2; $imagick->cropimage( $newWidth, $newHeight, ($cropWidth - $newWidth) / 2, ($cropHeight - $newHeight) / 2 ); $imagick->scaleimage( $imagick->getImageWidth() * 4, $imagick->getImageHeight() * 4 ); } header("Content-Type: image/jpg"); echo $imagick->getImageBlob(); } ?> ...which I can't get to work. Larry - perhaps this could be a subject for your next book? Last time I suggested a book, you brought out the excellent (but headache inducing ) Javascript - Develop and Design, which I was pleased to buy but had to read about 5 times for it to start to sink in. Old dogs and new tricks??? I'm sure it would be a good seller. You certainly have a way of explaining very complex subjects.
  9. Another question for Larry. I would like to offer a library of all of the thousands of images that I have in my raw data directory by displaying thumbnails. I know I can use: <a href = "images/raw/yadayada.jpg" target = "_blank"><img style = "width: 100px;" src = "images/raw/yadayada.jpg" .... /> </a> but this will involve huge overheads as it will mean downloading approx 1Mb images and then resizing them in the browser, so I would prefer to resize the images in PHP before downloading them, but I can't find any reference to this in the PHP manual, or the PHP GD manual. Any advice would be much appreciated. Max
  10. Just spotted a problem with the script - it is only checking files with the extension .jpg, not .JPG. Have changed: //Now create a variable ($getlisting) to be able to call only the category that we are interested in... $getlisting = 'images/' . $category . '/*.jpg'; to: //Now create a variable ($getlisting) to be able to call only the category that we are interested in... $getlisting = 'images/' . $category . '/*.*'; - can't really see any neat way around it. I suppose I could run it twice, once with .jpg and then with .JPG, then run the .JPGs through strtolower and then combine them in the $getlisting array to then be compared with the raw files. Any comments please.
  11. Hi Larry I thought that I'd post this as it might help other php-ers. I have a website which has many images. To facilitate the download of images, I save a reduced image under a directory name e.g. images/activities/P3451098.jpg for thumbnails and slideshows as well as the full size in e.g. images/raw/P3451098.jpg. Then I can offer an enlarged image using <a href = ***><img src...... target = "_blank"> etc. The problem is that as I send the images up using FTP (Filezilla) I can't be sure if all of the reduced images have the corresponding full sized images thanks to advanced dementia. Therefore, I have written a short routine to compare the two directories.... COMMENTS: 1) I was confused at first as to why it didn't work properly until I discovered that glob() is case sensitive, so that it wasn't finding .JPGs so had to run it twice (there is a variety of both depending on which camera they came from). 2) The search routine is not very elegant as it runs through all of the raw files even though it may have found a match in the first file. 3) I know that I could use glob(images/raw/*.*) instead of glob(images/raw/*.*) and in this case it wouldn't make any difference as all files in these directories are .jpgs - it just seems more precise to use *.jpg. I would appreciate any comments from anybody..... <?php //Declare variable $found to avoid undefined variable errors $found = "No"; //Call header which handles security and error messages include ('adminheader.php'); //Create an array $images which lists all of the relevant image directories on the server.. $images = array('4X4', 'activities', 'almonds', 'alojamiento', 'altiplano', 'archery', 'area', 'artifacts', 'baza', 'castillejar', 'castril', 'caving', 'fiestas', 'flowers', 'history', 'huescar', 'kayaking', 'index', 'markets', 'mountaineering', 'mountains', 'museums', 'photography', 'puebla', 'rafting', 'village', 'wildlife', 'activities/activities', 'activities/caving', 'activities/kayaking', 'activities/mountaineering', 'activities/outdoors', 'activities/rafting'); //Create array $raw which will be a listing of all of the large image files on the server $raw = glob('images/raw/*.jpg'); $raw2 = glob('images/raw/*.JPG'); //Work through the $images array so as to compare whether there is a large matching file in the 'raw' directory... foreach($images as $key => $category) { //Start with a header to ID each category.... echo 'CATEGORY:... ' . $category . '<br /><br />'; //Now create a variable ($getlisting) to be able to call only the category that we are interested in... $getlisting = 'images/' . $category . '/*.jpg'; //create an array of the files in this category.. $listing = glob($getlisting); //Run through the $raw array to see if it contains a file that matches the file in the category... foreach($listing as $key => $value) { //Create variable to use in str_replace.. $directory = 'images/' . $category . '/'; // Remove the unwanted directory details.... $value = str_replace($directory, "", $value); //Reduce any JPGs to jpgs... $value = strtolower($value); //Run through the $raw array to find a match.. foreach($raw as $key => $rawvalue) { //Get rid of directory details from $rawvalue... $rawvalue = str_replace("images/raw/", "", $rawvalue); //Bring any .JPGs to .jpgs.... $rawvalue = strtolower($rawvalue); //Do comparison. If raw image matches reduced image then do nothing.. if ($value == $rawvalue) { //If the small and large files match then switch variable $found to 'on'.... $found = "Found"; } } //Run through the $raw array to find a match.. foreach($raw2 as $key => $rawvalue) { //Get rid of directory details from $rawvalue... $rawvalue = str_replace("images/raw/", "", $rawvalue); //Bring any .JPGs to .jpgs.... $rawvalue = strtolower($rawvalue); //Do comparison. If raw image matches reduced image then do nothing.. if ($value == $rawvalue) { //If the small and large files match then switch variable $found to 'on'.... $found = "Found"; } } //If small and large files don't match, then print out the filename .. if ($found != "Found") { echo $value . "<br /><br />"; } //reset $found to "Not found".. $found = "No"; } //Close individual Category foreach echo "<br /><br />"; } //Close all category foreach echo "ALL DONE!"; include ('footer.php'); ?>
  12. STOP PRESS!! Darn it! I have just found a much easier way, thanks to your book (Chapter 2):.... Create array of all jpg files on server in the images/activities/activities directory: $listing = glob("images/activities/activities/*.jpg"); Use 'shuffle() to change the order of the jpg files in the array: shuffle($listing); Use 'foreach()' to trawl through the array to extract the filenames: foreach($listing as $key => $value) { This is a bit of js: echo '<div class="mySlides fade"> <img src = "' . $value . '" style=" display: block; margin: auto; width:80%; border-style: solid; border-width: 2px; border-color: black; vertical-align: top;" alt = "Sorry - image missing." /> </div>'; echo '<div style="text-align:center"> <span class="dot"></span> </div>'; $repeat = 1; } That also solves the issue of repeats. KISS - keep it simple, STOOPID! Regards Max
  13. Hi Larry. I am sure that this has been done elsewhere, but I thought I would share it with you anyway. I have a website that displays a slideshow of images of where I live ( www.beautifulcastril.com ). To make things cleaner and quicker, I just upload the jpgs to the server via Filezilla and then, in the program use glob() to bring their filenames into an array. I then used to pass through the array using foreach() to display the images automatically using js and CSS as per your book Chapter 2. The irritating thing was that they always came out in the same order so I have changed the php to randomize the image order. I have added comments in red specifically for this post:.... <?php include ('header.php'); ?> <table style = "width: 100%; border: 0; table-layout: fixed;"> <tr><td style = "width: 20%"><a href="castril.php"><img src = "images/village/P9040321.jpg" style = "width: 100%;" alt = "Sorry - image missing" title = "Click here" /></a></td><td style = "width: 20%;"><a href="castril.php" id = "area1">Castril town</a></td><td rowspan = "6" style = "vertical-align: top; margin: auto;"> This starts the js/CSS: <div class="slideshow-container" style = "margin: auto;"> <?php Get the images from the server and put them into an array called '$listing' using glob(): $listing = glob("images/area/*.jpg"); Find out how many files there are and subtract 1 as they start with 0: $arrlength = count($listing) - 1; Do a for/next loop to run through the whole array (from 0 to the length of the array - 1: for($x = 0; $x < $arrlength; $x++) { Get a random number between 0 and array length - 1 using mt_rand() which apparently is quicker than rand(): $random_keys = mt_rand(0, $arrlength); $value is the filename related to the random number obtained above: $value = $listing[$random_keys]; Use some js to take the filename and produce the image (see below): echo '<div class="mySlides fade"> <img src="' . $value . '" style="display: block; margin: auto; width:80%; border-style: solid; border-width: 2px; border-color: black; vertical-align: top;" alt = "Sorry - image missing"> </div>'; echo '<div style="text-align:center"> <span class="dot"></span> </div>'; $repeat = 1; //Can't remember what this does!!! } ?> </div> <br> Now for the js: <script> var slideIndex = 0; showSlides(); function showSlides() { var i; var slides = document.getElementsByClassName("mySlides"); var dots = document.getElementsByClassName("dot"); for (i = 0; i < slides.length; i++) { slides.style.display = "none"; } slideIndex++; if (slideIndex> slides.length) {slideIndex = 1} for (i = 0; i < dots.length; i++) { dots.className = dots.className.replace(" active", ""); } slides[slideIndex-1].style.display = "block"; dots[slideIndex-1].className += " active"; setTimeout(showSlides, 3000); // Change image every 3 seconds } </script> etc. etc....... COMMENTS: 1) I know that my CSS is clumsy and I should use id = "..." linked to a CSS file to make it cleaner and not be passing the same CSS code to the browser. Will sort it. 2) The mt_rand() function doesn't check that it hasn't supplied that number before and perhaps I should add a routine that looks at images that have been displayed and to inhibit the repeat(s) but it would make the code a bit clunky, I think. Something like: - Create an array In the 'for' loop: Second loop to: - Pass through array to see if $random_keys == $myarray() - If 'yes' then delete $random_keys - If 'No' then add $random_keys to array Return to loop...... In reality, if there are more than a few images, it doesn't really notice. I hope this has been of help. Regards Max
  14. That's a great question, Larry. Actually, every other website that I have looked at just terminates the text irrespective of where there is a space. e.g. Lovely property, not overpriced at all, new ro..........more... I have a bad habit of over-thinking these things. All sorted now.
  15. Thanks, Larry - I think I have my head round it now - that one apostrophe entered through a textarea caused me a lot of chaos. Keep up the great work.
×
×
  • Create New...