<?xml version="1.0" encoding="ISO-8859-1"?>

<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
	<channel>
		<title>Red Fox UK Limited Community Forums - Development Support</title>
		<link>http://forums.redfoxuk.com/</link>
		<description>Need to find out how to connect to a database in ASP, or simply cannot get that JavaScript to work? Help is at hand in this forum!</description>
		<language>en</language>
		<lastBuildDate>Tue, 07 Sep 2010 05:43:40 GMT</lastBuildDate>
		<generator>vBulletin</generator>
		<ttl>60</ttl>
		<image>
			<url>http://forums.redfoxuk.com/images/misc/rss.png</url>
			<title>Red Fox UK Limited Community Forums - Development Support</title>
			<link>http://forums.redfoxuk.com/</link>
		</image>
		<item>
			<title>using json to pull database into html pages.</title>
			<link>http://forums.redfoxuk.com/threads/6205-using-json-to-pull-database-into-html-pages.?goto=newpost</link>
			<pubDate>Sat, 14 Aug 2010 11:53:28 GMT</pubDate>
			<description>Im trying to build an app for iPhone which I can package up with phone gap. I know how to do the basic structure but im trying to get my html/javascript pages to connect to a database. Im doing this through json. 
  
  
basically I have a php page which pulls fields from the database: 
 
PHP:...</description>
			<content:encoded><![CDATA[<div>Im trying to build an app for iPhone which I can package up with phone gap. I know how to do the basic structure but im trying to get my html/javascript pages to connect to a database. Im doing this through json.<br />
 <br />
 <br />
basically I have a php page which pulls fields from the database:<br />
<div class="bbcode_container">
	<div class="bbcode_description">PHP Code:</div>
	<hr /><code class="bbcode_code"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;Database&nbsp;credentials<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$host&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'xx'</span><span style="color: #007700">;&nbsp;<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$db&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'xx'</span><span style="color: #007700">;&nbsp;<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$uid&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'xx'</span><span style="color: #007700">;&nbsp;<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$pwd&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'xx'</span><span style="color: #007700">;<br />&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;Connect&nbsp;to&nbsp;the&nbsp;database&nbsp;server&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$link&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mysql_connect</span><span style="color: #007700">(</span><span style="color: #0000BB">$host</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$uid</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$pwd</span><span style="color: #007700">)&nbsp;or&nbsp;die(</span><span style="color: #DD0000">"Could&nbsp;not&nbsp;connect"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//select&nbsp;the&nbsp;json&nbsp;database<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">mysql_select_db</span><span style="color: #007700">(</span><span style="color: #0000BB">$db</span><span style="color: #007700">)&nbsp;or&nbsp;die(</span><span style="color: #DD0000">"Could&nbsp;not&nbsp;select&nbsp;database"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;Create&nbsp;an&nbsp;array&nbsp;to&nbsp;hold&nbsp;our&nbsp;results<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$arr&nbsp;</span><span style="color: #007700">=&nbsp;array();<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//Execute&nbsp;the&nbsp;query<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$rs&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mysql_query</span><span style="color: #007700">(</span><span style="color: #DD0000">"SELECT&nbsp;id,userid,firstname,lastname,email&nbsp;FROM&nbsp;users"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;Add&nbsp;the&nbsp;rows&nbsp;to&nbsp;the&nbsp;array&nbsp;<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">while(</span><span style="color: #0000BB">$obj&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mysql_fetch_object</span><span style="color: #007700">(</span><span style="color: #0000BB">$rs</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$arr</span><span style="color: #007700">&#91;&#93;&nbsp;=&nbsp;</span><span style="color: #0000BB">$obj</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//return&nbsp;the&nbsp;json&nbsp;result.&nbsp;The&nbsp;string&nbsp;users&nbsp;is&nbsp;just&nbsp;a&nbsp;name&nbsp;for&nbsp;the&nbsp;container&nbsp;object.&nbsp;Can&nbsp;be&nbsp;set&nbsp;anything.<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">'('</span><span style="color: #007700">.</span><span style="color: #0000BB">json_encode</span><span style="color: #007700">(</span><span style="color: #0000BB">$arr</span><span style="color: #007700">).</span><span style="color: #DD0000">');'</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">?&gt;</span>
</span>
</code></code><hr />
</div> If you view the page it gives you the json query: <a href="http://www.garethmoore.net/jq.php" target="_blank">http://www.garethmoore.net/jq.php</a><br />
([{&quot;id&quot;:&quot;1&quot;,&quot;userid&quot;:&quot;fhardy&quot;,&quot;firstname&quot;:&quot;Frank&quot;,&quot;l  astname&quot;:&quot;Hardy&quot;,&quot;email&quot;:&quot;fhardy@hauntedclock.com&quot;},{&quot;id&quot;:&quot;2&quot;,&quot;userid&quot;:&quot;jhar  dy&quot;,&quot;firstname&quot;:&quot;Joe&quot;,&quot;lastname&quot;:&quot;Hardy&quot;,&quot;email&quot;:&quot;  jhardy@hauntedclock.com&quot;},{&quot;id&quot;:&quot;3&quot;,&quot;userid&quot;:&quot;ndre  w&quot;,&quot;firstname&quot;:&quot;Nancy&quot;,&quot;lastname&quot;:&quot;Drew&quot;,&quot;email&quot;:&quot;  ndrew@hauntedclock.com&quot;},{&quot;id&quot;:&quot;4&quot;,&quot;userid&quot;:&quot;sdoo&quot;  ,&quot;firstname&quot;:&quot;Scooby&quot;,&quot;lastname&quot;:&quot;Doo&quot;,&quot;email&quot;:&quot;sd  oo@mysterymachine.com&quot;}]);<br />
<br />
Then I have my HTML page (which is just stored on my loacl hard drive. This is the HTML/Javascript code:<br />
[HTML]<br />
&lt;html&gt;<br />
&lt;head&gt;<br />
 <br />
&lt;script type=&quot;text/javascript&quot; src=&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.js&quot;&gt;&lt;/script&gt;<br />
<br />
   &lt;script type=&quot;text/javascript&quot;&gt;<br />
$(document).ready(function(){<br />
 $.getJSON('http://www.garethmoore.net/jq.php?count=20&amp;callback=?', function(data){<br />
  $.each(data, function(index, item){<br />
   $('#twitter').append('&lt;div class=&quot;tweet&quot;&gt;&lt;p&gt;' + item.email + '&lt;/p&gt;&lt;/div&gt;');<br />
  });<br />
 <br />
 });<br />
 <br />
 });<br />
&lt;/script&gt;<br />
 <br />
&lt;/head&gt;<br />
<br />
&lt;body&gt;<br />
  &lt;div id=&quot;twitter&quot; &gt;<br />
   <br />
  &lt;/div&gt;<br />
 <br />
&lt;/body&gt;<br />
&lt;/html&gt;<br />
[/HTML]<br />
<br />
Ive pretty much taken the HTML/javascript from a Twitter feed that ive used loads before and it works. But for some reason, even though the code is the same, and the json output is the same (as the twitter output) this just doesnt seem to work.</div>

 ]]></content:encoded>
			<category domain="http://forums.redfoxuk.com/forums/8-Development-Support">Development Support</category>
			<dc:creator>Space Cowboy</dc:creator>
			<guid isPermaLink="true">http://forums.redfoxuk.com/threads/6205-using-json-to-pull-database-into-html-pages.</guid>
		</item>
	</channel>
</rss>
