Dynamic Table created from Recordset problem

Posted on 2006-05-09
Medium Priority
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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<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

Jason C. Levine earned 1600 total points
ID: 16652763
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

ID: 16653232
Legend! Spot on as usual

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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 …
Adobe Dreamweaver CS5 is a WYSIWYG web page editor that has advanced HTML, CSS, and Javascript rendering functionality and is probably the most well-known HTML editor available. Much of Dreamweaver's appeal centers around the Design View interfac…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Screencast - Getting to Know the Pipeline
Suggested Courses

831 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