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>

Link to comment
Share on other sites

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.

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.