Jump to content

I'm having trouble with my code, any help would be appreciated.


vet911

Recommended Posts

I'm having trouble with my code, any help would be appreciated. I'm trying to add an if statement that checks if $new =1, if it does it echos "new" else it echos "old". What is happening is if $new ="0 or 1 " it echos the same answer.

Here is partial code:

 

 

$result = mysql_query("SELECT * FROM $dbname WHERE  new = '1'") or die(mysql_error());
// store the record of the "" table into $row
$current = '';

// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
$id = $row['id'];
if (!$current) {
echo "<center><div><table border='0' width='520'>";
$current = $id;
echo "<img src='images/jewelry.png' alt='toveco'/><br/>";
echo "<div>";
	echo "Questions about store items use link in menu.<br/>";
	echo "Latest (".$rows5.") ";
	echo "Beads (".$rows4.") ";
	echo "Cabochons (".$rows3.") ";
echo "Earrings (".$rows1.") ";
echo "Pendants (".$rows2.") ";
echo "Rings (".$rows0.") ";
    echo "</div>";
    echo "<p><b>Click picture to enlarge.</b></p>";
echo "<hr width='520'>";
} elseif ($current != $id){
echo "</table></div><br><div><table border='0' width='520'>";
$current = $id;
echo "<hr width='520'>";
}
?>
<tr><td rowspan="9" width="110"><div class="image"><a href="<?= $row['image']; ?>" rel="lightbox" title="<?= $row['material']; ?>"><img src="<?= $row['image_th']; ?>" align="center" border="0"></a></div></td>
<td rowspan="9" width="110"><div class="image"><a href="<?= $row['image2']; ?>" rel="lightbox" title="<?= $row['material']; ?>"><img src="<?= $row['image2_th']; ?>" width="75" border="0"></a></div></td>
<tr><td>
<?php
if ($new=="0") echo "new";
else echo "old ";
?>
</td></tr>
<tr><th align="left">Item No.</th><td><?= $row['itemno']; ?></td></tr>
<tr><th align="left">Description</th><td><?= $row['description']; ?></td></tr>
<tr><th align="left">Cut</th><td><?= $row['cut']; ?></td></tr>
<tr><th align="left">Carat</th><td><?= $row['carat']; ?></td></tr>
<tr><th align="left">Material</th><td><?= $row['material']; ?></td></tr>
<tr><th align="left">Price</th><td><?= $row['price']; ?></td></tr>
<tr><th align="left">Availability</th><td><?= $row['availability']; ?></td></tr>
<tr><th></th>
<td></td>

Well, echoing it would be an essential step in debugging the code. You can't possibly know why the comparison isn't acting as you think it should unless you know the value of the variable you're comparing.

 

You should also have error_reporting set to -1, and display errors = On while developing so you can see any warnings or errors generated by php.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.