russianbear Posted August 25, 2009 Share Posted August 25, 2009 Hoping somebody can help me out. What I'm trying to do is query my db and pull from it a title and ID of a posting. The web app I'm building is a mini version of the craigslist.com Basically the user enters a bunch of information about a product they are trying to sell including pictures, etc... The LOC you see below will query the db based on user input and return a result set of ALREADY posted listings...so basically I'm trying to print out the titles of the postings and make those hyperlinks to the actual posts. The problem I'm running into isn't in the MySQL query - I already tested that and it works, but in my PHP logic in capturing the data after the query is executed! Okay - here is the rub. This code works, but only for a specific set of input. The input is captured on the prior page and it comes from 2 pull down menus that provides the SubCategoryID (i.e. option 0 = books, option 1 = art, option 2 = etc...) and the LocationID (option 0 = Cupertino, CA ; option 1 = Moscow, Russia, etc...) The results are ONLY displayed if the user chooses: LocationID = 0 and SubCategory = 0 (another words the code below only works if the user selected Cupertino and Books on the prior page). Is the problem obvious or do you need more information to further diagnose my stupidity? Thanks in advance! PS - I'll send a darn good bottle of Pinot to whoever can help me solve this issue! And if you don't drink, I'll send ya a couple of 2 liters of Mountain Dew. And if you don't drink caffeine either, well then you'll just have to settle with my thanks and BIG UPS!!!! if($stmt = $conn->prepare("SELECT Post_ID, Title FROM POSTS as p, LOCATION as l, SUBCATEGORY as s, REGION as r, CATEGORY as c WHERE((p.Location_ID=?) AND (p.SubCategory_ID=?) AND (r.Region_ID=?) AND (p.SubCategory_ID = s.SubCategory_ID) AND (p.Location_ID = l.Location_ID) AND (s.Category_ID = c.Category_ID) AND (l.Region_ID = r.Region_ID))")) { // Bind your variable to replace the ? $stmt->bind_param('iii', $field1, $field2, $field3); // Set your variables $field1 = $Sub_Category_ID; $field2 = $Location_ID; $field3 = $Region_ID; $row = array(); //Bind the result $stmt->bind_result($row['post_id'], $row['title']); //Execute the query $stmt->execute(); //Okay, got the result, how output them to the screen // Output here looks like USA->Cupertino->For Sale->Automobiles echo "<h3>$Region_Name -> $inputArray[location] -> $Category_Name -> $inputArray[sub_category]</h3>"; //here is where I'm getting the ID and title and storing them in a local 2-D array while($stmt->fetch()) { foreach($row as $key => $value) { $tmp[key] = $value; }//end foreach $this->PostArray[$count++] = $tmp; }//end while // PROBLEM IS - WHEN I attempt to print the array recursively, I get NOTHING!!!!! // Can you see anything in my logic that is BOGUS, for lack of better words. print_r($PostArray); }//end if ?> Quote Link to comment https://forums.phpfreaks.com/topic/171728-mysqli-binding-results-problem/ Share on other sites More sharing options...
fenway Posted August 28, 2009 Share Posted August 28, 2009 Welll, you're doing an inner join, so you'd need all 3 selections made for the code to return anything. Quote Link to comment https://forums.phpfreaks.com/topic/171728-mysqli-binding-results-problem/#findComment-908338 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.