Solved --- Problem with loop if field is 0
Posted: Wed Mar 10, 2004 2:58 pm
I am having a problem with a loop that I want to show the contents of a field if it is not zero. Here is my code:
I believe the problem lies in this code:
I am fairly new to this, a few months, so I appreciate the help in advance.
Thanks,
Dmacman
Code: Select all
<?
$dbHost = "xxxxx";
$dbName = "xxxxx";
$dbUser = "xxxxx";
$dbPass = "xxxxx";
$connmts = mysql_connect($dbHost, $dbUser, $dbPass) or trigger_error(mysql_error(),E_USER_ERROR);
$link = @mysql_connect($dbHost, $dbUser, $dbPass);
if (!$link){
$errorMsg = "Could not connect to server";
print "&result=Fail&errorMsg=$errorMsg";
exit;
}
if (!@mysql_select_db($dbName)){
$errorMsg = "Could not select $dbName database";
print "&result=Fail&errorMsg=$errorMsg";
exit;
}
$hold = $_REQUEST['merchant'];
$query = "SELECT * FROM coupons WHERE id LIKE '$hold%' AND active = 1 ORDER BY id asc";
$merchants = mysql_query($query, $connmts) or die(mysql_error());
if (mysql_num_rows($merchants) < 1) {
print "There are no offers at this time. ";
} else {
while ($row = mysql_fetch_array($merchants, MYSQL_ASSOC)) {
$list = $row['info'];
$coupon = $row['coupon'];
$merchant_name = $row['merchant_name'];
print "<strong>$merchant_name</strong><br><br>";
print "<a href='http://www.mytownsavings.com/proxy.asp?action=clip&coupon=$coupon'>";
if ($list != 0) {
print "<strong>$list</strong>";
} else {
print "<br>";
}
print "<br>";
}
}
?>Code: Select all
<?
if ($list != 0) {
print "<strong>$list</strong>";
} else {
print "<br>";
?>Thanks,
Dmacman