SQL search specifies

Asked

Viewed 64 times

-1

Ola wanted to do a database search with and that only brings the answer if conditions are reached used code.

$sql2 ="SELECT * FROM `link` WHERE 1  LIKE ds_url_orig='https://www.frasesdobem.com.br/frases-incriveis' AND ds_email_link_modo='0'";
                $query2 = mysqli_query($link, $sql2) or die(mysqli_error());
                $show2 = mysqli_fetch_array($query2);
                $email_type = $show2['ds_email_link_modo'];

                while($rows = mysqli_fetch_array($query2)){
                    $email_type  =$rows['ds_email_link_modo'];
                    echo $email_type.'/';
                }

if ds_url_orig is found and the ds_email_link_mode is equal to the query it shows, and if one of them is false it n shows result. But the code keeps showing if a condition is true someone can help me

1 answer

2


Are you using the LIKE incorrectly.

Correct:

SELECT * 
FROM `link` 
WHERE ds_url_orig LIKE '%https://www.frasesdobem.com.br/frases-incriveis%' 
AND ds_email_link_modo = '0'

Also, if you only have numbers on ds_email_link_modo, usually won’t need quotes, unless it’s something very specific.

AND ds_email_link_modo = 0

The AND obligatory that the first filter be mandatory.


"Reading" your query, would be basically like this:

Bring everything from the table link, where ds_url_orig contain '%https://www.frasesdobem.com.br/frases-incriveis%' and ds_email_link_modo is equal to 0.

The % at the beginning of LIKE means "anything before", and the end "anything after" (can be removed)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.