yoursurrogategod Posted June 26, 2012 Share Posted June 26, 2012 Hi. One thing that we have in our organization is a bunch of medical terms (the abbreviation and the long winded explanation). What I'd like to do is put all of them in a MySQL database and then pull them all out, store that data in a hidden field (no, none of this should be kept private, so it's ok if it's like that) and then using a little JavaScript, search over the hidden data and then display it to the user. Now, I can retrieve that stuff from the database, but what I'm having a hard time with is the searching the contents of a hidden field and then displaying it. Thoughts? If this isn't the right place for this post, please feel free to move it elsewhere. Quote Link to comment https://forums.phpfreaks.com/topic/264809-how-would-i-implement-this-version-of-a-dynamic-search/ Share on other sites More sharing options...
Jessica Posted June 26, 2012 Share Posted June 26, 2012 1. This doesn't have anything to do with searching. 2. How do you plan to hover over something that is hidden? Are you trying to say you want to display an abbreviation, and when it's hovered over, display the long version? Quote Link to comment https://forums.phpfreaks.com/topic/264809-how-would-i-implement-this-version-of-a-dynamic-search/#findComment-1357191 Share on other sites More sharing options...
yoursurrogategod Posted June 28, 2012 Author Share Posted June 28, 2012 1. This doesn't have anything to do with searching. 2. How do you plan to hover over something that is hidden? Are you trying to say you want to display an abbreviation, and when it's hovered over, display the long version? No. The data is retrieved from the database and is stored on the page in a hidden field. The user cannot see this info. However, there is a textbox that is displayed -- that -- as you type will display dynamically matching items. Quote Link to comment https://forums.phpfreaks.com/topic/264809-how-would-i-implement-this-version-of-a-dynamic-search/#findComment-1357772 Share on other sites More sharing options...
ManiacDan Posted June 28, 2012 Share Posted June 28, 2012 Don't use a hidden field, use a javascript array. That's what they're for. Always describe the problem. Don't ask how to implement your chosen solution, it's often wrong. Quote Link to comment https://forums.phpfreaks.com/topic/264809-how-would-i-implement-this-version-of-a-dynamic-search/#findComment-1357785 Share on other sites More sharing options...
yoursurrogategod Posted July 20, 2012 Author Share Posted July 20, 2012 1. This doesn't have anything to do with searching. 2. How do you plan to hover over something that is hidden? Are you trying to say you want to display an abbreviation, and when it's hovered over, display the long version? Why would I hover with the mouse over the abbreviation? I'm not sure how you managed to interpret my post this way, I never even used that specific word in my post . Basically it's supposed to be like this (I'm just making up random acronyms for the sake of an example): FBI Federal Bureau of Investigation GPS Global Positioning System ATF Bureau of Alcohol Tobacco and Firearms etc. This example can do the trick, but then I don't want my users to see the password that I'm using to access the database: http://stackoverflow.com/questions/857670/how-to-connect-to-sql-server-database-from-javascript What I'd like to do is dump this info into a JavaScript array using PHP. I'm not very strong when it comes to JavaScript, so this part is what is holding me back. How would I do this? The table would be made up of 2 columns (the acronym and the explanation). Quote Link to comment https://forums.phpfreaks.com/topic/264809-how-would-i-implement-this-version-of-a-dynamic-search/#findComment-1363037 Share on other sites More sharing options...
jcbones Posted July 20, 2012 Share Posted July 20, 2012 You would be better off (if it is a large recordset) to create your abbr links, then get the description via AJAX (which calls back to the server). Quote Link to comment https://forums.phpfreaks.com/topic/264809-how-would-i-implement-this-version-of-a-dynamic-search/#findComment-1363042 Share on other sites More sharing options...
yoursurrogategod Posted July 20, 2012 Author Share Posted July 20, 2012 You would be better off (if it is a large recordset) to create your abbr links, then get the description via AJAX (which calls back to the server). We're talking here about 400 records on a local intranet. I've considered this, but loading it all in one go isn't a really big problem. Quote Link to comment https://forums.phpfreaks.com/topic/264809-how-would-i-implement-this-version-of-a-dynamic-search/#findComment-1363045 Share on other sites More sharing options...
xyph Posted July 20, 2012 Share Posted July 20, 2012 What I'd like to do is dump this info into a JavaScript array using PHP. I'm not very strong when it comes to JavaScript, so this part is what is holding me back. How would I do this? The table would be made up of 2 columns (the acronym and the explanation). How would this hold you back? The syntax is simple, and well documented. I'd use a JS object, rather than a set of arrays. <?php $array = array( 'FBI'=>'Federal Bureau of Investigation', 'GPS'=>'Global Positioning System', 'ATF'=>'Bureau of Alcohol Tobacco and Firearms' ); echo '<script type="text/javascript">var data=new Object;'; foreach( $array as $key => $value ) { echo "data['$key']='$value';"; } echo ' for( var i in data) { document.write(i+"=>"+data[i]+"<br>"); } </script>'; ?> Output FBI=>Federal Bureau of Investigation GPS=>Global Positioning System ATF=>Bureau of Alcohol Tobacco and Firearms Quote Link to comment https://forums.phpfreaks.com/topic/264809-how-would-i-implement-this-version-of-a-dynamic-search/#findComment-1363069 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.