Suchy Posted August 31, 2009 Share Posted August 31, 2009 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 More sharing options...
corbin Posted August 31, 2009 Share Posted August 31, 2009 Have you read any AJAX tutorials? Link to comment https://forums.phpfreaks.com/topic/172613-solved-selecting-db-items/#findComment-909910 Share on other sites More sharing options...
Suchy Posted September 2, 2009 Author Share Posted September 2, 2009 Got to work. I just printed the results in filter.php and added a readystate function which places the results into a div. Link to comment https://forums.phpfreaks.com/topic/172613-solved-selecting-db-items/#findComment-911046 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.