Clearing/resetting a page
Posted by Chris_Isaac (Chris Isaac), 26 July 2003Hi
The following peice of code generates a list of hyperlinks, with values, which are then passed to the next part of the program which generates the search results. All works fine, except the page doesn't clear the hyperlinks, they remain and the results are put at the bottom.
I did try putting a form around each hyoerlink but that failed badly!
How would I clear the page before printing the results?
Posted by admin (Graham Ellis), 26 July 2003Chris, Your code generates a list of HREFs. As I read it, this code is working fine. It's just that when you re-submit your form back to the same script, the list re-appears. The solution is to have some sort of condition check in your code (before the code you submitted to the board) to check whether it's necessary to generate the links or not. The crudest / most "bull at a gate" approach to this is to put another paramater into the href links such as &specific=1 and test for $_GET[specific] before you output the HREF list. There's probably a much more elegant alternative if you look at your overall design.
Posted by Chris_Isaac (Chris Isaac), 26 July 2003I'm not sure I follow exactly what you mean. Yes, it does generate a list of hyperlinks, for example if you did a search on Newport it would come up with the following:
Town: Newport -- County : County Down
Town: Newport -- County : Isle of Wight
Town: Newport -- County : Gwent
Town: Newport Pagnell -- County : Buckinghamshire
Town: Newport, Pembrokeshire -- County : Pembrokeshire
Town: Newport, Shropshire -- County : Shropshire
which is fine, each 1 is basically a hyperlink as shown in the program above, it contains the town name, in this case Newport, the County name, depending on which 1 is selected, it also contains a parameter called nexty, which is hard coded to =2, which should move the program on.
When you say re-submit it, should the hyperlinks be in some sort of form? As it is it just uses the values in the hyperlink and carries on.
Posted by admin (Graham Ellis), 26 July 2003Then I don't understand what you mean by "doesn't clear the hyperlinks". I thought you meant that they were repeated on the screen when you wanted to move on to the next stage. Can you explain what you mean so that I can advise? Thanks!
The hyperlinks should NOT be in a form - they include the URL and the parameters all within the HREF parameter as an alternative to a form.
Posted by Chris_Isaac (Chris Isaac), 26 July 2003Perhaps its easier if you don't mind, trying the search, if you go to the following link and do a search on newport in the town box it will generate the hyperlinks, then if you select 1 you will see what I mean:
Posted by admin (Graham Ellis), 26 July 2003Yes - that's what I thought it was at first in this thread. You've got a logic error that causes the HREF menu code to be redisplayed even when you move on to list the accommodation.
Must dash ... have heard the words "Graham - dinner's ready"
Posted by Chris_Isaac (Chris Isaac), 26 July 2003Now your talking about logic I understand:
Posted by Chris_Isaac (Chris Isaac), 27 July 2003sorry, I keep going through the program, I can't see where I've gone wrong. below is a stipit from the original program (which works, ie goes from the search page straight to the results page):
here is the new code, which doesn't clear the page:
The only difference I can see is $next is pulled from the hyperlink, rather than hard coded. I have changed this to being hardcoded to $next=2; but this still doesn't clear the hyperlinks before displaying the results.
Posted by admin (Graham Ellis), 27 July 2003Indeed - next IS pulled back from the hypertext link, but then you go into your very first test ( if ($town ...) ) whatever value is in the variable, and possibly overwrite it with the value 9.
Posted by Chris_Isaac (Chris Isaac), 27 July 2003Right, I've changed the code to below, also I'm checking the value of $next and it is definately 2. I have shortened the code as below anyway, but its not making the blind bit of difference.
Posted by admin (Graham Ellis), 27 July 2003And where's the conditional statement that skips over the code you're showing us when $next has the value 2? I haven't seen anything that does this skipping over and (judging by the fact the list comes up) that code is where the problem lies!!
Posted by Chris_Isaac (Chris Isaac), 27 July 2003I've tried the following :
I've also tried :
and also :
I've also tried substituting the relevant $next statements for things like ($next!==2) in all the above places. Ths closest I can get is the last script. It does redisplay, but only the 1st paragraph (please chose a county...) and the 1st search line (in the case of newport is Newport, County Down)
am I putting the statement in the wrong place?
Posted by admin (Graham Ellis), 28 July 2003Quote:
Perhaps you have the setting of $next in the wrong place - you only set it after you test it in the first two cases, and in the last case you set it in the loop (thus causeing the loop to go round just once).
Try moving the assignment
$next = $_GET[nexty]
to the very top of the code you've quoted to me, and use the first positioning of the test on $next.
Posted by Chris_Isaac (Chris Isaac), 28 July 2003Good news: Page now clears
Bad News: No search results are being printed!
Ever have one of those days...
I've checked the results, both the town and county, as well as $next are carried forward, and the page is reset, but no results are printed.
Can you see anything in the code that might prevent it?
As soon as I put the code the way it was it works again.
Code now reads as folows:
Posted by admin (Graham Ellis), 28 July 2003Code looks fine, but .... you're not showing us the code that's now failing .... that's the following section. I think you might be panicking slightly rather that looking hard at the code, adding in extra print statements, "dry running" the code on paper, etc - all good techniques.
Suggestion - why not take a step back from the actual detail of all the code and draw yourself a state diagram and/or a flow chart to clarify your "model" - a few boxes "on the back of a fag packet" should do the trick. Concentrate on the conditionals and the state variables and I expect the whole thing will come much clearer!
Posted by Chris_Isaac (Chris Isaac), 28 July 2003Just a quick note to say thanks.
You were of course right, there was a for loop about 6 lines down expecting a varible count of at least 1. I've now sorted it out and its all working well.
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: email@example.com • WEB: http://www.wellho.net • SKYPE: wellho