I altered my php code so now I can get an array from mysql into json
using the code below. How do I get the resultant output to be in the
correct format for exhibit? I also included the resultant output of
one table row below so you can see the formatting the query currently
is in. THanks!

<? php
....login info....
$encodable = array();

mysql_connect(localhost, $username, $password);
mysql_select_db($database) or die("Unable to select database");
$result = mysql_query($sql);

while($obj = mysql_fetch_object($result))
{
$encodable[] = $obj;
}

$encoded = json_encode($encodable);

echo $encoded;

mysql_close();
?>


[{"recordID":"81","ProgramText":"University
","recordListingID":"0","uid":"matchrounder","specialty":"College","comments":"","reprtng":"0","edrtng":"0","resrtng":"0","facrtng":"0","overallrtng":"0","ranked":"0","mydate":"2009-12-07","interview":"","city":"Ann
Arbor ","state":"MI","lat":"42.277416","lng":"-83.733276"},




On Oct 3, 12:36 pm, Praveen <[email protected]> wrote:
> This is the code I have for mysql to json. Output is "null"
>
> <?php
> header('Content-type: application/json');  // this is the magic that
> sets responseJSON
>
> // Connecting, selecting database
> $link = mysql_connect(localhost, $username, $password)
>     or die('Could not connect: ' . mysql_error());
> mysql_select_db($database) or die('Could not select database');
>
> switch($_POST['op']) {
>     case 'getAllRecords': {
>         $table = $_POST['table'];
>         $query = sprintf("SELECT * FROM %s", mysql_real_escape_string
> ($table));
>         // Performing SQL query
>         $result = mysql_query($query) or die('Query failed: ' .
> mysql_error());
>         $all_recs = array();
>         while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
>             $all_recs[] = $line;
>         }
>         break;
>     }
>
> }
>
> echo json_encode($all_recs);
>
> // Free resultset
> //mysql_free_result($result);
>
> // Closing connection
> mysql_close($link);
> ?>
>
> On Oct 3, 12:08 pm, Praveen <[email protected]> wrote:
>
> > Mark,
>
> > Thanks for the example. This appears to be what I am looking for, so
> > thanks for sharing.
>
> > I looked at your json.generator.php file. This may be where I am
> > having my problem. I can't seem to figure out how to get data from
> > mysql into a json file that is in the correct formatting for exhibit
> > to understand. When I open your json.generator file it appears to be
> > in the correct formatting. What is the coding behind that file? I can
> > post the code I have been using if needed, but I am pretty sure it
> > doesn't actually do anything since the resultant output is "null".
>
> > Thanks!
>
> > On Oct 3, 10:29 am, mleden <[email protected]> wrote:
>
> > > Hi Praveen,
>
> > > If you want to see a working example of MySQL -> PHP -> JSON ->
> > > Exhibit, you can check out this example:http://www.thisbeautifulgame.com
>
> > > It's still a bit of a work in progress, but I think you'll get the
> > > idea of how to do it.  The key for me was in understanding that I can
> > > call a PHP script to generate the JSON "on the fly".  Look for the
> > > following line in the HTML source:
> > > <link href="../php/This.Beautiful.Game.Json.Generator.php"
> > > type="application/json" rel="exhibit/data" />
>
> > > HTH,
> > > -Mark
>
> > > On Oct 2, 11:43 pm, nunb <[email protected]> wrote:
>
> > > > XML is directly supported.
>
> > > >http://code.google.com/p/simile-widgets/wiki/Timeline_EventSources
>
> > > > (disclaimer: that link is directly 
> > > > fromhttp://www.simile-widgets.org/timeline/
> > > > -- there is also a link to an older doc wiki if you need it)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"SIMILE Widgets" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/simile-widgets?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to