I need a select that if the result is 0 or null it does not display the button

Asked

Viewed 61 times

-1

Hello need that if there is no link in the link column of the table the button does not display, the code in xampp works but in the hosting is not going I do not know why, the button displays and has no link or is not to display the button. follow php

<?php
$dados1 = mysqli_query($conectar, "SELECT p.produto, p.link1 from clientes c
JOIN infos i
ON c.id = i.idcliente
JOIN produtos p
ON i.idproduto = p.id WHERE p.id='$id'");

$num1 = mysqli_fetch_object($dados1);

if ($num1 == 0):

else :
    echo "<div class='pro-button2'>
                    <a href='$link1'>MediaFire</a>
                    </div><div style='float:left;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div>";
endif;
?>

if you have link = shows the button If no link = does not show the button

  • You must break the string <a href='+"$link1+"'>MediaFire</a>

  • So what I don’t understand is why he is echoing the button and in the column the value is NULL because there is no link in such id

1 answer

-1


With this query will be returned the number of records that contain a link and product with the same ID that you are informed.

SELECT count(*) 'linhas' FROM  clientes c
JOIN infos i ON c.id = i.idcliente
JOIN produtos p ON i.idproduto = p.id 
WHERE p.id='$id' AND p.link1 IS NOT NULL

From this code you can adapt according to the type of data stored in the field p.link1.

  • So, I need that if there is no link in the column it does not give me any information, now if there is link it returns me a button, already tried in several ways and it is not going

  • In a way, this is exactly what this code does, if its result is 0 (zero), that is to say that there is no record in the database that meets its criteria, if it returns anything other than zero, it is because there is a record.

  • I’m not getting why in the hosting even so continues to echo the boot and the local server xampp of all right

  • Every query will return you a set of data, so you have to specify the data you want to compare, I believe in your case, within the if should stay $num1->linhas = 0. See if this will work for you. NOTE: I edited the code to rename the count()

  • In xampp it worked, however in the hosting still it continues showing the button, in id where there is no link it understands that has link for example | 1 | NULL | Link2 | the hosting seems that is not understanding this null

  • I did, based on your code I only used the AND p.link1 IS NOT NULL and resolved

Show 1 more comment

Browser other questions tagged

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