/    Sign up×
Community /Pin to ProfileBookmark

Not returning expected results – Looping issues?

Hi all, I’m have some issues with [URL=”http://ben.broxie.co.uk/benwoolner/littleshopper”]my website[/URL]. At the moment if you use the links on the side an go for example Books > Childrens Books you see a selection of items which is all well and good.

The problem I’m finding is that if I then click on for example Book Of Paper Areoplanes my breadcrum trail says that we’ve come from the Sci-fi selection.

I think its because of my loop as that is the last result from my [COLOR=”Blue”]store_subcategories [/COLOR]table.

[QUOTE]

subcat_id cat_id subcat_title

1 1 Mens
2 1 Ladies
3 1 Boys
4 1 Girls
5 2 Compilations
6 2 Pop
7 2 Rock
8 2 Dance
9 3 Books For Beginners
10 3 Childrens Books
11 3 Romance
12 4 Childrens Games
13 4 Driving
14 5 Childrens Movies
15 5 Sci-fi

[/QUOTE]

This is a slection from my [COLOR=”Blue”]store_items[/COLOR] table just so you can see how I’ve set that up.

[QUOTE]

id subcat_id item_title item_price item_desc
1 1 Mens Vest Top 4.00 A sleeveless vest top, ideal for those hot summer …

2 1 Mens Short Sleeved T-shirt 5.00 A short sleeved, round neck T-shirt.

3 1 Mens Long Sleeved T-shirt 7.00 A long sleeved, round neck T-shirt.

4 1 Mens Hoodie 10.00 Made of thicker material to keep the heat in the h…
5 1 Mens Reversable Rugby Shirt 20.00 A reversable rugby shirt that shows a white stripe…

6 2 Ladies Vest Top 4.00 Vest Top
7 2 Ladies Short Sleeved T-shirt 5.00 Ladies Short Sleeved T-shirt

8 2 Ladies Long Sleeved T-shirt 7.00 Ladies Long Sleeved T-shirt
9 2 Ladies Hoodie 10.00 Ladies Hoodie
10 2 Womans Rugby Shirt 20.00 Womans Rugby Shirt

[/QUOTE]

This is all the php from this file because I’m at a total loss at the moment. I’m new to both PHP and SQL anyway so its all one big learning curve.

[code=php]
<?php
session_start();

//connect to server and select database; you may need it
$mysqli = mysqli_connect(“localhost”, “***”, “***”, “littleshopper”);

// sets up queries
$get_data_qry = “SELECT item_title, item_price, item_desc, item_image FROM store_items WHERE id='”.$_GET[“item_id”].”‘”;
$get_trail_qry = “SELECT subcat_id, subcat_title FROM store_subcategories”;

// sets up query calls
$get_data_res = mysqli_query($mysqli, $get_data_qry) or die(mysqli_error($mysqli));
$get_trail_res = mysqli_query($mysqli, $get_trail_qry) or die(mysqli_error($mysqli));

//get and show 1st level navigation
if (mysqli_num_rows($get_data_res) < 1)
{
$display_content = “<h3>We’re Sorry!</h3><p>We’ve searched out database and couldn’t find anything under that category</p>n”;
}
else
{
while ($trail = mysqli_fetch_array($get_trail_res))
{
$subcat_id = $trail[‘subcat_id’];
$subcat_title = $trail[‘subcat_title’];
}

while ($data = mysqli_fetch_array($get_data_res))
{
$item_title = ucwords(stripslashes($data[‘item_title’]));
$item_price = $data[‘item_price’];
$item_image = $data[‘item_image’];
$item_desc = $data[‘item_desc’];

$display_title =”<h3>”.$item_title.”</h3><br />n”;
$display_price =”<h3>&#163;”.$item_price.”</h3><br />n”;
$display_image =”<br /><img src=””.$item_image.”” /><br />n”;
$display_desc =”<br />” .$item_desc. “<br />n”;
}

//make breadcrumb trail
$display_trail = “<strong><em>You are viewing:</em>
<a href=”/benwoolner/littleshopper/showitems.php?subcat_id=”.$subcat_id.””> “.$subcat_title.”</a> &gt; “.$item_title.”</strong>
<form method=”post” action=”addtocart.php”>”;

//free result
mysqli_free_result($get_item_res);

//get colours
$get_colours_sql = “SELECT item_colour FROM store_item_colour WHERE item_id = ‘”.$_GET[“item_id”].”‘ ORDER BY item_colour”;
$get_colours_res = mysqli_query($mysqli, $get_colours_sql) or die(mysqli_error($mysqli));

if (mysqli_num_rows($get_colours_res) > 0) {
$display_form = “<p><strong>Available colours:</strong><br/>
<select name=”sel_item_colour”>”;

while ($colours = mysqli_fetch_array($get_colours_res)) {
$item_colour = $colours[‘item_colour’];
$display_form .= “<option value=””.$item_colour.””>”.$item_colour.”</option>”;
}
$display_form .= “</select>”;
}

//free result
mysqli_free_result($get_colours_res);

//get sizes
$get_sizes_sql = “SELECT item_size FROM store_item_size WHERE item_id = “.$_GET[“item_id”].” ORDER BY item_size”;
$get_sizes_res = mysqli_query($mysqli, $get_sizes_sql) or die(mysqli_error($mysqli));

if (mysqli_num_rows($get_sizes_res) > 0) {
$display_form .= “<p><strong>Available Sizes:</strong><br/>
<select name=”sel_item_size”>”;

while ($sizes = mysqli_fetch_array($get_sizes_res)) {
$item_size = $sizes[‘item_size’];
$display_form .= “<option value=””.$item_size.””>”.$item_size.”</option>”;
}
}

$display_form .= “</select>”;

//free result
mysqli_free_result($get_sizes_res);

$display_form .= ”
<p><strong>Select Quantity:</strong>
<select name=”sel_item_qty”>”;

for($i=1; $i<11; $i++) {
$display_form .= “<option value=””.$i.””>”.$i.”</option>”;
}

$display_form .= ”
</select>
<input type=”hidden” name=”sel_item_id” value=””.$_GET[“item_id”].””/>
<p><input type=”submit” name=”submit” value=”Add to Cart”/></p>
</form>”;
}
?>
[/code]

If you can help me stop my webpage giving out wrong information I’d be greatfull, and if you do help can you please comment the code or explain where I’ve gone wrong and what you’ve done to fix it so I can learn from my mistakes

Thanks
Ben

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @lil_bugga spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...