vet911 Posted April 19, 2011 Share Posted April 19, 2011 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> Quote Link to comment https://forums.phpfreaks.com/topic/234197-im-having-trouble-with-my-code-any-help-would-be-appreciated/ Share on other sites More sharing options...
mens Posted April 19, 2011 Share Posted April 19, 2011 How, and where is $new defined? Also note, if you are using integers encased as strings, you are better off using ctype_digit() for comparison. Quote Link to comment https://forums.phpfreaks.com/topic/234197-im-having-trouble-with-my-code-any-help-would-be-appreciated/#findComment-1203748 Share on other sites More sharing options...
spiderwell Posted April 19, 2011 Share Posted April 19, 2011 the statement isnt quite formed correctly <?php if ($new==0) { echo "new";} else { echo "old "; } ?> also theres a difference with "0" and 0, "0" is a string whereas 0 is a number, or false Quote Link to comment https://forums.phpfreaks.com/topic/234197-im-having-trouble-with-my-code-any-help-would-be-appreciated/#findComment-1203749 Share on other sites More sharing options...
Pikachu2000 Posted April 19, 2011 Share Posted April 19, 2011 What is the value of $new when you echo it? Quote Link to comment https://forums.phpfreaks.com/topic/234197-im-having-trouble-with-my-code-any-help-would-be-appreciated/#findComment-1203756 Share on other sites More sharing options...
vet911 Posted April 19, 2011 Author Share Posted April 19, 2011 $new is coming out of the database $result currently I just searching for the new that has a 1 in it. I haven't echoed $new yet. Quote Link to comment https://forums.phpfreaks.com/topic/234197-im-having-trouble-with-my-code-any-help-would-be-appreciated/#findComment-1203759 Share on other sites More sharing options...
Pikachu2000 Posted April 19, 2011 Share Posted April 19, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/234197-im-having-trouble-with-my-code-any-help-would-be-appreciated/#findComment-1203761 Share on other sites More sharing options...
vet911 Posted April 20, 2011 Author Share Posted April 20, 2011 I figured it out, thanks for you time and comments. It helped a lot. Quote Link to comment https://forums.phpfreaks.com/topic/234197-im-having-trouble-with-my-code-any-help-would-be-appreciated/#findComment-1203795 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.