Jump to content

Information only viewable if criteria from database meet.


KurveMedia

Recommended Posts

This is my first post, so im hoping somebody here can help. My problem is i have a directory that im buliding and there are free listing for businesses and paid listings for businesses. one of the features of the paid listing is that the listing will include a link to google maps.

 

Problem is i only want that information to show up for paid listings and not both free and paid. when the business owner signs up for thier paid listing, there is a hidden field in the form that populates a field in the database with the type of listing "free" or "paid". How would i be able to only have the link viewable on paid listings. just alittle FYI im fairly new to PHP. Any help would be great.

 

 

Thanks in advance

Mike

Link to comment
Share on other sites

Hi Mike

 

My approach is to add a column in your database called paid_listing and assign it a value either '0' or '1'. '0' for unpaid listings and '1' for paid listings.

 

Then all you need to do is run a query that tests the value of this field.

 

ie

 

if paid listing==1

print "link to google maps"

 

I could be more specific if you posted some of your code.

 

Hope it helps.

 

Matt

Link to comment
Share on other sites

poleposters

 

Thanks for the quick response, below is my code for the listings page. thanks in advance

 

 

<?php require_once('Connections/latinolinx.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$maxRows_rsSubCat = 10;
$pageNum_rsSubCat = 0;
if (isset($_GET['pageNum_rsSubCat'])) {
  $pageNum_rsSubCat = $_GET['pageNum_rsSubCat'];
}
$startRow_rsSubCat = $pageNum_rsSubCat * $maxRows_rsSubCat;

$colname_rsSubCat = "-1";
if (isset($_GET['MainCat'])) {
  $colname_rsSubCat = $_GET['MainCat'];
}
mysql_select_db($database_latinolinx, $latinolinx);
$query_rsSubCat = sprintf("SELECT MainCat, SubCat FROM subcategory WHERE MainCat = %s", GetSQLValueString($colname_rsSubCat, "text"));
$query_limit_rsSubCat = sprintf("%s LIMIT %d, %d", $query_rsSubCat, $startRow_rsSubCat, $maxRows_rsSubCat);
$rsSubCat = mysql_query($query_limit_rsSubCat, $latinolinx) or die(mysql_error());
$row_rsSubCat = mysql_fetch_assoc($rsSubCat);

if (isset($_GET['totalRows_rsSubCat'])) {
  $totalRows_rsSubCat = $_GET['totalRows_rsSubCat'];
} else {
  $all_rsSubCat = mysql_query($query_rsSubCat);
  $totalRows_rsSubCat = mysql_num_rows($all_rsSubCat);
}
$totalPages_rsSubCat = ceil($totalRows_rsSubCat/$maxRows_rsSubCat)-1;

$maxRows_rsListing = 10;
$pageNum_rsListing = 0;
if (isset($_GET['pageNum_rsListing'])) {
  $pageNum_rsListing = $_GET['pageNum_rsListing'];
}
$startRow_rsListing = $pageNum_rsListing * $maxRows_rsListing;

mysql_select_db($database_latinolinx, $latinolinx);
$query_rsListing = "SELECT * FROM listings";
$query_limit_rsListing = sprintf("%s LIMIT %d, %d", $query_rsListing, $startRow_rsListing, $maxRows_rsListing);
$rsListing = mysql_query($query_limit_rsListing, $latinolinx) or die(mysql_error());
$row_rsListing = mysql_fetch_assoc($rsListing);

if (isset($_GET['totalRows_rsListing'])) {
  $totalRows_rsListing = $_GET['totalRows_rsListing'];
} else {
  $all_rsListing = mysql_query($query_rsListing);
  $totalRows_rsListing = mysql_num_rows($all_rsListing);
}
$totalPages_rsListing = ceil($totalRows_rsListing/$maxRows_rsListing)-1;

Link to comment
Share on other sites

Hey Mike,

 

Not sure if you've posted the right bit of code.I'm only quite new to PHP.I can see that you've selected the listing data and then put it into an array.But I don't think you show the code that actually prints the listing.

 

What you need to do is make sure that the query also pulls out the data from the paid_listing column, so that when you print the listings you can print the extra info for the paid listing.

 

e.g

print "yourarrayname[business_name];"
         print "yourarrayname[phone_number];"
         print "yourarrayname[address];"

if(yourarrayname[paid listing]==1)
         print"yourarrayname[linktogooglemap];"

 

This way the premium listing link to googlemaps only appears if the paid_listing field for that business is ==1.

 

 

 

Link to comment
Share on other sites

hey poleposter

 

i think this is what your looking for, im fairly new to php also., i appreciate the help.

<h3><?php echo $_GET['SubCat']; ?></h3>
  <hr />
    <table border="1">
    <tr>
      <td> </td>
      <td> </td>
      <td> </td>
      </tr>
    <?php do { ?>
      <tr>
        <td><?php echo $row_rsListing['BusinessLogo']; ?></td>
        <td><?php echo $row_rsListing['BusinessName']; ?></td>
        <td> </td>
        </tr>
      <tr>
        <td> </td>
        <td> </td>
        <td> </td>
        </tr>
      <tr>
        <td> </td>
        <td>Address:</td>
        <td> </td>
        </tr>
      <tr>
        <td> </td>
        <td><?php echo $row_rsListing['BusinessStreet']; ?></td>
        <td> </td>
        </tr>
      <tr>
        <td> </td>
        <td><?php echo $row_rsListing['BusinessCity']; ?></td>
        <td><?php echo $row_rsListing['BizState']; ?></td>
        </tr>
      <tr>
        <td> </td>
        <td> </td>
        <td><?php echo $row_rsListing['BusinessZip']; ?></td>
        </tr>
      <tr>
        <td> </td>
        <td>Contact Information:</td>
        <td> </td>
        </tr>
      <tr>
        <td> </td>
        <td><?php echo $row_rsListing['BusinessPhone']; ?></td>
        <td> </td>
        </tr>
      <tr>
        <td> </td>
        <td><?php echo $row_rsListing['WebAddress']; ?></td>
        <td> </td>
        </tr>
      <tr>
        <td> </td>
        <td>Map:</td>
        <td> </td>
      </tr>
      <?php } while ($row_rsListing = mysql_fetch_assoc($rsListing)); ?>
  </table>
</div>

 

Thanks

Mike

Link to comment
Share on other sites

I've changed the code below.

 

It should work, as long as you have a column called 'paid_listing in the same table where all the other array information is retrieved ie BusinesLogo,BusinessName etc.

 

Have the paid_listing record set to '0' by default and update it to '1' when the paid listing is purchased. That way the condition

 

        if ($$row_rsListing['paid_listing']>0 is satisfied, and the print link to googlemaps is executed.

 

 

 

<h3><?php echo $_GET['SubCat']; ?></h3>
  <hr />
    <table border="1">
    <tr>
      <td> </td>
      <td> </td>
      <td> </td>
      </tr>
    <?php do { ?>
      <tr>
        <td><?php echo $row_rsListing['BusinessLogo']; ?></td>
        <td><?php echo $row_rsListing['BusinessName']; ?></td>
        <td> </td>
        </tr>
      <tr>
        <td> </td>
        <td> </td>
        <td> </td>
        </tr>
      <tr>
        <td> </td>
        <td>Address:</td>
        <td> </td>
        </tr>
      <tr>
        <td> </td>
        <td><?php echo $row_rsListing['BusinessStreet']; ?></td>
        <td> </td>
        </tr>
      <tr>
        <td> </td>
        <td><?php echo $row_rsListing['BusinessCity']; ?></td>
        <td><?php echo $row_rsListing['BizState']; ?></td>
        </tr>
      <tr>
        <td> </td>
        <td> </td>
        <td><?php echo $row_rsListing['BusinessZip']; ?></td>
        </tr>
      <tr>
        <td> </td>
        <td>Contact Information:</td>
        <td> </td>
        </tr>
      <tr>
        <td> </td>
        <td><?php echo $row_rsListing['BusinessPhone']; ?></td>
        <td> </td>
        </tr>
      <tr>
        <td> </td>
        <td><?php echo $row_rsListing['WebAddress']; ?></td>
        <td> </td>
        </tr>
      <tr>
        <td> </td>
        [color=limegreen]<td>
          <?php 
          if ($$row_rsListing['paid_listing']>0)
   {
   print " LINK TO GOOGLEMAPS";
   }
        </td>[/color]        <td> </td>
      </tr>
      <?php } while ($row_rsListing = mysql_fetch_assoc($rsListing)); ?>
  </table>
</div>

Link to comment
Share on other sites

  • 2 weeks later...

Poleposter

 

I used the code you said to use and im gettign the following error when i acccess that page

 

"Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/content/l/a/t/latinolinx/html/testing/listing.php on line 250"

 

the follow code is what is on line 250

 echo "<a href=\"http://maps.google.com/maps?f=q&hl=es&q=$row_rsListing['businessNumber'],$row_rsListing['BusinessStreet'],$row_rsListing['BusinessCity'],$row_rsListing['BizState'],$row_rsListing['BusinessZip']\">View Map</a>";}

 

Link to comment
Share on other sites

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.