Log in

View Full Version : Making temporary pages for products



Colonel_Popcorn
04-02-2009, 01:50 AM
Hey, I have made a search function to search a database and return the results. Now I need to post a link under the results to link to a page that contains the results. Is there a way to create a temporary php page that will display the selected product. I know I could create individual pages for the items, but with over a couple thousand items, that would take too long.

CrazyChop
04-02-2009, 03:27 AM
What you are looking for is called caching. but it is a massive effort and may require some server-side customisation plus it consumes a lot of resources (one user = 1 unique search = 1 file to store on server)

A better approach to solve your problem would be to return a URL to the search page with the search queries embedded:

search.php?search=games

If you want to, you can embed the productids into the url, though there is a limit



search.php?productid[]=1&productid[]=2&productid[]=3


This will result in an array called productid[] in $_GET, which you access via



$productid = $_GET['productid][0]; // will give you 1



The third one is to cache all the productid inside a temporary DB, with all the id into one text column, separated by commas. Use the explode to form an array of product-ids and then re-fetch the information. Add in a timestamp so you can make those pages expire.

Hope these suggestions help!

Colonel_Popcorn
04-02-2009, 05:00 AM
Well I guess the word temporary is the wrong term to use the way I described it, I guess it would be a permanent page that would only be up while the product was available. Sort of how newegg does theirs, but they use aspx instead of php. The code I use to display the results is:


else
{
while($fn<$nt)
{
$rw=0;
while($rw<10000)
{

$col=2;
$rr=$rw-1;
if ($output[$fn][$rw] == "")
{

}
else
{
$rcheck = 0;
while($rr>=-1)
{

if ($output[$fn][$rw][id] == $output[$fn][$rr][id])
{
$rcheck++;
}
else
{
}
$rr=$rr-1;
}
if ($rcheck == 0)
{
if ($output[$fn][$rw][type] == "Service")
{
?>
<div id="unit" style="height:160px;">
<div class="darkgraybig style19" style="margin-bottom:10px; padding-left:20px; margin-top:30px;"> <?php echo $output[$fn][$rw][name]; ?>
</div>
<div class="darkgray" style="margin-bottom:10px; padding-left:20px;">
<b class="lightblue"><?php echo $output[$fn][$rw][catchphrase]; ?></b>
<?php echo $output[$fn][$rw][description]; ?>
</div>
<div>
<img src="images/ch_view.jpg" style="margin-right:4px;" alt="">
<strong><a href="<?php echo $output[$fn][$rw][location] ?>" class="smallred">view details</a></strong>
</div>
<div>
</div>
</div>
<?php
}
else
{
?>

<div id="unit" style="height:160px;">
<div class="darkgraybig style19" style="margin-bottom:10px; padding-left:20px; margin-top:30px;">
<span class="lightblue style19">
<b><?php echo $output[$fn][$rw][2];?></b>
</span>
<b>&nbsp;<?php echo $output[$fn][$rw][3];?></b>
</div>
<div class="darkgray" style="margin-bottom:10px; padding-left:0px;">
<img src="<?php echo $output[$fn][$rw][image];?>" style="margin-right:14px; float:left;" alt="">
<?php echo $output[$fn][$rw][description];?>
<br />
<br />
</div>
<div style="float:left; margin-right:30px; margin-top:0px;">
<a href="#"><img src="images/kn_large.jpg" border="0" alt="" /></a>
</div>
<div style="float:left; margin-top:0px;">
<a href="#" class="largered">$<?php echo $output[$fn][$rw][cost];?></a>
</div>
</div>
<?php
}
}
else
{
}

}

$rw++;
}
$fn++;
}
}


So in the <a href"#"> part I would place the link to the generated page and when they clicked on the link, it would take them to that page just like a normal link. Does that clarify the problem a bit?

CrazyChop
04-02-2009, 02:17 PM
Use SQL to do a count for the number of products left in the inventory, or to check for its availability. If it is available, write the html to display it. If not, then don't.

Edit:

Okay, misread your question. What you need to do is to have a generic product.php page, which takes in a productid, maybe through $_POST or $_GET. From there, you read in the data of the product and display it as you deem fit. So each search result will have links like product.php?productid=1234 etc. etc. etc.

Colonel_Popcorn
04-04-2009, 09:42 PM
Alright, I got it working, thank you very much.