Jump to content

Problem with an IF in a WHILE


slipperyfish

Recommended Posts

Hey!

This is part of my shoutbox script to display the shouts.

I want to run an IF within the WHILE to determine wether the email field in the db contains "no" - which means no email obviouslly. However I tried the following script, and it doesn't work?

I have a few sample shouts in the db; with and without emails - and the outcome is that the email link is always there, which, altho only a small problem, I want it to function properly.

Im guessing it's something to do with the IF being within the WHILE.

[code]<?php

include('../include/connect.php');

$sql = "SELECT * FROM ns_shouts ORDER BY time DESC";
    $qr = mysql_query($sql) or die("Error communicating with database.");

If ($qr) {

    while($qa=mysql_fetch_array($qr)) {

    $name = $qa[username];
    $shout = $qa[message];
    $time = $qa[time];
    $email = $qa[email];

    If ($email=="no") {
        print '<font style="font-family: Tahoma; font-size: 10px; color: #f1f1f1;"><b>' .$name. '</b>: </font>';
    } else {
        print '<font style="font-family: Tahoma; font-size: 10px; color: #f1f1f1;"><a href="mailto:' .$email. '"><b>' .$name. '</b></a>: </font>';
    }

    print '<font style="font-family: Tahoma; font-size: 10px; color: #f1f1f1;">' .$shout. '<br /></font>';
    print '<font style="font-family: Tahoma; font-size: 8px; color: #999999;">' .$time. '</font>';
    print '<hr color="#999999">';

    }

} else {
    print "<font class=\"normal\">No Shouts.</font>";
}

?>[/code]


Anyone any ideas?

-Thankyou
Link to comment
Share on other sites

[!--quoteo(post=363925:date=Apr 12 2006, 03:19 AM:name=slipperyfish)--][div class=\'quotetop\']QUOTE(slipperyfish @ Apr 12 2006, 03:19 AM) [snapback]363925[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Hey!

This is part of my shoutbox script to display the shouts.

I want to run an IF within the WHILE to determine wether the email field in the db contains "no" - which means no email obviouslly. However I tried the following script, and it doesn't work?

I have a few sample shouts in the db; with and without emails - and the outcome is that the email link is always there, which, altho only a small problem, I want it to function properly.

Im guessing it's something to do with the IF being within the WHILE.

[code]<?php

include('../include/connect.php');

$sql = "SELECT * FROM ns_shouts ORDER BY time DESC";
    $qr = mysql_query($sql) or die("Error communicating with database.");

If ($qr) {

    while($qa=mysql_fetch_array($qr)) {

    $name = $qa[username];
    $shout = $qa[message];
    $time = $qa[time];
    $email = $qa[email];

    If ($email=="no") {
        print '<font style="font-family: Tahoma; font-size: 10px; color: #f1f1f1;"><b>' .$name. '</b>: </font>';
    } else {
        print '<font style="font-family: Tahoma; font-size: 10px; color: #f1f1f1;"><a href="mailto:' .$email. '"><b>' .$name. '</b></a>: </font>';
    }

    print '<font style="font-family: Tahoma; font-size: 10px; color: #f1f1f1;">' .$shout. '<br /></font>';
    print '<font style="font-family: Tahoma; font-size: 8px; color: #999999;">' .$time. '</font>';
    print '<hr color="#999999">';

    }

} else {
    print "<font class=\"normal\">No Shouts.</font>";
}

?>[/code]
Anyone any ideas?

-Thankyou
[/quote]

The expression $email=="no" returns true if and only if the $email string is "no". In all other cases it returns false. If you want to search for the string "no" within a string use eregi()

if eregi("no", $email) {
// $email contains "no"
// Process
}

eregi() is case insensitive.
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.