PHP - How To Implement The Awesome Search-as-you-type (sayt) In Php
Hi there.
I am working on a PHP web form and trying to implement search functionality. It is called Search-as-you-Type. For example, when we do a search in facebook, we get all the pictures and names of the people. in a drop-down like style. I believe this is implemented using some AJAX. Please see the screenshot I've attached. Could any one please share the code or give me some advice on how I can accomplish this. Thank you! All comments and feedbacks are always welcomed Similar TutorialsHi Friends..... I want to implement search indexing (like joomla) in my website. Earlier I develop search from database by "select" statement. But for whole website, I don't have any idea to do it............ Plzzzzzzz Help ??????/// I'll highly oblized to you............. I'm converting a search feature that currently uses two successive dropdown fields to do the search. The search is initiated when the user selects the option from the dropdown. The resultant (it's always 1 record) is then displayed in detail with a + sign next to it so that the user can add the record he just searched for. I've replaced it with a single dropdown and type-ahead field that uses javascript. The type ahead replaces the second drop down. I didn't want users have to select amongst hundreds of records in a drop down, by forcing them to start typing the second drop down, I can narrow the results to the exact item the user is looking for. My problem is that I'm not sure how to get the type ahead result to initiate the search on the user select. I initiate it like this in the old version... <table> <tr> <td width="130px" valign="top"><form name="nav"><select name="platform" id="platform" onChange="document.location.href=document.nav.platform.options[document.nav.platform.selectedIndex].value"> <option>Platform</option> <? $result = mysql_query("SELECT * FROM Platform"); while($row = mysql_fetch_array($result)) { ?> <option value="?ptfm_ctrl=1&ptfm_id=<?=$row['id_platform']?>" <? if ($_GET['ptfm_id']==$row['id_platform']) { ?>selected="selected"<? } ?>><?=$row['platform']?></option> <? } ?> </select></form></td> <? if (isset($_GET["ptfm_ctrl"])) { ?> <tr> </table> The new solution generates the type ahead result like this... <div> <form> <div> Start typing the name of the product, select the correct title when it appears: <br /> <input type="text" size="30" value="" id="inputString" onkeyup="lookup(this.value);" onblur="fill();" /> </div> <div class="suggestionsBox" id="suggestions" style="display: none;"> <img src="upArrow.png" style="position: relative; top: -12px; left: 30px;" alt="upArrow" /> <div class="suggestionList" id="autoSuggestionsList"> </div> </div> </form> </div> How can I initiate the search using the second method? This topic has been moved to PHPFreaks.com Questions, Comments, & Suggestions. http://www.phpfreaks.com/forums/index.php?topic=351181.0 As a freelancer working alone, I've got to wear all the hats, doing all the front end and back end design and development. So perhaps I'm never really specializing in any one thing, and I tend to miss some good stuff, like MySQL GROUP BY. Doing counts of things using GROUP BY is very handy. I saw somebody doing that in a thread, and adapted it to two things that I was working on in the last week. Sweet!
What other fun MySQL stuff am I missing out on?
finder.com.au is making waves in the comparison space, and we are expanding our Design & Technology team massively this year. We are looking for several full-stack Senior PHP Developers who will be responsible for building a wide variety of web-based applications (using PHP and MySQL) in addition to maintaining existing PHP code, optimizing website and database performance and developing custom PHP solutions. This is a great opportunity for web people at heart to join a growing team delivering awesome products that get used by hundreds of thousands of users. As a developer at finder.com.au you will have the freedom, autonomy, and responsiblity to improve the code, tools, and architecture without having to cut through red tape.
Why finder.com.au?
We've just been named one of the top service companies in the Asia Pacific for 2014, taking silver in the Stevie Awards for Australian Service Company of the year.
We’ve also been dubbed one of Anthill’s 50 coolest companies in Australia for 2013 thanks to our amazing team, wonderful users and cool company culture. As a development team, we move quickly, releasing code several times per day. You need to be willing to move fast, rely on automation, make decisions on less than perfect information, trust your teammates, and constantly strive to improve.
A new Head of Design and Technology, with experience at two of local startup scene’s biggest success stories, recently joined us to lead the team on a mission to speed up the entire company to become the Australian brand for comparison. The team runs hackdays every other month that give all developers free time to show off their creativity and innovation. You will have choice of OS, laptop or desktop, IDE and toolset, and up to 3 monitors. What’s more, you will experience an ultra modern office located in the heart of the Sydney CBD, catered lunches and breakfast supplied every day and all the snacks and drinks you want!
Who are you?
You live and breathe development and your code has soul. You are a great PHP coder that wants to join a team where you can flex your skills and grow further. You are an expert who understands complex problems and enjoys deploying solutions to business problems. You are keen to get your projects live and solve business problems and improve the development environment and tooling. You also have experience in getting code live multiple times per day.
You may be applying from overseas – We are happy to provide support with sponsored relocation services. We already have a number of people on our team from overseas so you will be joining a community.
Must have experience:
4+ years of PHP development experience for Senior Roles
Experience with phpunit
Knowledge of CI tools (Bamboo, Travis, CircleCI)
Knowledge of CD tools (Beanstalk, Capistrano)
Knowledge of Git
Ability and desire to use and extend Git tools (GitHub, Bitbucket) to enhance workflow
Ability to mentor junior developers
Experience with Wordpress beneficial
Knowledge of Front End technologies beneficial
Knowledge of monitoring tools beneficial
Please send us a resume to iwantin@finder.com.au and optionally provide us with a link to your GitHub or Bitbucket profile and a personal note as to why you would want to work with us at finder.com.au.
hi there, i am fairly new to OOPs in php, i get an error when i declare the argument type (as object) in a function and pass the same type (object). class eBlast { public static function getEmail(object $result) { return $result->email; } } $r = mysql_fetch_object($query); eBlast::getEmail($r); echo gettype($r); // outputs: object error is : Code: [Select] Catchable fatal error: Argument 1 passed to eBlast::getEmail() must be an instance of object, instance of stdClass given, called in C:\wamp\www\integra\client\pl_eblast\admin\send_emails.php on line 145 and defined in C:\wamp\www\integra\client\pl_eblast\app\app.eBlast.php on line 8 if i remove the type declaration in the function it works, but just would like to know why it shows error when pass the same type, also isnt mysql_fetch_object is the instance of stdclass? thanks in advance! hi phpfreaks I have an class that is called "connDatabase" what I want to do with it is either extend it or implement it. But I don't know which one to use. The other issue I have is say class "a" has three vars that the that the construct needs to obstantiate and "connDatabase" needs three of its own. How do I obstantiate? thanks for any help Hi
Could you please tell me how can i implement gmail api to send email to user contact on behalf of that user.
I was going to use Google analytics API to develop my cms dashboard content but i am unsure that it's the best way to go about it. Does anyone have any suggestions? I just posted a topic on here about sorting php array alphabetically, the solution was posted so quick I decided to post this as well and maybe save some of my time. So I have this javascript Quote <html> <head><title>Darkapec Movie Player</title> <script type="text/javascript" src="ss1.js"> </script> </head> <body> <h1>Darkapec Movie Player</h1> <b>Video location :</b> <input type="text" id="id4"/> <input type="button" onclick='ld()' value="Load" /><br/> <div id="id1"></div> <div id="nowt"></div> <script type="text/javascript"> function ld(){ document.write("<html><!DOCTYPE HTML PUBLIC \"-\/\/W3C\/\/DTD HTML 4.01 Transitional\/\/EN\"http\:\/\/www.w3.org\/TR\/html4\/loose.dtd><html xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\" xml:lang=\"en\" lang=\"en\"><head><title>Darkapec Movie Player</title><script type=\"text\/javascript\" src=\"ss1.js\"><\/script><script type=\"text\/javascript\" src=\"fun1.js\"><\/script><\/head><body><h1>Darkapec Movie Player<\/h1><br/><embed type=\"application/x-vlc-plugin\" name=\"video1\" id=\"vlc\" autoplay=\"yes\" loop=\"no\" width=\"640\" height=\"480\" target=\""+document.getElementById("id4").value+"\"/><div id=\"nowt\"></div><div id=\"id1\"></div><div id=\"id2\"></div><script type=\"text\/javascript\" src=\"fun1.js\"><\/script><br/><input type=\"button\" onclick='pl()' value=\"Play\" /><input type=\"button\" onclick=\'ps()\' value=\"Pause\" /><input type=\"button\" onclick=\'st()\' value=\"Stop\" /><input type=\"button\" onclick=\'vlc.audio.toggleMute()\' value=\"Mute\" /><br/><b>width :</b><input type=\"text\" id=\"i1\"/><br/><b>height :</b><input type=\"text\" id=\"i2\"/><br/><input type=\"button\" onclick=\'aspectRatio()\' value=\"Adjust Screen\" />"); } </script> <br/> </body> </html> I have put 2 enclosing the code where I would like to implement the following PHP script Quote <?php $dir="/backup/Movies"; $files = array(); if ($handle = opendir($dir)) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != ".." && $file != "index.php" && $file != "New Movies" && $file != "Icons" && $file != "Tv Shows") { $files[] = $file; } } closedir($handle); } sort($files) ?> <form action="listen.php" method="post" name="table"> <select name="Movie"> <p> <?php $tmp = array(); foreach ($files as $file) { $tmp[] = "<option value='$file'>$file</option>"; } echo implode("\n",$tmp) . "\n"; ?> </p> </select> </form> Thanks again for the help Jake I have a website that I did for my uncle and now, the requirements are going beyond my html knowledge and into the realm of server scripting. My issue is that I need to loop through all the images in a given folder and subfolders and preload them into the html so that the user can view them within a slide show. There are currently 6 subfolders with over 20 pics in each and there are more pics to come and different folders to add. I have a media page with the first picture within each category (subfolder) displayed as an eye catcher to the category. once the user clicks on the image, the slide show will start in a popup. The problem is that with js, I have to list out every image since it cannot look through a directory listing. I would like to simply call a server side script that will create an array of the images and preload them so that when the slide show is ran, the appropriate images will show. I am found numerous scripts for preloading images, written in php, but I am unsure how to implement them and keep a html extension for my pages. As the site is written entirely in html and javascript, I would like to keep the html extentions if possible. As this is my first site, I am sure that server side scripting will become a bigger role, but baby steps are what I need right now. In addition, if anyone has a good site for learning the server scripting world, I would greatly appreciate the reference. Hi All,
How could i implemnent tab strip (jquery ui tab) in php.
Any help in this regard will be appreciated
Thanks
Ahsan
----------------------------------------------------------this code---------------------------------------------------------------------- <?php if($login_incorrect){ if(isset($_COOKIE['login'])){ if($_COOKIE['login'] < 3){ $attempts = $_COOKIE['login'] + 1; setcookie('login', $attempts, time()+60*10); //set the cookie for 10 minutes with the number of attempts stored } else{ echo 'You are banned for 10 minutes. Try again later'; } } else{ setcookie('login', 1, time()+60*10); //set the cookie for 10 minutes with the initial value of 1 } } ?> ----------------------------------------------------in here---------------------------------------------------------------------------------- include('dbc.php'); if(isset($_POST['login'])) { $username=$_POST['username']; $password=$_POST['password']; if(empty($username) && empty($password)) { echo"<script>alert('please enter username and password')</script>"; } if(empty($username) || empty($password)) { echo"<script>alert('please enter username and password')</script>"; } $pass= hash('sha512', $password); $set="Lecturer"; $set2='Admin'; $sel="select * from $tb1 where username='$username' and password='$pass'"; $result=mysqli_query($con,$sel); $row=mysqli_fetch_array($result); if($row['username']== $username && $row['password']== $pass && $row['usertype']==$set) { $_SESSION["username"] = $_POST["username"]; $_SESSION['last_login_timestamp'] = time(); $_SESSION['username'] = $username; header('location:userhome.php'); } elseif ($row['username']== $username && $row['password']== $pass && $row['usertype']==$set2) { $_SESSION["username"] = $_POST["username"]; $_SESSION['last_login_timestamp'] = time(); $_SESSION['username'] = $username; header('location:adminhome.php'); }} else {echo"<script>alert('not registered/approved')</script>";} ?>
I'm working on a Wordpress theme, and I'm assigning my own image to the navi list. So far assigning the image to the corresponding works if I type in the path manually, but the only problem I'm experiencing is assigning the correct path to the image with a Wordpress specific function, here's the code: <div id='nav' class='link_var_4'> <div id='blog_navi'><?php wp_nav_menu(array( "link_before" => "<li><img src='" . bloginfo ('template_directory') . "/images/arrow.png' /></li>", "theme_location" => "primary-menu")); ?> </div> </div> How can I make the bloginfo function work inside the array in this above example? I've tried different variations and methods, none of them gave the expected results. For those who don't know Wordpress, normally in Wordpress you'd do it like this: <a href="<?php bloginfo('url'); ?>" title="<?php bloginfo('description'); ?>"><img src="<?php bloginfo ('template_directory'); ?>/images/logo.png" alt="<?php bloginfo('description'); ?>" /></a> I have a while loop that fetches data from the database and prints it out organized in a table. Now I want to implement a voting functionality, the problem I'm encountering is, once I've printed out a list of tables one table after other with the while loop I need to figure out a way to tell the query TO WHICH of those tables to ADD or SUBTRACT the vote. I thought of implement a hidden id field into the while loop of contributions, the id field would be fetched from the auto_increment field in the contribution table in the MySQL database. Since the id field is unique there can be no misunderstandings to which table to add the vote. My question how can I do exactly that? How can I add a hidden id field to the while loop with the table WHICH I then can pass along to the voting script. Here's the while loop: while ($row = mysqli_fetch_array($data)) { echo "<table padding='0' margin='0' class='knuffixTable'>"; echo "<tr><td width='65px' height='64px' class='avatar_bg' rowspan='2' colpan='2'><img src='$avatar_path' alt='avatar' /></td><td class='knuffix_username'><strong>" . $user_name; echo "</strong><br />" . $row['category'] . " | " . date('M d, Y', strtotime($row['contributed_date'])) . "</td></tr><tr><td>"; echo "<form action='' method='post'> <input type='submit' name='plusVote' value='Y' /> <input type='submit' name='minusVote' value='N' /> </form></td><td class='votes'>Y[ - ] | N[ - ]</td></tr>"; echo "<tr><td class='knuffix_name' colspan='3'><strong>" . htmlentities($row['name']) . "</strong><br /></td></tr>"; echo "<tr><td colspan='2' class='knuffix_contribution'><pre>" . $row['contribution'] . "</pre><br /></td></tr>"; echo "</table>"; } If I simply add $row['con_id'] it's obviously going to be echo'd out, what is the right practice to have it hidden? Basically I am submitting and retrieving data from a 3rd party's API. But every time I submit a form, it gives me this error. Access to XMLHttpRequest at 'https://3rdpartywebsite.com/api' from origin 'https://mywebsite.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
So I have been researching and there seems to be so many different answers. I have tried adding this code to the page but still get an error. <?php // ADD THIS CODE ON THE VERY TOP OF THE PAGE I AM SUBMITTING THE FORM. header("Access-Control-Allow-Origin: *"); header("Access-Control-Allow-Credentials: true"); header("Access-Control-Max-Age: 1000"); header("Access-Control-Allow-Headers: X-Requested-With, Content-Type, Origin, Cache-Control, Pragma, Authorization, Accept, Accept-Encoding"); header("Access-Control-Allow-Methods: PUT, POST, GET, OPTIONS, DELETE"); ?>
I have also tried to add this to .htaccess file and still get the same error. Header add Access-Control-Allow-Headers "origin, x-requested-with, content-type" Header add Access-Control-Allow-Methods "PUT, GET, POST, DELETE, OPTIONS"
I was wondering what am I doing wrong? What's the correct way of implementing CORS to my site? Hi again people! I found this code that codes for a countdown timer. My problem is, how do I implement it? I've found similar codes that leave me dazzled as I try to get them to work. The URL from which I found this is: http://scripts.franciscocharrua.com/server-side-countdown-clock.php The code is: Code: [Select] function countdown_clock(year, month, day, hour, minute, format) { //I chose a div as the container for the timer, but //it can be an input tag inside a form, or anything //who's displayed content can be changed through //client-side scripting. html_code = '<div id="countdown"></div>'; document.write(html_code); Today = new Date(); Todays_Year = Today.getFullYear() - 2000; Todays_Month = Today.getMonth(); <? $date = getDate(); $second = $date["seconds"]; $minute = $date["minutes"]; $hour = $date["hours"]; $day = $date["mday"]; $month = $date["mon"]; $month_name = $date["month"]; $year = $date["year"]; ?> //Computes the time difference between the client computer and the server. Server_Date = (new Date(<?= $year - 2000 ?>, <?= $month ?>, <?= $day ?>, <?= $hour ?>, <?= $minute ?>, <?= $second ?>)).getTime(); Todays_Date = (new Date(Todays_Year, Todays_Month, Today.getDate(), Today.getHours(), Today.getMinutes(), Today.getSeconds())).getTime(); countdown(year, month, day, hour, minute, (Todays_Date - Server_Date), format); } function countdown(year, month, day, hour, minute, time_difference, format) { Today = new Date(); Todays_Year = Today.getFullYear() - 2000; Todays_Month = Today.getMonth(); //Convert today's date and the target date into miliseconds. Todays_Date = (new Date(Todays_Year, Todays_Month, Today.getDate(), Today.getHours(), Today.getMinutes(), Today.getSeconds())).getTime(); Target_Date = (new Date(year, month, day, hour, minute, 00)).getTime(); //Find their difference, and convert that into seconds. //Taking into account the time differential between the client computer and the server. Time_Left = Math.round((Target_Date - Todays_Date + time_difference) / 1000); if(Time_Left < 0) Time_Left = 0; switch(format) { case 0: //The simplest way to display the time left. document.all.countdown.innerHTML = Time_Left + ' seconds'; break; case 1: //More datailed. days = Math.floor(Time_Left / (60 * 60 * 24)); Time_Left %= (60 * 60 * 24); hours = Math.floor(Time_Left / (60 * 60)); Time_Left %= (60 * 60); minutes = Math.floor(Time_Left / 60); Time_Left %= 60; seconds = Time_Left; dps = 's'; hps = 's'; mps = 's'; sps = 's'; //ps is short for plural suffix. if(days == 1) dps =''; if(hours == 1) hps =''; if(minutes == 1) mps =''; if(seconds == 1) sps =''; document.all.countdown.innerHTML = days + ' day' + dps + ' '; document.all.countdown.innerHTML += hours + ' hour' + hps + ' '; document.all.countdown.innerHTML += minutes + ' minute' + mps + ' and '; document.all.countdown.innerHTML += seconds + ' second' + sps; break; default: document.all.countdown.innerHTML = Time_Left + ' seconds'; } //Recursive call, keeps the clock ticking. setTimeout('countdown(' + year + ',' + month + ',' + day + ',' + hour + ',' + minute + ',' + time_difference + ', ' + format + ');', 1000); } I've tried saving the file as a php file and html file, but to no avail... |