Export MySQL to Json: Difference between revisions
Jump to navigation
Jump to search
Kaplanerkan (talk | contribs) No edit summary |
Kaplanerkan (talk | contribs) |
||
(9 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
<pre> | <pre> | ||
SET SESSION group_concat_max_len = 100000000; | SET SESSION group_concat_max_len = 100000000; // IMPORTANT | ||
SELECT | SELECT | ||
Line 11: | Line 11: | ||
AS json FROM menu ; | AS json FROM menu ; | ||
</pre> | |||
== Privat SQL only for me == | |||
<pre> | |||
// SET SESSION group_concat_max_len = 100000000; | |||
// SELECT | |||
// CONCAT("[", | |||
// GROUP_CONCAT( | |||
// CONCAT("{\"Menue\":\"",Menue,"\""), | |||
// CONCAT(",\"Text_D\":\"",Text_D,"\""), | |||
// CONCAT(",\"Beschreibung_D\":\"",Beschreibung_D,"\""), | |||
// CONCAT(",\"Sort\":\"",Sort,"\""), | |||
// CONCAT(",\"Gruppe\":\"",Gruppe,"\""), | |||
// CONCAT(",\"Preis3\":\"",Preis3,"\""), | |||
// CONCAT(",\"WarenGruppe\":\"",WarenGruppe,"\""), | |||
// CONCAT(",\"Extra\":\"",Extra,"\""), | |||
// CONCAT(",\"WGruppenText\":\"",waren_gruppen.Text,"\""), | |||
// CONCAT(",\"Sabu_Sabu\":\"",Sabu_Sabu,"\""), | |||
// CONCAT(",\"Ipad_Zeitzone\":\"",Ipad_Zeitzone,"\""), | |||
// CONCAT(",\"ShabuShabu_AH\":\"",ShabuShabu_AH,"\""), | |||
// CONCAT(",\"ShabuShabu_ALK\":\"",ShabuShabu_ALK,"\""), | |||
// CONCAT(",\"ShabuShabu_ALK_Preis\":\"",ShabuShabu_ALK_Preis,"\""), | |||
// CONCAT(",\"Text_D\":\"",Text_D),"\"}") | |||
// ,"]") | |||
// AS json FROM menu INNER JOIN waren_gruppen ON menu.WarenGruppe = waren_gruppen.Firma ; ; | |||
</pre> | |||
== Datas.json saved as Array == | |||
<pre> | |||
[ | |||
{"Menue":"1", "TextD":"Sake"}, | |||
{"Menue":"2", "TextD":"Maguro"}, | |||
{"Menue":"3", "TextD":"Mutsu"}, | |||
{"Menue":"4", "TextD":"Izumidai"}, | |||
{"Menue":"5", "TextD":"Amaebi"}, | |||
{"Menue":"6", "TextD":"Ebi"}, | |||
{"Menue":"7", "TextD":"Kanikama"}, | |||
{"Menue":"8", "TextD":"Avocado"}, | |||
{"Menue":"9", "TextD":"Tamago"} | |||
] | |||
</pre> | |||
== Parse the Result == | |||
<pre> | |||
Function Button1_onclick() | |||
$.getJSON("datas.json", gotResult) | |||
End Function | |||
Function gotResult(data) | |||
Dim speisen=[] | |||
// For i=0 To i < data.length | |||
For i=0 To 10 | |||
speisen[i]=[String(data[i].Menue),String(data[i].TextD)] | |||
Next | |||
End Function | |||
'JavaScript | |||
' var speisen=[]; | |||
' $.getJSON("datas.json", function(data) { | |||
' var i=0; | |||
' for (i=0; i<10; i++){ | |||
' speisen[i]=[String(data[i].Menue),String(data[i].TextD)]; | |||
' } | |||
' }); | |||
'End JavaScript | |||
' ANOTHER METHODS | |||
'JavaScript | |||
'$.getJSON( "datas.json", function(data) { | |||
' var items = []; | |||
' $.each( data, function( key, val ) { | |||
' items.push( "<li id='" + key + "'>" + val + "</li>" ); | |||
' }); | |||
' | |||
' $( "<ul/>", { | |||
' "class": "my-new-list", | |||
' html: items.join( "" ) | |||
' }).appendTo( "body" ); | |||
'}); | |||
' | |||
' | |||
'End JavaScript | |||
</pre> | |||
== Export whith PHP == | |||
<pre> | |||
<?php | |||
header('Access-Control-Allow-Origin: *'); | |||
mysql_connect("localhost", "root", "here_root_passwort"); | |||
mysql_select_db("databank_name"); | |||
$res = mysql_query("SELECT Menue,.................... ShabuShabu_ALK_Preis FROM menu INNER JOIN waren_gruppen ON menu.WarenGruppe = waren_gruppen.Firma ;"); | |||
$records = array(); | |||
while($obj = mysql_fetch_object($res)) { | |||
$records []= $obj; | |||
} | |||
file_put_contents("d:\\backup\data.json", json_encode($records)); | |||
?> | |||
</pre> | </pre> |
Latest revision as of 15:22, 4 October 2013
SET SESSION group_concat_max_len = 100000000; // IMPORTANT SELECT CONCAT("[", GROUP_CONCAT( CONCAT("{ \"Menue\": \" ", Menue , " \" "), CONCAT(", \"Text_D\": \" ", Text_D), " \"}") ,"]") AS json FROM menu ;
Privat SQL only for me
// SET SESSION group_concat_max_len = 100000000; // SELECT // CONCAT("[", // GROUP_CONCAT( // CONCAT("{\"Menue\":\"",Menue,"\""), // CONCAT(",\"Text_D\":\"",Text_D,"\""), // CONCAT(",\"Beschreibung_D\":\"",Beschreibung_D,"\""), // CONCAT(",\"Sort\":\"",Sort,"\""), // CONCAT(",\"Gruppe\":\"",Gruppe,"\""), // CONCAT(",\"Preis3\":\"",Preis3,"\""), // CONCAT(",\"WarenGruppe\":\"",WarenGruppe,"\""), // CONCAT(",\"Extra\":\"",Extra,"\""), // CONCAT(",\"WGruppenText\":\"",waren_gruppen.Text,"\""), // CONCAT(",\"Sabu_Sabu\":\"",Sabu_Sabu,"\""), // CONCAT(",\"Ipad_Zeitzone\":\"",Ipad_Zeitzone,"\""), // CONCAT(",\"ShabuShabu_AH\":\"",ShabuShabu_AH,"\""), // CONCAT(",\"ShabuShabu_ALK\":\"",ShabuShabu_ALK,"\""), // CONCAT(",\"ShabuShabu_ALK_Preis\":\"",ShabuShabu_ALK_Preis,"\""), // CONCAT(",\"Text_D\":\"",Text_D),"\"}") // ,"]") // AS json FROM menu INNER JOIN waren_gruppen ON menu.WarenGruppe = waren_gruppen.Firma ; ;
Datas.json saved as Array
[ {"Menue":"1", "TextD":"Sake"}, {"Menue":"2", "TextD":"Maguro"}, {"Menue":"3", "TextD":"Mutsu"}, {"Menue":"4", "TextD":"Izumidai"}, {"Menue":"5", "TextD":"Amaebi"}, {"Menue":"6", "TextD":"Ebi"}, {"Menue":"7", "TextD":"Kanikama"}, {"Menue":"8", "TextD":"Avocado"}, {"Menue":"9", "TextD":"Tamago"} ]
Parse the Result
Function Button1_onclick() $.getJSON("datas.json", gotResult) End Function Function gotResult(data) Dim speisen=[] // For i=0 To i < data.length For i=0 To 10 speisen[i]=[String(data[i].Menue),String(data[i].TextD)] Next End Function 'JavaScript ' var speisen=[]; ' $.getJSON("datas.json", function(data) { ' var i=0; ' for (i=0; i<10; i++){ ' speisen[i]=[String(data[i].Menue),String(data[i].TextD)]; ' } ' }); 'End JavaScript ' ANOTHER METHODS 'JavaScript '$.getJSON( "datas.json", function(data) { ' var items = []; ' $.each( data, function( key, val ) { ' items.push( "<li id='" + key + "'>" + val + "</li>" ); ' }); ' ' $( "<ul/>", { ' "class": "my-new-list", ' html: items.join( "" ) ' }).appendTo( "body" ); '}); ' ' 'End JavaScript
Export whith PHP
<?php header('Access-Control-Allow-Origin: *'); mysql_connect("localhost", "root", "here_root_passwort"); mysql_select_db("databank_name"); $res = mysql_query("SELECT Menue,.................... ShabuShabu_ALK_Preis FROM menu INNER JOIN waren_gruppen ON menu.WarenGruppe = waren_gruppen.Firma ;"); $records = array(); while($obj = mysql_fetch_object($res)) { $records []= $obj; } file_put_contents("d:\\backup\data.json", json_encode($records)); ?>