<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Research: Math, Computing and MRI &#187; PHP</title>
	<atom:link href="http://mri.brechmos.org/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://mri.brechmos.org</link>
	<description>by Craig Jones</description>
	<lastBuildDate>Wed, 10 Aug 2011 16:53:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Show SQL table output using PHP</title>
		<link>http://mri.brechmos.org/2010/01/show-sql-table-output-using-php/</link>
		<comments>http://mri.brechmos.org/2010/01/show-sql-table-output-using-php/#comments</comments>
		<pubDate>Sat, 09 Jan 2010 02:21:27 +0000</pubDate>
		<dc:creator>craig</dc:creator>
				<category><![CDATA[Computing]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://mri.brechmos.org/?p=29</guid>
		<description><![CDATA[I found this code on the internet. This is a nice bit of code to show an arbitrary table with headers and all the entries. There is probably lots more one could do with it, but it works well for &#8230; <a href="http://mri.brechmos.org/2010/01/show-sql-table-output-using-php/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I <a title="http://forum.siteground.com/archive/index.php/t-12434.html" rel="nofollow" href="http://forum.siteground.com/archive/index.php/t-12434.html"> found</a> this code on the internet. This is a nice bit of code to show an arbitrary table with headers and all the entries. There is probably lots more one could do with it, but it works well for general testing and is completely independent of what is in the table.</p>
<p>[cc lang="php"]<br />
function display($table)<br />
{<br />
	$db_host = &#8216;localhost&#8217;;<br />
	$db_user = &#8216;<userid here>&#8216;;<br />
	$db_pwd = &#8216;
<password here>&#8216;;<br />
 <br />
	$database = &#8216;<sql database here>&#8216;;<br />
 <br />
	if (!mysql_connect($db_host, $db_user, $db_pwd))<br />
	    die(&#8220;Can&#8217;t connect to database&#8221;);<br />
 <br />
	if (!mysql_select_db($database))  ||  die(&#8220;Can&#8217;t select database&#8221;);<br />
 <br />
	// sending query<br />
	$result = mysql_query(&#8220;SELECT * FROM {$table}&#8221;);<br />
	if (!$result) {<br />
	    die(&#8220;Query to show fields from table failed&#8221;);<br />
	}<br />
 <br />
	$fields_num = mysql_num_fields($result);<br />
 <br />
	echo &#8220;<br />
<h1>;Table: {$table}</h1>
<p>&#8220;;<br />
	echo &#8220;<br />
<table border='1'>
<tr>&#8220;;<br />
	// printing table headers<br />
	for($i=0; $i<$fields_num; $i++)<br />
	{<br />
	    $field = mysql_fetch_field($result);<br />
	    echo "
<td>{$field->name}</td>
<p>&#8220;;<br />
	}<br />
	echo &#8220;</tr>
<p>\n&#8221;;<br />
	// printing table rows<br />
	while($row = mysql_fetch_row($result))<br />
	{<br />
	    echo &#8220;<br />
<tr>&#8220;;<br />
 <br />
	    // $row is array&#8230; foreach( .. ) puts every element<br />
	    // of $row to $cell variable<br />
	    foreach($row as $cell)<br />
		echo &#8220;
<td>$cell</td>
<p>&#8220;;<br />
 <br />
	    echo &#8220;</tr>
<p>\n&#8221;;<br />
	}<br />
        echo &#8220;</table>
<p>&#8220;;<br />
	mysql_free_result($result);<br />
}<br />
[/cc]</p>
]]></content:encoded>
			<wfw:commentRss>http://mri.brechmos.org/2010/01/show-sql-table-output-using-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

