Dynamic Table created from Recordset problem

Posted on 2006-05-09
Last Modified: 2010-04-25
Hi all,
I have a dynamic table who's images are being populated from a recordset (thanks to the guidance of Jason1178!). I can set the link on each of the images created in the table to a particular and pass a url parameter with it. However, I want to send the user to two different pages based on which image they click on. This will be based on whether the category_id in the recordset is either 1 or 2.  How can I set this? Some kind of IF statement is required but I can't seem to get my head around it. Here is the code so far for the page:)

<?php require_once('../Connections/GSM_mobile.php'); ?>
mysql_select_db($database_GSM_mobile, $GSM_mobile);
$query_rsPostalfromDB = "SELECT type_type_id, type_type_name, type_category_id, image_src FROM type_table WHERE type_category_id = 2";
$rsPostalfromDB = mysql_query($query_rsPostalfromDB, $GSM_mobile) or die(mysql_error());
$row_rsPostalfromDB = mysql_fetch_assoc($rsPostalfromDB);
$totalRows_rsPostalfromDB = mysql_num_rows($rsPostalfromDB);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<style type="text/css">
   td {height: 89px; width: 129px;}
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>

<form id="form1" name="form1" method="post" action="">
  <table border="1" >
$rsPostalfromDB_endRow = 0;
$rsPostalfromDB_columns = 3; // number of columns
$rsPostalfromDB_hloopRow1 = 0; // first row flag
do {
    if($rsPostalfromDB_endRow == 0  && $rsPostalfromDB_hloopRow1++ != 0) echo "<tr>";
      <td><a href="jasontester.php?Type_variable=<?php echo $row_rsPostalfromDB['type_type_id']; ?>"><img src="http://localhost/GSM/Images/<?php echo $row_rsPostalfromDB['image_src']; ?>" alt="<?php echo $row_rsPostalfromDB['type_type_name']; ?>" border="0" /></a></td>
      <?php  $rsPostalfromDB_endRow++;
if($rsPostalfromDB_endRow >= $rsPostalfromDB_columns) {
 $rsPostalfromDB_endRow = 0;
} while ($row_rsPostalfromDB = mysql_fetch_assoc($rsPostalfromDB));
if($rsPostalfromDB_endRow != 0) {
while ($rsPostalfromDB_endRow < $rsPostalfromDB_columns) {
Question by:dereksheahan
    LVL 70

    Accepted Solution

    Hi again, Derek.  Here is where the loop occurs.

    <a href="jasontester.php?Type_variable=<?php echo $row_rsPostalfromDB['type_type_id']; ?>"><img src="http://localhost/GSM/Images/<?php echo $row_rsPostalfromDB['image_src']; ?>" alt="<?php echo $row_rsPostalfromDB['type_type_name']; ?>" border="0" />

    All you need to do is make this a simple if-then-else using PHP the same way DW uses it to show/hide regions:

    <?php if($row_rsPostalfromDB['type_category_id'] == 1) { ?>

    <a href="PAGE1.PHP?Type_variable=<?php echo $row_rsPostalfromDB['type_type_id']; ?>"><img src="http://localhost/GSM/Images/<?php echo $row_rsPostalfromDB['image_src']; ?>" alt="<?php echo $row_rsPostalfromDB['type_type_name']; ?>" border="0" />

    <?php } else { ?>

    <a href="PAGE2.PHP?Type_variable=<?php echo $row_rsPostalfromDB['type_type_id']; ?>"><img src="http://localhost/GSM/Images/<?php echo $row_rsPostalfromDB['image_src']; ?>" alt="<?php echo $row_rsPostalfromDB['type_type_name']; ?>" border="0" />

    <?php } ?>

    Author Comment

    Legend! Spot on as usual

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    I still run into .cgi files every now and then. In some instances, I actually prefer the simplicity of a .cgi script to other options. Since I use DreamWeaver extensively, what I needed was a way to open .cgi scripts in Dreamweaver. And I wanted to …
    This article is very specific and is only intended to help if you are installing Dreamweaver 8 in a Windows 7 environment with Office 2007 installed.   I'm not sure why Microsoft tends to release OS' that should not be released but they do.  Windows…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now