Location: PHPKode > projects > HypatiaDB > hypatiadb/xhr/get-data.php
<?php
//This is a generic "get data as a list" page that returns a list snippet.
//Useful for XmlHttpRequests.

include('../common_db.php');
include('../functions.php');
dbconnect($host, $username, $password);
$strings = loadStrings($lang,'GETDATA');


header("Content-Type: application/xml");

echo('<');?>?xml version="1.0" encoding="UTF-8"?>

<?php
switch($_REQUEST['action']) {
	case 'table-list':
		echo('<ul xmlns="http://www.w3.org/1999/xhtml">');
		$db = mysql_escape_string($_REQUEST['db']);
		if(mysql_select_db($db)) {
		$_SESSION['current_db'] = $db;
		$tables = mysql_query("SHOW TABLES");
		if(mysql_num_rows($tables) == 0) {
			echo("<li>$strings[GD_NOTABLES]</li>");
		} else {
			while($table = mysql_fetch_array($tables)) {
				echo("<li><a href=\"browse.php?database=$db&amp;table=$table[0]\" title=\"Browse this table\">" . htmlspecialchars($table[0]) . "</a></li>");
			}
		}
		} else {
			echo("<li>$strings[GD_PLEASESELECT]</li>");
		}
		echo('</ul>');
		break;
	case 'tl-ops':
		//table list for a select options box
		if(isset($_REQUEST['db'])) {
			$db = mysql_escape_string($_REQUEST['db']);
			$_SESSION['current_db'] = $db;
			mysql_select_db($db);
		} else {
			$db = $_SESSION['current_db'];
			mysql_select_db($db);
		}
		($tables = mysql_query("SHOW TABLES")) or die('<p xmlns="http://www.w3.org/1999/xhtml">' . $strings['GD_BADDB'] . '</p>');
		echo("<select name=\"table\" xmlns=\"http://www.w3.org/1999/xhtml\">");
		while($table = mysql_fetch_array($tables)) {
			echo("<option value=\"$table[0]\">$table[0]</option>");
		}
		echo('</select>');
		break;
	case 'get-row':
		echo('<div xmlns="http://www.w3.org/1999/xhtml">');
		if(isset($_REQUEST['db'])) {
			$db = mysql_escape_string($_REQUEST['db']);
			$_SESSION['current_db'] = $db;
			mysql_select_db($db);
		} else {
			$db = $_SESSION['current_db'];
			mysql_select_db($db);
		}
		$table = $_REQUEST['tbl'];		//table
		$pk = $_REQUEST['pk'];			//the primary key
		$rowid = mysql_real_escape_string($_REQUEST['rowid']);		//the value of the primary key
		$field = $_REQUEST['field'];		//field to get
		$query = "SELECT $field FROM $table WHERE $pf = $rowid";
		echo(mysql_result(mysql_query($query), 0, 0));

		echo('</div>');
	default:
		//something bad happened
		echo('<p xmlns="http://www.w3.org/1999/xhtml">' . $strings['GD_UNKNOWNOP'] . '</p>');
		break;
}

?>
Return current item: HypatiaDB