Cities Example Code:
<?php
try {
/*** connect to SQLite database ***/
$dbh = new PDO('sqlite:../data/cities.db');
$city_id = $_GET['city'];
if (!$city_id) { $city_id = 1; }
$sql = "select * from city where parent_id=$city_id and id>1 order by arabic";
echo '<form action="City.php" method="get" name="frm"><p align="center">';
echo "Selected Node ID: $city_id <br /><br />";
$sth = $dbh->prepare("select * from city where id=$city_id");
$sth->execute();
$result = $sth->fetch(PDO::FETCH_ASSOC);
echo $result['arabic'] . ' / ' . $result['english'] . '<br />';
if (!empty($result['latitude'])) {
echo 'Latitude: ' . $result['latitude'];
echo ', Longitude: ' . $result['longitude'];
}
echo '<br /><br /><select name="city" dir="rtl" onChange="document.frm.submit()">';
echo '<option>- إختر رجاء -</option>';
/*
* You will have noticed that we can iterate over the result set directly
* with foreach. This is because internally the PDO statement implements
* the SPL traversble iterator, thus giving all the benifits of using SPL.
*
* The greatest benifit of this is that SPL iterators know only one element
* at a time and thus large result sets become manageable without hogging
* memory.
*/
foreach ($dbh->query($sql) as $row) {
echo '<option value="' . $row['id'] . '">';
if ($row['arabic'] == '') {
$title = $row['english'];
} else {
$title = $row['arabic'];
}
echo "$title</option>\n";
}
echo '</select> ';
echo '<input type="button" onclick="window.location=\'City.php\';"
value="قم باختيار جديد" /></form></p>';
// Close the databse connection
$dbh = null;
} catch(PDOException $e) {
echo $e->getMessage();
}
Total execution time is 0.0046360492706299 seconds
Amount of memory allocated to this script is 380288 bytes
Names of included or required files:
- /var/www/vhosts/ar-php.org/httpdocs/I18N/Arabic/Examples/City.php