SELECT selects too quick
am 05.01.2007 11:47:31 von Anne Bos
In a database about houses I want the visitor to make a choice by
typing in an address. As a result the database presents one or more
adresses according to the input. So far so good.
However, when arriving on this page I want to present a greeting and
some instructions. So the page starts with:
if (!isset ($_POST['address'])) {echo "Welcome, Instructions etc.";}
?>
In spite of this I always get a list of all addresses, perfectly as I
want to present them AFTER the input.
What might I do wrong, what is it I'm overlooking?
Any suggestion is appreciated.
Re: SELECT selects too quick
am 05.01.2007 12:53:25 von Captain Paralytic
Anne Bos wrote:
> In a database about houses I want the visitor to make a choice by
> typing in an address. As a result the database presents one or more
> adresses according to the input. So far so good.
>
> However, when arriving on this page I want to present a greeting and
> some instructions. So the page starts with:
>
> if (!isset ($_POST['address'])) {echo "Welcome, Instructions etc.";}
> ?>
>
> In spite of this I always get a list of all addresses, perfectly as I
> want to present them AFTER the input.
> What might I do wrong, what is it I'm overlooking?
> Any suggestion is appreciated.
Is the rest of the code in an "else" block, or will is execute
regardless of whether $_POST['address'])) is set?
Re: SELECT selects too quick
am 05.01.2007 15:05:38 von Anne Bos
On 5 Jan 2007 03:53:25 -0800 wrote "Captain Paralytic"
:
>
>Anne Bos wrote:
>
>> In a database about houses I want the visitor to make a choice by
>> typing in an address. As a result the database presents one or more
>> adresses according to the input. So far so good.
>>
>> However, when arriving on this page I want to present a greeting and
>> some instructions. So the page starts with:
>>
>> if (!isset ($_POST['address'])) {echo "Welcome, Instructions etc.";}
>> ?>
>>
>> In spite of this I always get a list of all addresses, perfectly as I
>> want to present them AFTER the input.
>> What might I do wrong, what is it I'm overlooking?
>> Any suggestion is appreciated.
>
>Is the rest of the code in an "else" block, or will is execute
>regardless of whether $_POST['address'])) is set?
To get rid of this situation I made an 'else' block with a code that
is checked when results are coming. But I thought that this should not
be necessary as in the beginning there should be no input is
POST['address']
Re: SELECT selects too quick
am 05.01.2007 15:09:31 von Captain Paralytic
Anne Bos wrote:
> On 5 Jan 2007 03:53:25 -0800 wrote "Captain Paralytic"
> :
>
> >
> >Anne Bos wrote:
> >
> >> In a database about houses I want the visitor to make a choice by
> >> typing in an address. As a result the database presents one or more
> >> adresses according to the input. So far so good.
> >>
> >> However, when arriving on this page I want to present a greeting and
> >> some instructions. So the page starts with:
> >>
> >> if (!isset ($_POST['address'])) {echo "Welcome, Instructions etc.";}
> >> ?>
> >>
> >> In spite of this I always get a list of all addresses, perfectly as I
> >> want to present them AFTER the input.
> >> What might I do wrong, what is it I'm overlooking?
> >> Any suggestion is appreciated.
> >
> >Is the rest of the code in an "else" block, or will is execute
> >regardless of whether $_POST['address'])) is set?
>
> To get rid of this situation I made an 'else' block with a code that
> is checked when results are coming. But I thought that this should not
> be necessary as in the beginning there should be no input is
> POST['address']
If you don't code the else, then all the code will run regardless of
the if statement. You do understand the basics of programming don't you?
Re: SELECT selects too quick
am 05.01.2007 15:18:20 von Shion
Anne Bos wrote:
> On 5 Jan 2007 03:53:25 -0800 wrote "Captain Paralytic"
> :
>
>> Anne Bos wrote:
>>
>>> In a database about houses I want the visitor to make a choice by
>>> typing in an address. As a result the database presents one or more
>>> adresses according to the input. So far so good.
>>>
>>> However, when arriving on this page I want to present a greeting and
>>> some instructions. So the page starts with:
>>>
>>> if (!isset ($_POST['address'])) {echo "Welcome, Instructions etc.";}
>>> ?>
>>>
>>> In spite of this I always get a list of all addresses, perfectly as I
>>> want to present them AFTER the input.
>>> What might I do wrong, what is it I'm overlooking?
>>> Any suggestion is appreciated.
>> Is the rest of the code in an "else" block, or will is execute
>> regardless of whether $_POST['address'])) is set?
>
> To get rid of this situation I made an 'else' block with a code that
> is checked when results are coming. But I thought that this should not
> be necessary as in the beginning there should be no input is
> POST['address']
'If' don't work like that by itself, it just allows or denies something to be
done when the program is at the if-statement. And everything after the 'if' is
executed too. Of course you can make the program to stop inside an 'if'
function testsome($something,$somethingelse) {
if($something==$somethingelse) {
echo "something and somethingelse are the same\n";
return;
}
echo "something isn't somethingelse\n";
}
echo "first test: ";
testsome(1,1);
echo "second test: ";
testsome(1,2);
?>
You shoudl get an output that looks like:
first test: something and somethingelse are the same
second test: something isn't somethingelse
inside functions 'return' is a good way to stop execute things in program,
while on your page 'exit' had been a better option.
--
//Aho
Re: SELECT selects too quick
am 06.01.2007 21:59:12 von Anne Bos
On Fri, 05 Jan 2007 15:18:20 +0100 wrote "J.O. Aho"
:
>Anne Bos wrote:
>> On 5 Jan 2007 03:53:25 -0800 wrote "Captain Paralytic"
>> :
>>
>>> Anne Bos wrote:
>>>
>>>> In a database about houses I want the visitor to make a choice by
>>>> typing in an address. As a result the database presents one or more
>>>> adresses according to the input. So far so good.
>>>>
>>>> However, when arriving on this page I want to present a greeting and
>>>> some instructions. So the page starts with:
>>>>
>>>> if (!isset ($_POST['address'])) {echo "Welcome, Instructions etc.";}
>>>> ?>
>>>>
>>>> In spite of this I always get a list of all addresses, perfectly as I
>>>> want to present them AFTER the input.
>>>> What might I do wrong, what is it I'm overlooking?
>>>> Any suggestion is appreciated.
>>> Is the rest of the code in an "else" block, or will is execute
>>> regardless of whether $_POST['address'])) is set?
>>
>> To get rid of this situation I made an 'else' block with a code that
>> is checked when results are coming. But I thought that this should not
>> be necessary as in the beginning there should be no input is
>> POST['address']
>
>'If' don't work like that by itself, it just allows or denies something to be
>done when the program is at the if-statement. And everything after the 'if' is
>executed too. Of course you can make the program to stop inside an 'if'
>
>
>
>function testsome($something,$somethingelse) {
> if($something==$somethingelse) {
> echo "something and somethingelse are the same\n";
> return;
> }
>
> echo "something isn't somethingelse\n";
> }
>
>echo "first test: ";
> testsome(1,1);
>echo "second test: ";
> testsome(1,2);
>?>
>
>You shoudl get an output that looks like:
>first test: something and somethingelse are the same
>second test: something isn't somethingelse
>
>inside functions 'return' is a good way to stop execute things in program,
>while on your page 'exit' had been a better option.
Thank you. After all this is quite logical
Re: SELECT selects too quick
am 06.01.2007 22:08:44 von Rik
J.O. Aho wrote:
> inside functions 'return' is a good way to stop execute things in
> program, while on your page 'exit' had been a better option.
Don't forget: return can also end includes.
The times I've seen horribly nested if statements all over files that were
only used as includes are numerous. A simple return will clear a lot of
nesting, and make those scripts a lot more readable.
--
Rik Wasmus