Jump to content

[SOLVED] Selecting DB items


Suchy

Recommended Posts

I am having trouble with my code.

What it supposed to do is that you see a list of categories (ex. pencils, pens, erasers....)

and once you select a category the items should be displayed.

 

The items.php calls the filter.php file which contains a filter MySQL  query.

This works fine, except I can't get the items once they are retrieved from the database to show up on the items.php page

 

items.php

<html>
<body>
<script language=JavaScript>


function getHTTPObject()
{
if (window.ActiveXObject) 
	return new ActiveXObject("Microsoft.XMLHTTP");
else if (window.XMLHttpRequest) 
	return new XMLHttpRequest();
else 
{
	alert("Please turn on JavaScript or disable NoScript plugin.");
	return null;
  	}
} 



function filter_cat(select) 
{
var selected_cat_id = select.value;

httpObject = getHTTPObject();
if (httpObject != null) 
{
	httpObject.open("GET", "filter.php?i=" + selected_cat_id , true);
	httpObject.send(null);
}
} 
</script>

......

                   <!-- this displays categories ex. pens, pencils /-->     
                   <form action="<?=$_SERVER['../PHP_SELF']?>" >
                           <select size="5" onchange="filter_cat(this)" /> 
                                           <?php foreach($categories as $i) { ?>
                                                      <option value="<?= $i['id']; ?>" ><? printf ("%.30s", $i['name']); ?></option>
                                                    <?php } ?>
                                             </select>                
                        </form>	
......

<!-- this should display the items from a choosen category, ex. red pencil, blue pencil ...
<?php foreach($items as $i) 
    echo $i['id'] . " - " . $i['name'] . "<br>";
?>

...
</body>
</html>

 

filter.php

<?php
include("DBconnect.php");

$selected_id = mysql_real_escape_string($_GET['i']);   

$filter_results = mysql_query("SELECT * FROM items WHERE id_cat = '$selected_id'") ;	

$items = getRows($filter_results);

?>

 

How can I get this to work ?

Link to comment
Share on other sites

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.