PHP City Guess Country Game Data Extension Tutorial

PHP City Guess Country Game Data Extension Tutorial

PHP City Guess Country Game Data Extension Tutorial

We had occasion to revisit the “City Guess Country Game” web application of PHP City Guess Country Game Sharing Tutorial and were dismayed at the absence of “Belgium” on the country list. We looked into the workings of the web application and found that it based its City and Country dropdowns based on the contents of Webservices XML files (who we would like to thank profusely).

How to start seeing Belgium, even though we write this on a Wednesday? We think we could either …

  • start accessing the Webservices Belgium XML file (but, sadly, if you’ve tried that last link, you can see why not) … or …
  • “data extend” (not talk about file extensions) the Capitals and Countries data sets of Country via Capital Placeholder Quiz Game Tutorial and that way, guarantee at least one city entry per country

… and yes, we opted for the latter. And yes, we recognize there will be a lopsided number of cities linking to the XML data countries. True enough, but playing the quiz, this does not detract from the interest of the quiz in our opinion. And it feels that much more interesting and challenging seeing a full list of country (answer) options for any city (question) ask, in our opinion.

But the proof is in the “user pudding” and perhaps you will find the changed city_guess.php City Guess Country game more or less challenging than the one lacking Belgium (perhaps because it’s Wednesday?)


Previous relevant PHP City Guess Country Game Sharing Tutorial is shown below.

PHP City Guess Country Game Sharing Tutorial

PHP City Guess Country Game Sharing Tutorial

We mentioned how much thought was needed for our revamped Nimh game to involve an Inline HTML Form Email, and thereby be spurning any Javascript “smarts” already involved, so as to both …

  • collaborate and share and involve more than one game player … as well as …
  • seeing the graphics of that game there in the body section of the email

… and so, rather than jumping straight into Nimh (ouch! … got burnt!) we are picking …

  • a simple PHP game …
  • currently involving lots of Javascript “smarts” in its workings …

  • not yet involving any Inline HTML Form Email functionality

… and work towards collaborating and sharing via those means. The verdict? Yes, even for “small games” like the changed city_guess.php City Guess Country game (you can read the background to, with PHP City Guess Country Game Primer Tutorial), it is no doddle to think “no Javascript”. It is an exercise that helps you appreciate the power and usefulness of client-side Javascript in web applications. The upside is an improvement of your appreciation of how to pare something down to those smaller “navigatable” HTML form snippets to break a concept into collaborative and sharable parts.

Two new HTML form elements become involved, to make this happen …

  1. the HTML form method=POST action=’//www.rjmprogramming.com.au/HTMLCSS/emailhtml.php’ … to navigate to Inline HTML Form Email creating PHP helper web application …

    <form target=iemail style=display:none; action='//www.rjmprogramming.com.au/HTMLCSS/emailhtml.php' method=POST>
    <input type=hidden name=inline value=''></input>
    <input type=hidden name=emailto id=emailto value=''></input>
    <input type=hidden name=subject id=subject value='City Guess Country Game'></input>
    <textarea style=display:none; name=htmlis id=htmlis value=''></textarea>
    <input type=submit style=display:none; id=contact value=Email></input>
    </form>

    … filling in emailto (Email To) and htmlis (Inline HTML Form Email content) in a named HTML iframe element, so as not to have to navigate away from the web page …

    <iframe name=iemail src=//www.rjmprogramming.com.au/HTMLCSS/emailhtml.php style=display:none;></iframe>
  2. the HTML form method=GET action=’https://www.rjmprogramming.com.au/Games/CityGuessCountry/city_guess.php’ shell …

    <form target=_top id=cgcform action='https://www.rjmprogramming.com.au/Games/CityGuessCountry/city_guess.php' method=GET>
    </form>

    … encasing existant HTML City and Country elements

… and on returning to “web browser land” from “email client land” the emailee’s answers contribute to the PHP logic …


$egoes="0";
$escore="0";
$emdef="";

if (isset($_GET['thiscity']) && isset($_GET['ucountry']) && isset($_GET['eanswer'])) {
if ($_GET['ucountry'] == $_GET['eanswer']) {
$egoes="1 Well done! " . str_replace("+"," ",urldecode($_GET['thiscity'])) . " is indeed in " . str_replace("+"," ",urldecode($_GET['eanswer'])) . ".";
$escore="1";
} else {
$egoes="1 Sorry, <a title='Google image search' style=cursor:pointer;text-decoration:underline; onclick=woit(this.innerHTML);>" . str_replace("+"," ",urldecode($_GET['thiscity'])) . "</a> is in " . str_replace("+"," ",urldecode($_GET['eanswer'])) . " but is not in " . str_replace("+"," ",urldecode($_GET['ucountry'])) . ".";
}
if (isset($_GET['emailfrom'])) {
$emdef=str_replace("+"," ",urldecode($_GET['emailfrom']));
}
}

… informing of the user of the “Check” (submit button) of their email dropdown selected Country answer for the City presented to them.

We found that second method=GET was the means by which macOS Mail app and Webmail means of emailing were both supported.


Previous relevant PHP City Guess Country Game Primer Tutorial is shown below.

PHP City Guess Country Game Primer Tutorial

PHP City Guess Country Game Primer Tutorial

There is no end to the variety of web applications you can do by seeing what free information is out there, but please don’t disrepect the sources of that information. The source for our information today is the excellent XML files created at Webservices … so … thanks.

Today’s game is deceptively simple but quite dynamic, in the sense that we set aside a web server directory for our game today that we have called “City Guess Country Game” and whatever subset of XML files you have from //www.webservicex.net/new/Home/Index are dynamically read to be the source of information. Here, for the next level up of dynamism you’d involve an RSS feed perhaps, but, today, we just talk about using what we statically have “plonked” in our directory set aside for the game. The word “plonked” always makes me associate with the ever useful PHP method called glob … yes … glob … and so it is here, because that “globbing” definitely goes on. What you will perhaps be disappointed with today is that we don’t use PHP XML native functionality to process the XML data, and please know we recommend trying these approaches as you see fit, but we find the PHP explode method relatively easy to deploy for scenarios like this where the data form is so predictable, and simple.

Deceptively simple games can sometimes be the best, and find that that interest, or not, relates to what we are interested in ourselves … for me that, in particular, is atlases, geography, the “where” of life … so today’s game interests me as much as it will bore others (no doubt).

We show you PHP source code you could call city_guess.php and a live run link as well.

If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.

This entry was posted in eLearning, Event-Driven Programming, Tutorials and tagged , , , , , , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>