Jump to content
Larry Ullman's Book Forums
skim5_1999

Dynamic Catalogue: Myisqli Fetch?

Recommended Posts

Hello,

In Example 2 home page, when you click ont he red mug, it takes you to a sales page with the red mug on top PLUS all these other products. I am in the process of creating my own Dynamic catalogue and would like to learn if there's a way to click on that red mug on the home page and then land on a sales page that ONLY has details of the red mug, and no other products. More specifically, the current codes on Ex 2 is as follow:

 

1) The red mug on the home page has the following href:

<a href="/shop/sales/#' . $row['sku'] .'>

 

2) The above ultimately goes to a list_sales.html page with the following codes:

 

"while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {

 

echo '<h3 id="' . $row['sku'] . '">' . $row['category'] . '::' . $row['name'] .'</h3>

<div class="img-box">

<p><img alt="' . $row['name'] . '" src="/products/' . $row['image'] . '" />' . $row['description'] . '<br />' .

get_price('goodies', $row['price'], $row['sale_price']) . '

<strong>Availability:</strong> ' . get_stock_status($row['stock']) . '</p>

<p><a href="/cart.php?sku=' . $row['sku'] . '&action=add" class="button">Add to Cart</a></p></div>';"

 

 

3) Is there a way to still link the home page to the list_sales.html but so that only one "SKU" or product is shown at a time? I already tried taking out the "while" loop but then it just shows the very first row even if other products are selected on the home page. I basically want so that a pix of the product the consumer selects from the home page takes them to a detailed page about that one product in a dynamic fashion...

 

THANK YOU!

sjk

Share this post


Link to post
Share on other sites

I would create a "product" page that lists a single product. That page should be passed the SKU. Then you change the link so it goes to the product page.

Share this post


Link to post
Share on other sites

Hello - Thanks for your reply. I'm quite a newbie, I actually have trouble figuring out how to "pass the SKU" over to a specific page. Is there a mysqli function that passes it over so it "catches" and recognizes just one SKU? the mysqli_fetch either gives me all the SKU or just the first one...Thanks so much! This book has really helped me get my business started

Sjk

Share this post


Link to post
Share on other sites

Hi,

 

The book has some quite complex code in it, so if you are new to PHP you may struggle to adapt your code to meet your needs. I have read Larry's "PHP and MYSQL" which is a good primer for the effortless e-commerce book. There is also "PHP for the Web" which may be a good option for you too, however I haven't read it.

 

In answer to your question: To a pass over the SKU there are a couple of ways. I suspect that the $_GET['var'] will suffice.

 

To use this you need to have a set up similar to this:

 

page.php

<?php
echo '<a href="product.php?sku=15">See Product 15</a>';
?>

 

then on product.php

<?php
if(isset($_GET['sku'])) {
$sku = $_GET['sku'];
} else {
// default page if no sku or invalid
}
?>

 

From there you can use the $sku variable you created in your mysqli queries

 

Hope that helps ;)

  • Upvote 1

Share this post


Link to post
Share on other sites

Thank you so much, Jonathon, again! It took me a long time, but thanks to your initial guidance, i finally figured out what I have to do to make it more dynamic and not have every single item shown with mysqli_fetchy_array. I'm sure there's some rookie mistake I'm making here, but here's what I've done for others who are looking to do the same thing

 

On page.php, write

"<?php echo '<a href="product.php?sku='.row['sku'].'">See Product 15</a>'; ?>"

 

 

And then on product.php, write (after including the config and requiring MYSQL),

"if (isset($_GET['SKU'])) {

$sql="SELECT * FROM table WHERE table_id=".$_GET['SKU'];

$result=mysqli_query ($dbc, $sql);

$row=mysqli_fetch_array($result);

echo '

<p> ' .$row['put a column name in the table here'] . ' </p>

';

}

 

yay! thanks!

sjk

Share this post


Link to post
Share on other sites

Yeah essentially that's it.

You can always validate the

$_GET['sku']

checking it's an integer maybe?

so

if(isset($_GET['sku']) && is_numeric($_GET['sku'])) {
// Do something
}

 

also do you need to SELECT everything from the database?

You can just:

 SELECT column, column2 FROM table WHERE sku=$_GET['sku']

 

But yeah well done :)

  • Upvote 1

Share this post


Link to post
Share on other sites

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.   Paste as plain text instead

  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.

Loading...

×
×
  • Create New...