Last active
December 22, 2015 16:39
-
-
Save xymox12/6501189 to your computer and use it in GitHub Desktop.
openconf query
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT paper.title, | |
GROUP_CONCAT(CONCAT('{{', | |
author.name_first, | |
'}}{{', | |
author.name_last, | |
'}}')) | |
AS names, | |
paper.abstract, | |
topic.topicname, | |
paper.paperid | |
FROM ((oc_db.papertopic papertopic | |
INNER JOIN oc_db.topic topic ON (papertopic.topicid = topic.topicid)) | |
INNER JOIN oc_db.paper paper ON (paper.paperid = papertopic.paperid)) | |
INNER JOIN oc_db.author author ON (paper.paperid = author.paperid) | |
GROUP BY paper.title |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
header("content-type:text/xml"); | |
/* The workhorse */ | |
function getXML($sql="Default Query") { | |
$db_host = "localhost"; | |
$db_user = "xxxx"; | |
$db_pass = "xxxx"; | |
$db_name = "oc_db"; | |
$db = mysql_connect($db_host, $db_user, $db_pass); | |
if (!$db) { | |
die('Could not connect: ' . mysql_error()); | |
} | |
mysql_select_db($db_name,$db); | |
$result = mysql_query($sql, $db); | |
$columns=""; | |
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; | |
echo "<records>\n"; | |
while($row=mysql_fetch_assoc($result)) | |
{ | |
$columns.="<record>\n"; | |
foreach($row as $key => $value) | |
{ | |
$key = htmlspecialchars($key, ENT_QUOTES, 'UTF-8'); | |
$value = htmlspecialchars($value, ENT_QUOTES, 'UTF-8'); | |
$columns.="<$key>$value</$key>\n"; | |
} | |
$columns.="</record>\n"; | |
} | |
echo $columns; | |
echo "</records>\n"; | |
} | |
/* Call the fucntion */ | |
getXML("SELECT paper.title, | |
GROUP_CONCAT(CONCAT('{{', | |
author.name_first, | |
'}}{{', | |
author.name_last, | |
'}}')) | |
AS names, | |
paper.abstract, | |
topic.topicname, | |
paper.paperid | |
FROM ((oc_db.papertopic papertopic | |
INNER JOIN oc_db.topic topic ON (papertopic.topicid = topic.topicid)) | |
INNER JOIN oc_db.paper paper ON (paper.paperid = papertopic.paperid)) | |
INNER JOIN oc_db.author author ON (paper.paperid = author.paperid) | |
GROUP BY paper.title"); | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="ISO-8859-1"?> | |
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> | |
<xsl:template match="records"> | |
<html> | |
<body> | |
<h1>Papers</h1> | |
<xsl:apply-templates/> | |
</body> | |
</html> | |
</xsl:template> | |
<xsl:template match="record"> | |
<div id="{paperid}"> | |
<xsl:apply-templates select="title"/> | |
<xsl:apply-templates select="names"/> | |
<xsl:apply-templates select="topicname"/> | |
<xsl:apply-templates select="abstract"/> | |
</div> | |
</xsl:template> | |
<xsl:template match="title"> | |
<h2 class="{name()}"><xsl:value-of select="."/></h2> | |
</xsl:template> | |
<xsl:template match="names | topics | abstract"> | |
<p class="{name()}"><xsl:value-of select="."/></p> | |
</xsl:template> | |
</xsl:stylesheet> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment