Jump to content

[SOLVED] Keep query data after reload help PLEASE - newbie


Recommended Posts

I've got drop down boxes that visitors select to see the items that they want. After selection the selected option gets displayed. I need help with the paging and sort by options coz if i sort or page I loose the selected items. The working code can be viewed at http://www.hefty.co.za. Sorting and paging is not yet enabled. Let me know if you need my code. Thanks

When the options that the visitors selected is displayed and they want to sort the records by using the sort by drop down or they go to page 2 I loose the records that were displayed so I end up with sorry no records found.

 

Here is the code that displays the records

<?php

$cat=$_POST['cat'];
$subcat=$_POST['subcat'];
$area=$_POST['area'];

if ($subcat != "1")
{
  $result = mysql_query("SELECT * FROM c_listing INNER JOIN c_company ON c_listing.c_company_id = c_company.c_company_id WHERE c_subcategory_id=$subcat AND area_id=$area");

  if ($area !="1")
    {
    $result = mysql_query("SELECT * FROM c_listing INNER JOIN c_company ON c_listing.c_company_id = c_company.c_company_id WHERE area_id=$area");
    }
    else
    {
  	$result = mysql_query("SELECT * FROM c_listing INNER JOIN c_company ON c_listing.c_company_id = c_company.c_company_id WHERE c_subcategory_id=$subcat");
    }
}
else
{
  $result = mysql_query("SELECT * FROM c_listing INNER JOIN c_company ON c_listing.c_company_id = c_company.c_company_id WHERE area_id=$area");

if ($area !="1")
    {
    $result = mysql_query("SELECT * FROM c_listing INNER JOIN c_company ON c_listing.c_company_id = c_company.c_company_id WHERE area_id=$area");
    }
    else
    {
  	$result = mysql_query("SELECT * FROM c_listing INNER JOIN c_company ON c_listing.c_company_id = c_company.c_company_id INNER JOIN c_subcategory ON c_listing.c_subcategory_id = c_subcategory.c_subcategory_id WHERE c_category_id=$cat");
    }
}
?>
<?php
$count=0; 
while($row = mysql_fetch_array($result)) 
  { 
echo "<table border='0' width='100%'> ";
echo "<tr>";
  	echo "<td rowspan='4'>"; 
	echo "<a href='classifieds/" . $row['c_item_ref'] . ".jpg'><img src='classifieds/" . $row['c_item_ref'] . ".jpg' width='150'></a>";
	echo "</td>";
  	echo "<th>Description</th>";
	echo "<th align='right'>Price: R " . $row['c_item_price'] . "</th>";
  echo "<tr>";
  	echo "<td colspan='2'>" . $row['c_item_description'] . "</td>";
echo "</tr>";
echo "<tr>";
  	echo "<td colspan='2'><b>Contact:</b> " . $row['c_company_contact_detail'] . "</td>";
echo "</tr>";
echo "<tr>";
  	echo "<td colspan='2'>";
	echo "<b>Email: </b>";
	echo "<a href='mailto:" . $row['c_company_email'] . "?subject=Listing on Hefty Description: " . $row['c_item_description'] . " Price: R " . $row['c_item_price'] . "'>" . $row['c_company_email'] . "</a></td>"; 
  echo "</tr>"; 
echo "<tr><td colspan='3' id='break'> </td></tr>";
$count++; 
  } 
if ($count==0) 
  { 
  echo 'Sorry no record was found.Please search again';
  } 
echo "</table>";
mysql_close($con);
?>

If you need to keep track of these;

 

$cat=$_POST['cat'];

$subcat=$_POST['subcat'];

$area=$_POST['area'];

 

Add them to your URL;

 

$link = '<a href="directory/your-page.php?cat=$cat&subcat=$subcat&area=$area">your link</a>'

Fixed the code above to have proper syntax, here is correct example:

 

$link = '<a href="directory/your-page.php?cat=' . $cat . '&subcat=' . $subcat . '&area=' . $area . '">your link</a>';

 

And this should be using "$_GET" not $_POST, since variables appeneded to an array is "GET"ting the data, when it is in a form and method="post" it is "posting" the data.

 

$cat=$_GET['cat'];
$subcat=$_GET['subcat'];
$area=$_GET['area'];

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.