// Chart Search version 1
//
// Peter T Garner.
// Uses PHP and MySQL.
// This works fine on my Mitsubishi Trium. YMMV.
// I developed this on the Linux version of the
// deckit emulator from www.pyweb.com.
//
// This is the first deck that prompts you for
// a chart (table), then a (book) Isbn to search for.
//
// N.B ******************
// The decks detailed below serve to illustrate
// how WML can be combined with PHP and MySQL to
// enable WAP-enabled devices to select and display
// data from a multi-table database. I used book chart
// data from my employer, Whitaker BookTrack (see
// http://www.booktrack.co.uk) as part of a pilot project.
// Currently, there is no WAP based service from Whitaker
// BookTrack, but this may change in the near future. Please
// contact me at peterg@teleord.co.uk for more information.
<!-- We only want digits 1-9 of the Isbn as it will be
unique in the database without the check digit. If
we assume a match for the Isbn, the check digit will
be added when the result is returned.
Note the 2 postfield statements that will pass on the 2
variables that we collect on the way. We need to post
them now as we are going to leave this deck after we
enter the ISBN -->
// Once you have selected your database table and entered
// your search string, this deck is then accessed (c2b.wml).
// It uses a simple MySQL database called "Charts" and the
// tables are named according to the week they relate to.
// Please note that this script doesn't do any checking for
// length of output. If it's over the limit you will probably
// get a 'malformed http' message or something similar. This
// will be tidied up in the next version..
<card id="card2" title="Result">
<p>
<?php
if ( !empty($Isbn) )
{
if ( $DBcon = mysql_connect("localhost", "","") )
{
mysql_select_db("chart");
$query = "select ISBN, cPosition, Author, Title, ";
$query .= " RRP, ASP, WeeksIn, PrevPos, Imprint from ";
$query .= $myChart;
$query .= " where ISBN like '$Isbn%'";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
if ( $row )
{
//
// we need to change any ampersands to '+'
//
$TI = strtr($row[Title], "&", "+");
$AU = strtr($row[Author], "&", "+");
//
// sometimes, an author is not listed on the database
//
if ( empty($row[Author])) { $AU = "unknown"; }
//
// we need to change any ampersands to '+'
//
$AU = explode (",", $AU);
$PU = strtr($row[Imprint], "&", "+");
//
// now we will display our result.. We swap the first
// and last names of the author to produce a user-friendly
// display.
//
echo "Isbn $row[ISBN] is '$TI' by '$AU[1] $AU[0]' with an ";
echo "RRP of #$row[RRP]. ";
echo "Currently it is at number $row[cPosition]. ";
//
// A more user-friendly display of new entries..
//
if ( $row[WeeksIn] == '0' )
{
echo "This is a new entry in the charts. ";
}
else
{
echo "It has been in the charts for ";
echo "$row[WeeksIn] ";
echo "weeks. ";
echo "Last week it was at number ";
echo "$row[PrevPos]. ";
}
// Say who publishes it ..
echo "It is published by $PU. ";
echo "The typical street price is #$row[ASP]";
//
// And show a disclaimer along with the tablename
// that we used..
//
echo "<br/><br/><small>(C) BookTrack " . date('Y') . "<br/>E&OE</small>";
echo "<br/><small>$myChart</small>";
}
else
{
echo "Sorry<br/>No match for $Isbn";
}
mysql_close($DBcon);
}
}
else
{
echo "You can't have an empty ISBN";
}
?>
<br/>
</p>
</card>
</wml>