Jump to content

Recommended Posts

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

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'");

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.

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.

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>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.