Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
Clearing/resetting a page

Posted by Chris_Isaac (Chris Isaac), 26 July 2003
Hi

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?

Thanks

Chris

Code:
for ($n=0; $n<count($estname);$n=$n+2) {
                 
                 $x=$n+1;
                 print "<a href=\"http://www.limited.org.uk/finder.php4?nexty=2&name=$estname[$n]&town=$estname[$x]\">Name: $estname[$n]  -- Town : $estname[$x]</a>";
                 print"<br>";
                 $next=$_GET[nexty];
     }



Posted by admin (Graham Ellis), 26 July 2003
Chris,  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 2003
I'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.

Thanks

Chris

Posted by admin (Graham Ellis), 26 July 2003
Then 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 2003
Perhaps 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:

http://www.limited.org.uk/finder.php4

Thanks

Chris

Posted by admin (Graham Ellis), 26 July 2003
Yes - 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 2003
Now your talking about logic I understand:

if($dinner==ready){
        GO EAT!;
       
    }



Posted by Chris_Isaac (Chris Isaac), 27 July 2003
sorry, 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):

Code:
     if ($town) {
           $searches = array("^$town");
           $reports = array("$town");
           $next = 2;
           }

if ($next == 2) {

     sql_connect();

blah blah... prints results



here is the new code, which doesn't clear the page:

Code:
     if ($town) {
           $searches = array("^$town");
           $reports = array("$town");            
           $county=array();
           sql_connect();
           $sql="select town, county from locations where town rlike \"$town\"";
           $query=mysql_query($sql);
           while ($row=mysql_fetch_array($query)){
                 array_push($county,$row[0],$row[1]);
           }
           $next = 9;
}

if ($next==9) {                  
     print "Please choose the county associated with the town<br>";
     print "or try another search<br><br>";

for ($n=0; $n<count($county);$n=$n+2) {
                 
                 $x=$n+1;
                 print "<a href=\"http://www.limited.org.uk/finder.php4?nexty=2&town=$county[$n]&county=$county[$x]\">Town: $county[$n]  -- County : $county[$x]</a>";
                 print"<br>";
                 $next=$_GET[nexty];
     }
}

if ($next==2) {

 blah blah prints results......



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.

Any thoughts?

Thanks

Chris

Posted by admin (Graham Ellis), 27 July 2003
Indeed - 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 2003
Right, 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.

help.... please....

Chris

Code:
     if ($town) {
           $searches = array("^$town");
           $reports = array("$town");            
           $county=array();
           sql_connect();
           $sql="select town, county from locations where town rlike \"$town\"";
           $query=mysql_query($sql);
           while ($row=mysql_fetch_array($query)){
                 array_push($county,$row[0],$row[1]);
           }
     print "Please choose the county associated with the town<br>";
     print "or try another search<br><br>";
for ($n=0; $n<count($county);$n=$n+2) {
                 $x=$n+1;
                 print "<a href=\" http://www.limited.org.uk/finder.php4?nexty=2&town=$county[$n]&county=$county[$x]\">Town: $county[$n]  -- County : $county[$x] ---$next</a>";
                 print"<br>";
                 $next=$_GET[nexty];
           }
}



Posted by admin (Graham Ellis), 27 July 2003
And 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 2003
I've tried the following :

Code:
     if ($town) {
           if($next<2){
           $searches = array("^$town");
           $reports = array("$town");            
           $county=array();
           sql_connect();
           $sql="select town, county from locations where town rlike \"$town\"";
           $query=mysql_query($sql);
           while ($row=mysql_fetch_array($query)){
                 array_push($county,$row[0],$row[1]);
           }

     print "Please choose the county associated with the town<br>";
     print "or try another search<br><br>";
for ($n=0; $n<count($county);$n=$n+2) {
                 $x=$n+1;
                 print "<a href=\" http://www.limited.org.uk/finder.php4?nexty=2&town=$county[$n]&county=$county[$x]\">Town: $county[$n]  -- County : $county[$x] ---$next</a>";
                 print"<br>";
                 $next=$_GET[nexty];
           }}
}


I've also tried :

Code:
     if ($town) {
           $searches = array("^$town");
           $reports = array("$town");            
           $county=array();
           sql_connect();
           $sql="select town, county from locations where town rlike \"$town\"";
           $query=mysql_query($sql);
           while ($row=mysql_fetch_array($query)){
                 array_push($county,$row[0],$row[1]);
           }
if($next<2){

     print "Please choose the county associated with the town<br>";
     print "or try another search<br><br>";
for ($n=0; $n<count($county);$n=$n+2) {
                 $x=$n+1;
                 print "<a href=\" http://www.limited.org.uk/finder.php4?nexty=2&town=$county[$n]&county=$county[$x]\">Town: $county[$n]  -- County : $county[$x] ---$next</a>";
                 print"<br>";
                 $next=$_GET[nexty];
           }}
}


and also :

Code:
     if ($town) {
           $searches = array("^$town");
           $reports = array("$town");            
           $county=array();
           sql_connect();
           $sql="select town, county from locations where town rlike \"$town\"";
           $query=mysql_query($sql);
           while ($row=mysql_fetch_array($query)){
                 array_push($county,$row[0],$row[1]);
           }

     print "Please choose the county associated with the town<br>";
     print "or try another search<br><br>";
for ($n=0; $n<count($county);$n=$n+2) {
                 $x=$n+1;

if($next<2){
                 print "<a href=\" http://www.limited.org.uk/finder.php4?nexty=2&town=$county[$n]&county=$county[$x]\">Town: $county[$n]  -- County : $county[$x] ---$next</a>";
                 print"<br>";
                 $next=$_GET[nexty];
           }}
}


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?

Chris

Posted by admin (Graham Ellis), 28 July 2003
Quote:
am I putting the statement in the wrong place?


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 2003
Good 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.

Chris

Code now reads as folows:  

Code:
if ($town) {
     $next=$_GET[nexty];

     if($next<2){

           $searches = array("^$town");
           $reports = array("$town");            
           $county=array();
           sql_connect();
           $sql="select town, county from locations where town rlike \"$town\"";
           $query=mysql_query($sql);
           while ($row=mysql_fetch_array($query)){
                 array_push($county,$row[0],$row[1]);
           }
     print "Please choose the county associated with the town<br>";
     print "or try another search<br><br>";
for ($n=0; $n<count($county);$n=$n+2) {
                 $x=$n+1;
                 print "<a href=\" http://www.limited.org.uk/finder.php4?nexty=2&town=$county[$n]&county=$county[$x]\">Town: $county[$n]  -- County : $county[$x] ---$next</a>";
                 print"<br>";
           }}
}





Posted by admin (Graham Ellis), 28 July 2003
Code 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 2003
Just 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.

Thanks
Again.

Chris  



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho