Page 1 of 1
What am i missing in my if statement
Posted: Thu Jan 15, 2015 6:39 am
by jonnyfortis
i am having a real issue with something i have done a 1000 times. i want to show an image on a page only if the category has been requested. it is working for one category but none of the others. for the category that works i need an image replacing so i have an ignore then an == but with the ones that dont work i just need the ==
here is what i have
Code: Select all
$var1_rsProd = "-1";
if (isset($_GET['Cat'])) {
$var1_rsProd = $_GET['Cat'];
}
mysql_select_db($database_twizSS15, $twizSS15);
$query_rsProd = sprintf("SELECT * FROM twiz_Cat, btwiz_products WHERE twiz_products.catID = twiz_Cat.catID AND twiz_products.catID = %s ORDER BY CAST(`order` AS UNSIGNED) ASC", GetSQLValueString($var1_rsProd, "int"));
$query_limit_rsProd = sprintf("%s LIMIT %d, %d", $query_rsProd, $startRow_rsProd, $maxRows_rsProd);
$rsProd = mysql_query($query_limit_rsProd, $beauSS15) or die(mysql_error());
$row_rsProd = mysql_fetch_assoc($rsProd);
catID == 44 works
Code: Select all
<? if ($row_rsProd['catID'] != 44):
?>
<div class="my-div" style="background-image:url('../images/SS15/thumbs/<?php echo $row_rsProd['Image']; ?>')"><br /><br /><br /><br />
<br />
<br />
<?php if ($row_rsProd['OutOfStock'] == 1): ?><img src="../images/sold-out.png" alt="sold out" width="100" height="100" align="right" /><?php endif;?></div>
<?php endif;?>
<? if ($row_rsProd['catID'] == 44):
?>
<div id="jackets"><a href="../SS15/SS15product-detail.php?ItemID=3036"><img src="../images/SS15/3036L.jpg" width="400" height="400" alt="jackets" /></a>
<a href="../SS15/SS15product-detail.php?ItemID=3037"><img src="../images/SS15/3037L.jpg" width="400" height="400" alt="jackets2" /></a><?php endif;?>
31 is one of the categorys that doesnt
Code: Select all
<? if ($row_rsProd['catID'] == 31):
?>
<a href="../SS15/SS15product-detail.php?ItemID=3062"><img src="../images/SS15/thumbs/3062.jpg"/></a>
<?php endif;?>
there is other code around it like a loop etc but this is the bit i think is the issue
Re: What am i missing in my if statement
Posted: Thu Jan 15, 2015 6:50 am
by Celauran
jonnyfortis wrote:
Code: Select all
<? if ($row_rsProd['catID'] == 31):
?>
<a href="../SS15/SS15product-detail.php?ItemID=3062"><img src="../images/SS15/thumbs/3062.jpg"/></a>
<?php endif;?>
there is other code around it like a loop etc but this is the bit i think is the issue
Nothing wrong with that bit of code. Have you inspected the value of $row_rsProd['catID']? Have you confirmed that the query actually returned results?
Re: What am i missing in my if statement
Posted: Thu Jan 15, 2015 7:07 am
by jonnyfortis
Celauran wrote:jonnyfortis wrote:
Code: Select all
<? if ($row_rsProd['catID'] == 31):
?>
<a href="../SS15/SS15product-detail.php?ItemID=3062"><img src="../images/SS15/thumbs/3062.jpg"/></a>
<?php endif;?>
there is other code around it like a loop etc but this is the bit i think is the issue
Nothing wrong with that bit of code. Have you inspected the value of $row_rsProd['catID']? Have you confirmed that the query actually returned results?
yes i am still trying to find out when it will show on the page. it doesnt show in certain parts.. very stranged
if i place it above all the other code it show but if i place it at the bottom of the page where i need it ..it doesnt. i will show you the whole page because there are some loops in the page but that should effect it
it works if i put it within the loop but it then show the item 4 time which is no good
Code: Select all
<? if ($row_rsProd['catID'] != 44):
?>
<?php if ($totalRows_rsProd == 0) { // Show if recordset empty ?>
<span class="headerRED">
<br />
No Products Found
<?php } // Show if recordset empty ?>
</span>
<?php if ($totalRows_rsProd > 0) { // Show if recordset not empty ?>
<table border="0" class="maintext">
<tr>
<td><?php if ($pageNum_rsProd > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_rsProd=%d%s", $currentPage, 0, $queryString_rsProd); ?>">First</a>
<?php } // Show if not first page ?></td>
<td><?php if ($pageNum_rsProd > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_rsProd=%d%s", $currentPage, max(0, $pageNum_rsProd - 1), $queryString_rsProd); ?>">Previous</a>
<?php } // Show if not first page ?></td>
<td><?php if ($pageNum_rsProd < $totalPages_rsProd) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_rsProd=%d%s", $currentPage, min($totalPages_rsProd, $pageNum_rsProd + 1), $queryString_rsProd); ?>">Next</a>
<?php } // Show if not last page ?></td>
<td><?php if ($pageNum_rsProd < $totalPages_rsProd) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_rsProd=%d%s", $currentPage, $totalPages_rsProd, $queryString_rsProd); ?>">Last</a>
<?php } // Show if not last page ?></td>
</tr>
</table>
</p>
<table cellpadding="0" cellspacing="0" >
<tr>
<?php
$rsProd_endRow = 0;
$rsProd_columns = 4; // number of columns
$rsProd_hloopRow1 = 0; // first row flag
do {
if($rsProd_endRow == 0 && $rsProd_hloopRow1++ != 0) echo "<tr>";
?>
<td width="250" height="250" align="right" valign="bottom"><a href="../SS15/SS15product-detail.php?ItemID=<?php echo $row_rsProd['ItemID']; ?>"><div class="my-div" style="background-image:url('../images/SS15/thumbs/<?php echo $row_rsProd['Image']; ?>')"><br /><br /><br /><br />
<br />
<br />
<?php if ($row_rsProd['OutOfStock'] == 1): ?><img src="../images/sold-out.png" alt="sold out" width="100" height="100" align="right" /><?php endif;?></div>
<span class="strangelove"></span>
</a>
</td>
<?php $rsProd_endRow++;
if($rsProd_endRow >= $rsProd_columns) {
?>
</tr>
<?php
$rsProd_endRow = 0;
}
} while ($row_rsProd = mysql_fetch_assoc($rsProd));
if($rsProd_endRow != 0) {
while ($rsProd_endRow < $rsProd_columns) {
echo("<td> </td>");
$rsProd_endRow++;
}
echo("</tr>");
}?><br />
</table>
<table border="0" class="maintext">
<tr>
<td><?php if ($pageNum_rsProd > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_rsProd=%d%s", $currentPage, 0, $queryString_rsProd); ?>">First</a>
<?php } // Show if not first page ?></td>
<td><?php if ($pageNum_rsProd > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_rsProd=%d%s", $currentPage, max(0, $pageNum_rsProd - 1), $queryString_rsProd); ?>">Previous</a>
<?php } // Show if not first page ?></td>
<td><?php if ($pageNum_rsProd < $totalPages_rsProd) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_rsProd=%d%s", $currentPage, min($totalPages_rsProd, $pageNum_rsProd + 1), $queryString_rsProd); ?>">Next</a>
<?php } // Show if not last page ?></td>
<td><?php if ($pageNum_rsProd < $totalPages_rsProd) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_rsProd=%d%s", $currentPage, $totalPages_rsProd, $queryString_rsProd); ?>">Last</a>
<?php } // Show if not last page ?></td>
</tr>
</table>
<?php } // Show if recordset not empty ?><?php endif;?>
<? if ($row_rsProd['catID'] == 44):
?>
<div id="jackets"><a href="../SS15/SS15product-detail.php?ItemID=3036"><img src="../images/SS15/3036L.jpg" width="400" height="400" alt="jackets" /></a>
<a href="../SS15/SS15product-detail.php?ItemID=3037"><img src="../images/SS15/3037L.jpg" width="400" height="400" alt="jackets2" /></a><?php endif;?>
<? if ($row_rsProd['catID'] == 31):
?><a href="../SS15/SS15product-detail.php?ItemID=3061"><img src="../images/SS15/thumbs/3061.jpg"/></a><?php endif;?>
<? if ($row_rsProd['catID'] == 31):
?>
<a href="../SS15/SS15product-detail.php?ItemID=3062"><img src="../images/SS15/thumbs/3062.jpg"/></a>
<?php endif;?>
<? if ($row_rsProd['catID'] == 36):
?>
<a href="../SS15/SS15product-detail.php?ItemID=3061"><img src="../images/SS15/3061.jpg"/></a>
<?php endif;?>
<? if ($row_rsProd['catID'] == 36):
?>
<a href="../SS15/SS15product-detail.php?ItemID=3062"><img src="../images/SS15/3062.jpg"/></a>
<?php endif;?></div>
</p>
</div>
Re: What am i missing in my if statement
Posted: Thu Jan 15, 2015 7:21 am
by Celauran
Outside of the loop, $row_rsProd only has one value; the one from the last iteration of the loop. This is why it works inside the loop and not outside. What is it you're trying to do here? I can see you're showing links and images based on a per-category basis, but why is 4 times bad if the catID matches 4 times? What's the end goal?
Re: What am i missing in my if statement
Posted: Thu Jan 15, 2015 7:26 am
by jonnyfortis
Celauran wrote:Outside of the loop, $row_rsProd only has one value; the one from the last iteration of the loop. This is why it works inside the loop and not outside. What is it you're trying to do here? I can see you're showing links and images based on a per-category basis, but why is 4 times bad if the catID matches 4 times? What's the end goal?
basically what i am trying do i force a product that is already in another category to show in a second category so if it shows up for times it is showing the same (forced product) four times
would it be better if i show by the item id within the loop?...just tried that wont work
Re: What am i missing in my if statement
Posted: Thu Jan 15, 2015 7:29 am
by Celauran
Items can't belong to more than one category?
Re: What am i missing in my if statement
Posted: Thu Jan 15, 2015 7:30 am
by jonnyfortis
Celauran wrote:Items can't belong to more than one category?
no the way it has been set up, there was no need until now..with just a few
Re: What am i missing in my if statement
Posted: Thu Jan 15, 2015 7:37 am
by Celauran
Looking through the fragments of code you've posted, it looks like you're trying to display products for a certain category based on a GET parameter. If so, could you not use that same parameter to display the additional links?
Re: What am i missing in my if statement
Posted: Thu Jan 15, 2015 7:43 am
by jonnyfortis
Celauran wrote:Looking through the fragments of code you've posted, it looks like you're trying to display products for a certain category based on a GET parameter. If so, could you not use that same parameter to display the additional links?
yes thats what i am trying to do. can you explain what you mean please?
i have tried to build an new query and use the GET parameter from the other quesry but that doesnt seem to work.
Re: What am i missing in my if statement
Posted: Thu Jan 15, 2015 7:45 am
by jonnyfortis
jonnyfortis wrote:Celauran wrote:Looking through the fragments of code you've posted, it looks like you're trying to display products for a certain category based on a GET parameter. If so, could you not use that same parameter to display the additional links?
yes thats what i am trying to do. can you explain what you mean please?
i have tried to build an new query and use the GET parameter from the other quesry but that doesnt seem to work.
hang on
Code: Select all
mysql_select_db($database_beauSS15, $beauSS15);
$query_rsPros1 = sprintf("SELECT * FROM beauloves_Cat, beauloves_products WHERE beauloves_products.catID = beauloves_Cat.catID AND beauloves_products.catID = %s ORDER BY CAST(`order` AS UNSIGNED) ASC", GetSQLValueString($var1_rsProd, "int"));
$rsPros1 = mysql_query($query_rsPros1, $beauSS15) or die(mysql_error());
$row_rsPros1 = mysql_fetch_assoc($rsPros1);
$totalRows_rsPros1 = mysql_num_rows($rsPros1);
<? if ($row_rsPros1['catID'] == 31):
?><a href="../SS15/SS15product-detail.php?ItemID=3061"><img src="../images/SS15/thumbs/3061.jpg"/></a><?php endif;?>
worked