0

I am experimenting with PHP. This is my func.php

function returnBlankStylist(){

$sql=mysql_query("SELECT * FROM `".$dbn."`.`stylist` WHERE `stylist`.`customer_id`='1'");
if (mysql_affected_rows()==0) {
 return false;
} else {
 return true;
}
}

This is my page.tpl

<?php if (returnBlankStylist==false){?>
<div class="center graybox"> Please enjoy this discount since this you have never filled out a query before</div>
<? }?>

If the customer Id 1 exists it shows the message, and if the customer Id 1 does not exist it shows the message?

3 Answers 3

4

Page.tpl

<?php if (returnBlankStylist() == false) : ?>
    <div class="center graybox">
        Please enjoy this discount since this you have never filled out a query before
    </div>
<? endif; ?>

or

<?php if (!returnBlankStylist()) : ?>
    <div class="center graybox">
        Please enjoy this discount since this you have never filled out a query before
    </div>
<? endif; ?>

or

<?php if (returnBlankStylist() == false) { ?>
    <div class="center graybox">
        Please enjoy this discount since this you have never filled out a query before
    </div>
<? } ?>
Sign up to request clarification or add additional context in comments.

3 Comments

Why the dots and calling the function again within the IF?
returnBlankStylist alone doesn't do anything, you need to call it by adding the (). The dots don't really matter, it just looks better ;)
@TheBlackBenzKid it's just an alternative syntax
1

you have missed parenthises ..

if(returnBlankStylist()==false){
    //your code...
}

hope it will work for you

Comments

1

Please replace your code if (mysql_affected_rows()==0) to if (mysql_num_rows()==0);

and try this:

<?php if (!returnBlankStylist()){?>
<div class="center graybox"> Please enjoy this discount since this you have never filled out a query before</div>
<? }?>

1 Comment

repped for efforts – I prefer the ! when it can be used for performance and less characters

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.