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
https://forums.phpfreaks.com/topic/172613-solved-selecting-db-items/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.