nezbo Posted February 7, 2008 Share Posted February 7, 2008 Hi all I have a database and i want to have a dropdown that i an select an option that filters the select statement e.g. i have a select statement like this $foo = @mysql_query("SELECT * FROM hearAndThere"); this brings back everything. i.e. Name Area jo NW john NE bob NW steve S what i want to do not is select NW from a dropdown that filters out everthing except for NW in the area, and with out refreshing the page. i am going to want to go more ant one filtering. i havent started the page yet but i want to plan it first. Link to comment https://forums.phpfreaks.com/topic/89908-php-and-javascript-database-display/ Share on other sites More sharing options...
The Little Guy Posted February 7, 2008 Share Posted February 7, 2008 $foo = @mysql_query("SELECT * FROM hearAndThere WHERE `Area != 'NW'"); Link to comment https://forums.phpfreaks.com/topic/89908-php-and-javascript-database-display/#findComment-460870 Share on other sites More sharing options...
nezbo Posted February 7, 2008 Author Share Posted February 7, 2008 i know i can do that but i wont to do it on the fly, with out having to refresh the page... so i need to use javascript to filter out the none NW ones. if i change i drop down it doesnt reload the page. $foo = @mysql_query("SELECT * FROM hearAndThere WHERE `Area != 'NW'"); Link to comment https://forums.phpfreaks.com/topic/89908-php-and-javascript-database-display/#findComment-460881 Share on other sites More sharing options...
haku Posted February 7, 2008 Share Posted February 7, 2008 Thats an AJAX issue. This is the wrong section of the forum for AJAX questions. Go back to the main page and scroll down a little further, you will find the AJAX area there. Link to comment https://forums.phpfreaks.com/topic/89908-php-and-javascript-database-display/#findComment-460884 Share on other sites More sharing options...
nezbo Posted February 7, 2008 Author Share Posted February 7, 2008 but i am using it with in PHP, and i need it to work with an mysql select with in php Thats an AJAX issue. This is the wrong section of the forum for AJAX questions. Go back to the main page and scroll down a little further, you will find the AJAX area there. Link to comment https://forums.phpfreaks.com/topic/89908-php-and-javascript-database-display/#findComment-460887 Share on other sites More sharing options...
haku Posted February 7, 2008 Share Posted February 7, 2008 The solution to your problem does not lie in PHP. Its a javascript (AJAX) issue that works with php, but is not php. Link to comment https://forums.phpfreaks.com/topic/89908-php-and-javascript-database-display/#findComment-460892 Share on other sites More sharing options...
Wolphie Posted February 7, 2008 Share Posted February 7, 2008 A recent code snippet. I think this may be the solution to your problem and if it isn't it's in the correct direction. http://www.phpfreaks.com/forums/index.php?topic=155984.msg808536#new Link to comment https://forums.phpfreaks.com/topic/89908-php-and-javascript-database-display/#findComment-460901 Share on other sites More sharing options...
aschk Posted February 7, 2008 Share Posted February 7, 2008 Ok, so what else are you filtering by? Once you have filtered by Area (e.g. NW) how else are you going to filter your results? From what I can see the little guy has given pretty much what i'd give. Let us know what other filters you are expecting and i'm sure we can help. Link to comment https://forums.phpfreaks.com/topic/89908-php-and-javascript-database-display/#findComment-460906 Share on other sites More sharing options...
The Little Guy Posted February 7, 2008 Share Posted February 7, 2008 its not AJAX Your PHP: <?php $foo = @mysql_query("SELECT * FROM hearAndThere"); while($row = mysql_fetch_array($foo)){ echo '<p><span title="'.$row['area'].'">'.$row['Name'].'</span></p>'; } ?> Example PHP Output: <select> <option onclick="showNames('NW');" value="NW">NW</option> <option onclick="showNames('NE');" value="NW">NE</option> <option onclick="showNames('S');" value="NW">S</option> </select> <p><span title="NW">Ryan</span></p> <p><span title="S">Mike</span></p> <p><span title="NE">Jaimee</span></p> <p><span title="SW">Nancy</span></p> <p><span title="NW">Benny</span></p> Your JavaScript: <script type="text/javascript"> function showNames(loca){ tags = document.getElementsByTagName("span"); for(i=0;i<tags.length;i++){ tag = tags[i]; if(tag.getAttribute("title") == loca) tag.setAttribute("style", "display:block"); else tag.setAttribute("style", "display:none"); } } </script> Link to comment https://forums.phpfreaks.com/topic/89908-php-and-javascript-database-display/#findComment-460929 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.