Jump to content

If /if Else


Jdog

Recommended Posts

Hey, I am new to PHP and I'm having a problem with a listing script I recently installed.

 

Long story short basically there are 3 listing types, the 3rd, or "3" is free listings, I am trying to use an IF or IF ELSE code so that if the [package] = 3, it shows the listing name without the link, here is the code for the listing.

 

I have bolded the area that needs to have the command.

 

 

<table class="listbox" width="100%" border="0" cellspacing="0" cellpadding="0">

<tr>

<?PHP

//---------------------------------------------------------------------

$filename = "$svr_rootscript/product_images/thumb/$row[iMAGENAME].jpg";

if (file_exists($filename)) {

//---------------------------

?>

<td valign="top" ><a class="thumbimage" href="<?PHP mrd("$MyProductTitle", "$row[LID]", "$_GET[category]", "$rowxxx[MR]", "index.php?page=detail"); ?>"><img src="product_images/thumb/<?php echo "$row[iMAGENAME]"; ?>.jpg" border="1" width="100px" /></a></td>

<?PHP } ?>

<td width="100%" valign="top">

 

 

 

<?php if ($row[package] != 3) { ?>

<h3><a href = "<?PHP mrd("$MyProductTitle", "$row[LID]", "$_GET[category]", "$rowxxx[MR]", "index.php?page=detail"); ?>"><?php echo "$row[TITLE]"; ?></a></h3>

<?PHP } ?>

 

<p><?php echo $row[CAPTION]; ?></p>

 

</td>

</tr>

</table>

 

The current IF command was told to me by a tech support from the place I got the software, but it doesn't work :(

 

Any help would be much appreciated.

 

Thank you.

Link to comment
Share on other sites

Nevermind, I worked it out.

 

 

<?php if ($row[PACKAGE] != 3) { ?>

<h3><a href = "<?PHP mrd("$MyProductTitle", "$row[LID]", "$_GET[category]", "$rowxxx[MR]", "index.php?page=detail"); ?>"><?php echo "$row[TITLE]"; ?></a></h3>

<?PHP } ?>

<?php if ($row[PACKAGE] != 1) { ?>

<?php echo "$row[TITLE]"; ?>

<?PHP } ?>

<p><?php echo $row[CAPTION]; ?></p>

 

 

If anyone can suggest a cleaner code go nuts.

Link to comment
Share on other sites

You really should be putting quotes around those array keys when they're not inside strings*. You may not see the message but PHP complains every time you do that. As for cleaner code... I don't see much to do.

<?php if ($row["PACKAGE"] != 3) { ?>
<h3><a href = "<?PHP mrd("$MyProductTitle", "$row[LID]", "$_GET[category]", "$rowxxx[MR]", "index.php?page=detail"); ?>"><?php echo "$row[TITLE]"; ?></a></h3>
<?PHP } ?>
<?php if ($row["PACKAGE"] != 1) { ?>
<?php echo "$row[TITLE]"; ?>
<?PHP } ?>
<p><?php echo $row["CAPTION"]; ?></p>

 

* Unless you use the {} syntax, then you do.

Link to comment
Share on other sites

The only way I see to make that code cleaner, is to remove all of those unnecessary PHP tags and quotes:

if ($row["PACKAGE"] != 3) {
   $link = mrd ($MyProductTitle, $row['LID'], $_GET['category'], $rowxxx['MR'], "index.php?page=detail");
   echo '<h3><a href = "'.$link.'">'.$row['TITLE'].'</a></h3>';
}

if ($row["PACKAGE"] != 1) {
   echo $row['TITLE'];
}

echo "<p>{$row['CAPTION']}</p>\n";

 

Also, giving your functions and variables some descriptive and meaningful names would go a long way. (What does mrd() do, for instance? I have no idea based upon the name alone.)

Link to comment
Share on other sites


Thanks for the replies guys, I have since found another problem, thought it would make more sense posting in there than making a new thread on it.

 

Ok package 1 and 2 work fine, but when I try to apply the same code but to a package != 3, it's not working, on the page that has packages 1 and 2 listed it has the template for 3 listed below each result, when i remove the IF commands for package 3 it displays 1 and 2 perfectly, and the result as package 3 twice, using the templates from 1 and 2, is there a bug or something from preventing this IF command I posted before working for more than 2 commands?

 

And to answer the other comment, I didn't write the code, I got the code when I got idev business listing 3.0, it was precoded, I am just making tweaks.

 

The results page is currently, with the code like this the template set for package 3 shows below both 1 & 2 and for package 3 it only shows the result twice, as template 1 and 2 (hope this makes sense)

 

<?php if ($_GET

 == searchr) $row[LID] = $row[iD]; ?>

<?php
$SQLbg = "SELECT * from PACKAGES WHERE ID = '$row[PACKAGE]'";
$resultbg = @mysql_query( $SQLbg ); $rowbg = @mysql_fetch_array( $resultbg );
if ($rowbg[HIGHLIGHT] != $nil) $bgcolor = $rowbg[HIGHLIGHT];
?>
<?php if ($_GET[mode] == 'search') $row[iD] = $row[iD]; ?>
<?PHP
$SQLview = "SELECT * from VIEW WHERE L_ID = '$row[iD]'"; $resultview = @mysql_query( $SQLview ); $rowview = @mysql_fetch_array( $resultview );
$SQLvisit = "SELECT * from VISIT WHERE L_ID = '$row[iD]'"; $resultvisit = @mysql_query( $SQLvisit ); $rowvisit = @mysql_fetch_array( $resultvisit );
?>

<?PHP
$country = ereg_replace(' ','+',$row[COUNTRY]);
$state = ereg_replace(' ','+',$row[sTATE]);
$province = ereg_replace(' ','+',$row[PROVINCE]);
$city = ereg_replace(' ','+',$row[CITY]);
$zip = ereg_replace(' ','+',$row[ZIP]);
$street = ereg_replace(' ','+',$row[sTREET]);

$country = strtolower($country);
$state = strtolower($state);
$province = strtolower($province);
$city = strtolower($city);
$zip = strtolower($zip);
$street = strtolower($street);
?>

<?PHP
$MyProductTitle=EdURL($row[TITLE]);
$row[CATEGORY]=str_replace("-","","$row[CATEGORY]");
?>

<?php if ($row["PACKAGE"] != 1) { ?>
<table class="listbox-red" width="100%" border="0" cellspacing="0" cellpadding="0" height="120px">
<tr>
<?PHP
//---------------------------------------------------------------------
$filename = "$svr_rootscript/product_images/thumb/$row[iMAGENAME].jpg";
if (file_exists($filename)) {
//---------------------------
?>
<td rowspan="2" valign="top" ><div class="thumbimage"><img src="product_images/thumb/<?php echo "$row[iMAGENAME]"; ?>.jpg" border="0" height="100px"></div>
<a href="<?PHP mrd("$MyProductTitle", "$row[LID]", "$_GET[category]", "$rowxxx[MR]", "index.php?page=detail"); ?>"><img src="images/more-info.gif"></a></td>
<?PHP } ?>
<td width="80%" valign="top"><h3><a href = "<?PHP mrd("$MyProductTitle", "$row[LID]", "$_GET[category]", "$rowxxx[MR]", "index.php?page=detail"); ?>"><font color="#FF0000">**URGENT**</font>
<?php echo "$row[TITLE]"; ?> - <?php echo $row[AGE]; ?></a></h3>
<p><?php echo $row[CAPTION]; ?></p>
<p></p></td>
<td width="20%" valign="top"><B><?php echo $row[sTATE]; ?></b><br> <?php echo $row[CITY]; ?>
<br> <br> </td>
</tr>
<tr>
<td valign="bottom"><b><?php echo $row[GENDER]; ?> <?php echo $row[bREED]; ?></b></td>
<td width="20%" valign="bottom"><?php echo "$row[DA]/$row[MA]/$row[YA]"; ?></td>
</tr>
</table>
<?PHP } ?>

<?php if ($row["PACKAGE"] != 2) { ?>
<table class="listbox" width="100%" border="0" cellspacing="0" cellpadding="0" height="120px">
<tr>
<?PHP
//---------------------------------------------------------------------
$filename = "$svr_rootscript/product_images/thumb/$row[iMAGENAME].jpg";
if (file_exists($filename)) {
//---------------------------
?>
<td rowspan="2" valign="top" ><div class="thumbimage"><img src="product_images/thumb/<?php echo "$row[iMAGENAME]"; ?>.jpg" border="0" height="100px" /></div>
<a href="<?PHP mrd("$MyProductTitle", "$row[LID]", "$_GET[category]", "$rowxxx[MR]", "index.php?page=detail"); ?>"><img src="images/more-info.gif"></a></td>
<?PHP } ?>
<td width="80%" valign="top"> <h3><a href = "<?PHP mrd("$MyProductTitle", "$row[LID]", "$_GET[category]", "$rowxxx[MR]", "index.php?page=detail"); ?>"><?php echo "$row[TITLE]"; ?>
- <?php echo $row[AGE]; ?></a></h3>
<p><?php echo $row[CAPTION]; ?></p>
</td>
<td width="20%" valign="top"><B><?php echo $row[sTATE]; ?></b><br> <?php echo $row[CITY]; ?> </td>
</tr>
<tr>
<td valign="bottom"><b><?php echo $row[GENDER]; ?> <?php echo $row[bREED]; ?></b></td>
<td width="20%" valign="bottom"><?php echo "$row[DA]/$row[MA]/$row[YA]"; ?></td>
</tr>
</table>
<?PHP } ?>
<?php if ($row["PACKAGE"] != 3) { ?>
<table class="listbox" width="100%" border="0" cellspacing="0" cellpadding="0" height="120px">
<tr>
<?PHP
//---------------------------------------------------------------------
$filename = "$svr_rootscript/product_images/thumb/$row[iMAGENAME].jpg";
if (file_exists($filename)) {
//---------------------------
?>
<td rowspan="2" valign="top" ><div class="thumbimage"><img src="product_images/thumb/<?php echo "$row[iMAGENAME]"; ?>.jpg" border="0" height="100px" /></div>
<a href="<?PHP mrd("$MyProductTitle", "$row[LID]", "$_GET[category]", "$rowxxx[MR]", "index.php?page=detail"); ?>"><img src="images/more-info.gif"></a></td>
<?PHP } ?>
<td width="80%" valign="top"> <h3><a href = "<?PHP mrd("$MyProductTitle", "$row[LID]", "$_GET[category]", "$rowxxx[MR]", "index.php?page=detail"); ?>"><?php echo "$row[TITLE]"; ?>
- <?php echo $row[AGE]; ?></a></h3>
<p><?php echo $row[CAPTION]; ?></p>
</td>
<td width="20%" valign="top"><B><?php echo $row[sTATE]; ?></b><br> <?php echo $row[CITY]; ?> </td>
</tr>
<tr>
<td valign="bottom"><b><?php echo $row[GENDER]; ?> <?php echo $row[bREED]; ?></b></td>
<td width="20%" valign="bottom"><?php echo "$row[DA]/$row[MA]/$row[YA]"; ?></td>
</tr>
</table>
<?PHP } ?>

Edited by Jdog
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.