Jump to content

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

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.