Jump to content

if else


fer0an

Recommended Posts

hello

I've query that find duplicate entry on my website.

I want add entry if it's not duplicate else continue next entry.

this is my code but when finding duplicate stoped and write cannot fronted.

 

if($result5_f = mysql_query($query5_f) ) echo "fronted"; else die(mysql_error()."cannot fronted");

 

please help me

Link to comment
https://forums.phpfreaks.com/topic/241492-if-else/
Share on other sites

Im also a big fan of curly brackets, and wasn't sure the code would work without them, so I did a little test

 

<?php
$br = "breeze";
	if($br == "breeze") echo "its a breeze"; else echo "not so easy";
?>

 

and the result was "its a breeze" so while I agree curly brackets are probably best practice, they don't appear to be necessary

Link to comment
https://forums.phpfreaks.com/topic/241492-if-else/#findComment-1240515
Share on other sites

Curly brackets are not required IF the if/else statement only has one line following it.  I am a fan of using them at all times.  That being said, I'm not sure if this line of code does what you want it to:

$result5_f == mysql_query($query5_f)

 

As mysql_query() returns a result resource, and not the actual data.  It would help you understand this better, if you ran this line:

echo mysql_query($query5_f);

Link to comment
https://forums.phpfreaks.com/topic/241492-if-else/#findComment-1240536
Share on other sites

Its been so long since Ive coded proper PHP (I've been using CakePHP for a few years now) I can hardly remember how the database calls go.

 

Perhaps something like (hope my syntax is correct)

 

<?php $r1 = mysql_query("SELECT * FROM tablename WHERE fieldname == '$comparison_value'");

if(mysql_num_rows($r1) > 0){
   echo "its a duplicate";
}
else{
   echo "its unique";
} ?>

Link to comment
https://forums.phpfreaks.com/topic/241492-if-else/#findComment-1240657
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.