slipperyfish Posted April 12, 2006 Share Posted April 12, 2006 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]<?phpinclude('../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 Link to comment Share on other sites More sharing options...
bonaparte Posted April 12, 2006 Share Posted April 12, 2006 [!--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]<?phpinclude('../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. Quote Link to comment Share on other sites More sharing options...
slipperyfish Posted April 12, 2006 Author Share Posted April 12, 2006 sorry, i dont think i explained properly. When they submit a shout, if they didnt enter an email, the default value "no" is put in the database. In the database, if the value of the email field is equal to "no", then the email link shouldn't be visible for that row. Quote Link to comment 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.