Store an array to WordPress databaseHow does database indexing work?How do I check if an array includes an object in JavaScript?How to append something to an array?Deleting an element from an array in PHPHow to insert an item into an array at a specific index (JavaScript)?Storing Objects in HTML5 localStorageLoop through an array in JavaScriptHow to check if an object is an array?How do I remove a particular element from an array in JavaScript?For-each over an array in JavaScript?

Can you cast a blanket Invisibility and let the targets see each other?

What happens to unproductive professors?

Is it OK to leave real names & info visible in business card portfolio?

How do you move up one folder in Finder?

Extract string from each line of a file

Why is the ladder of the LM always in the dark side of the LM?

Is there any word for "disobedience to God"?

Why did Harry Potter get a bedroom?

Has anyone in space seen or photographed a simple laser pointer from Earth?

Switching interface VLAN ID Mid-Production

Is "De qui parles-tu" (for example) as formal as it is in English, or is it normal for the French to casually say that

How can I effectively communicate to recruiters that a phone call is not possible?

How were Martello towers supposed to work?

Which star / galaxy is moving away from us the fastest?

Indesign - how to change the style of the page numbers?

How do we handle pauses in a dialogue?

Why would non-kinetic weapons be used for orbital bombardment?

Shortest hex dumping program

What is the measurable difference between dry basil and fresh?

What does the phrase "head down the rat's hole" mean here?

What were the main German words for a prostitute before 1800?

Single word for "refusing to move to next activity unless present one is completed."

Is there any reason why MCU changed the Snap to Blip

Are there any balance issues in allowing two half-feats to be taken without the Ability Score Increase instead of a feat?



Store an array to WordPress database


How does database indexing work?How do I check if an array includes an object in JavaScript?How to append something to an array?Deleting an element from an array in PHPHow to insert an item into an array at a specific index (JavaScript)?Storing Objects in HTML5 localStorageLoop through an array in JavaScriptHow to check if an object is an array?How do I remove a particular element from an array in JavaScript?For-each over an array in JavaScript?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I created an application that's hosted in a WordPress website that allows everything on the page to be customized. How can I store an array with a user-defined ID to the WordPress database when the user clicks Save? The user can then go to their "Customized Pages" page and view all of their customized pages named as the ID they set when initially saving. On clicking on one of their customized pages, it will load the customizable page with the array associated to the ID that they set.



Edit



Gone with the JSON Encode method. Here is where i am at.



var array = [];

$('img').click(function()
var id = $(this).attr('id');
array.push(id);

);

$('#sendQuote').click(function(e)
e.preventDefault();

$.ajax(
url:"readJson.php",
method: "post",
data: myBuild: JSON.stringify( array ) ,
success: function(res)
console.log(res);

)
);


ReadJson.php



$array = $_POST['myBuild'];
print_r($array);

global $wpdb;


Any ideas in posting this to wp_meta or a custom table?










share|improve this question
























  • Author Meta or options table should be fine. Custom tables have other advantages and I've used them a lot. Just figure out what works best for you.

    – Jordan Cauley
    Apr 4 at 12:04

















1















I created an application that's hosted in a WordPress website that allows everything on the page to be customized. How can I store an array with a user-defined ID to the WordPress database when the user clicks Save? The user can then go to their "Customized Pages" page and view all of their customized pages named as the ID they set when initially saving. On clicking on one of their customized pages, it will load the customizable page with the array associated to the ID that they set.



Edit



Gone with the JSON Encode method. Here is where i am at.



var array = [];

$('img').click(function()
var id = $(this).attr('id');
array.push(id);

);

$('#sendQuote').click(function(e)
e.preventDefault();

$.ajax(
url:"readJson.php",
method: "post",
data: myBuild: JSON.stringify( array ) ,
success: function(res)
console.log(res);

)
);


ReadJson.php



$array = $_POST['myBuild'];
print_r($array);

global $wpdb;


Any ideas in posting this to wp_meta or a custom table?










share|improve this question
























  • Author Meta or options table should be fine. Custom tables have other advantages and I've used them a lot. Just figure out what works best for you.

    – Jordan Cauley
    Apr 4 at 12:04













1












1








1


1






I created an application that's hosted in a WordPress website that allows everything on the page to be customized. How can I store an array with a user-defined ID to the WordPress database when the user clicks Save? The user can then go to their "Customized Pages" page and view all of their customized pages named as the ID they set when initially saving. On clicking on one of their customized pages, it will load the customizable page with the array associated to the ID that they set.



Edit



Gone with the JSON Encode method. Here is where i am at.



var array = [];

$('img').click(function()
var id = $(this).attr('id');
array.push(id);

);

$('#sendQuote').click(function(e)
e.preventDefault();

$.ajax(
url:"readJson.php",
method: "post",
data: myBuild: JSON.stringify( array ) ,
success: function(res)
console.log(res);

)
);


ReadJson.php



$array = $_POST['myBuild'];
print_r($array);

global $wpdb;


Any ideas in posting this to wp_meta or a custom table?










share|improve this question
















I created an application that's hosted in a WordPress website that allows everything on the page to be customized. How can I store an array with a user-defined ID to the WordPress database when the user clicks Save? The user can then go to their "Customized Pages" page and view all of their customized pages named as the ID they set when initially saving. On clicking on one of their customized pages, it will load the customizable page with the array associated to the ID that they set.



Edit



Gone with the JSON Encode method. Here is where i am at.



var array = [];

$('img').click(function()
var id = $(this).attr('id');
array.push(id);

);

$('#sendQuote').click(function(e)
e.preventDefault();

$.ajax(
url:"readJson.php",
method: "post",
data: myBuild: JSON.stringify( array ) ,
success: function(res)
console.log(res);

)
);


ReadJson.php



$array = $_POST['myBuild'];
print_r($array);

global $wpdb;


Any ideas in posting this to wp_meta or a custom table?







javascript php sql wordpress






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 26 at 19:26







Luke

















asked Mar 25 at 23:08









LukeLuke

86 bronze badges




86 bronze badges












  • Author Meta or options table should be fine. Custom tables have other advantages and I've used them a lot. Just figure out what works best for you.

    – Jordan Cauley
    Apr 4 at 12:04

















  • Author Meta or options table should be fine. Custom tables have other advantages and I've used them a lot. Just figure out what works best for you.

    – Jordan Cauley
    Apr 4 at 12:04
















Author Meta or options table should be fine. Custom tables have other advantages and I've used them a lot. Just figure out what works best for you.

– Jordan Cauley
Apr 4 at 12:04





Author Meta or options table should be fine. Custom tables have other advantages and I've used them a lot. Just figure out what works best for you.

– Jordan Cauley
Apr 4 at 12:04












1 Answer
1






active

oldest

votes


















0














You have 2 options.



Encode the array as json using json_encode and then decode it for use using json_decode



Serialize the array via serialize and unserialize via unserialize






share|improve this answer























  • Doing that would make it impossible to query for certain items in the array. Sure you could pull everything out and then filter but its not as efficient. Also those aren't the only options... probably the most accepted way is to store each item in its own table.

    – Isaac Vidrine
    Mar 26 at 20:17












  • You can absolutely do queries against strong json depending on the data you are searching. You can't index values but you can search values. It depends on what you need, in this case it sounds like a collection of configuration variables which is not often a set of values you need to query.

    – Jordan Cauley
    Mar 30 at 0:42











  • Well, it really depends on the database. I know with with ms sql at least, json is stored as plain text, therefore losing the ability to query and search field values.

    – Isaac Vidrine
    Mar 31 at 23:02











  • We're talking about mysql or mariadb because it's WordPress. But again you can query the DB for strings inside the JSON, and again in the example provided by the request he doesn't need to query values anyway. They are just storing configuration.

    – Jordan Cauley
    Apr 3 at 23:08











  • you can query the DB for strings inside the JSON.... and thats about all you can do. You cant say anything like "give me objects in this array whos values equal this". Idk about mariadb but mysql is this way as well, you have to store json as plain text. Yeah I get that its easy to just get the entire string, but with large data sets storing as json would be a nightmare.

    – Isaac Vidrine
    Apr 4 at 1:02











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55347668%2fstore-an-array-to-wordpress-database%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














You have 2 options.



Encode the array as json using json_encode and then decode it for use using json_decode



Serialize the array via serialize and unserialize via unserialize






share|improve this answer























  • Doing that would make it impossible to query for certain items in the array. Sure you could pull everything out and then filter but its not as efficient. Also those aren't the only options... probably the most accepted way is to store each item in its own table.

    – Isaac Vidrine
    Mar 26 at 20:17












  • You can absolutely do queries against strong json depending on the data you are searching. You can't index values but you can search values. It depends on what you need, in this case it sounds like a collection of configuration variables which is not often a set of values you need to query.

    – Jordan Cauley
    Mar 30 at 0:42











  • Well, it really depends on the database. I know with with ms sql at least, json is stored as plain text, therefore losing the ability to query and search field values.

    – Isaac Vidrine
    Mar 31 at 23:02











  • We're talking about mysql or mariadb because it's WordPress. But again you can query the DB for strings inside the JSON, and again in the example provided by the request he doesn't need to query values anyway. They are just storing configuration.

    – Jordan Cauley
    Apr 3 at 23:08











  • you can query the DB for strings inside the JSON.... and thats about all you can do. You cant say anything like "give me objects in this array whos values equal this". Idk about mariadb but mysql is this way as well, you have to store json as plain text. Yeah I get that its easy to just get the entire string, but with large data sets storing as json would be a nightmare.

    – Isaac Vidrine
    Apr 4 at 1:02
















0














You have 2 options.



Encode the array as json using json_encode and then decode it for use using json_decode



Serialize the array via serialize and unserialize via unserialize






share|improve this answer























  • Doing that would make it impossible to query for certain items in the array. Sure you could pull everything out and then filter but its not as efficient. Also those aren't the only options... probably the most accepted way is to store each item in its own table.

    – Isaac Vidrine
    Mar 26 at 20:17












  • You can absolutely do queries against strong json depending on the data you are searching. You can't index values but you can search values. It depends on what you need, in this case it sounds like a collection of configuration variables which is not often a set of values you need to query.

    – Jordan Cauley
    Mar 30 at 0:42











  • Well, it really depends on the database. I know with with ms sql at least, json is stored as plain text, therefore losing the ability to query and search field values.

    – Isaac Vidrine
    Mar 31 at 23:02











  • We're talking about mysql or mariadb because it's WordPress. But again you can query the DB for strings inside the JSON, and again in the example provided by the request he doesn't need to query values anyway. They are just storing configuration.

    – Jordan Cauley
    Apr 3 at 23:08











  • you can query the DB for strings inside the JSON.... and thats about all you can do. You cant say anything like "give me objects in this array whos values equal this". Idk about mariadb but mysql is this way as well, you have to store json as plain text. Yeah I get that its easy to just get the entire string, but with large data sets storing as json would be a nightmare.

    – Isaac Vidrine
    Apr 4 at 1:02














0












0








0







You have 2 options.



Encode the array as json using json_encode and then decode it for use using json_decode



Serialize the array via serialize and unserialize via unserialize






share|improve this answer













You have 2 options.



Encode the array as json using json_encode and then decode it for use using json_decode



Serialize the array via serialize and unserialize via unserialize







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 26 at 11:43









Jordan CauleyJordan Cauley

2191 silver badge5 bronze badges




2191 silver badge5 bronze badges












  • Doing that would make it impossible to query for certain items in the array. Sure you could pull everything out and then filter but its not as efficient. Also those aren't the only options... probably the most accepted way is to store each item in its own table.

    – Isaac Vidrine
    Mar 26 at 20:17












  • You can absolutely do queries against strong json depending on the data you are searching. You can't index values but you can search values. It depends on what you need, in this case it sounds like a collection of configuration variables which is not often a set of values you need to query.

    – Jordan Cauley
    Mar 30 at 0:42











  • Well, it really depends on the database. I know with with ms sql at least, json is stored as plain text, therefore losing the ability to query and search field values.

    – Isaac Vidrine
    Mar 31 at 23:02











  • We're talking about mysql or mariadb because it's WordPress. But again you can query the DB for strings inside the JSON, and again in the example provided by the request he doesn't need to query values anyway. They are just storing configuration.

    – Jordan Cauley
    Apr 3 at 23:08











  • you can query the DB for strings inside the JSON.... and thats about all you can do. You cant say anything like "give me objects in this array whos values equal this". Idk about mariadb but mysql is this way as well, you have to store json as plain text. Yeah I get that its easy to just get the entire string, but with large data sets storing as json would be a nightmare.

    – Isaac Vidrine
    Apr 4 at 1:02


















  • Doing that would make it impossible to query for certain items in the array. Sure you could pull everything out and then filter but its not as efficient. Also those aren't the only options... probably the most accepted way is to store each item in its own table.

    – Isaac Vidrine
    Mar 26 at 20:17












  • You can absolutely do queries against strong json depending on the data you are searching. You can't index values but you can search values. It depends on what you need, in this case it sounds like a collection of configuration variables which is not often a set of values you need to query.

    – Jordan Cauley
    Mar 30 at 0:42











  • Well, it really depends on the database. I know with with ms sql at least, json is stored as plain text, therefore losing the ability to query and search field values.

    – Isaac Vidrine
    Mar 31 at 23:02











  • We're talking about mysql or mariadb because it's WordPress. But again you can query the DB for strings inside the JSON, and again in the example provided by the request he doesn't need to query values anyway. They are just storing configuration.

    – Jordan Cauley
    Apr 3 at 23:08











  • you can query the DB for strings inside the JSON.... and thats about all you can do. You cant say anything like "give me objects in this array whos values equal this". Idk about mariadb but mysql is this way as well, you have to store json as plain text. Yeah I get that its easy to just get the entire string, but with large data sets storing as json would be a nightmare.

    – Isaac Vidrine
    Apr 4 at 1:02

















Doing that would make it impossible to query for certain items in the array. Sure you could pull everything out and then filter but its not as efficient. Also those aren't the only options... probably the most accepted way is to store each item in its own table.

– Isaac Vidrine
Mar 26 at 20:17






Doing that would make it impossible to query for certain items in the array. Sure you could pull everything out and then filter but its not as efficient. Also those aren't the only options... probably the most accepted way is to store each item in its own table.

– Isaac Vidrine
Mar 26 at 20:17














You can absolutely do queries against strong json depending on the data you are searching. You can't index values but you can search values. It depends on what you need, in this case it sounds like a collection of configuration variables which is not often a set of values you need to query.

– Jordan Cauley
Mar 30 at 0:42





You can absolutely do queries against strong json depending on the data you are searching. You can't index values but you can search values. It depends on what you need, in this case it sounds like a collection of configuration variables which is not often a set of values you need to query.

– Jordan Cauley
Mar 30 at 0:42













Well, it really depends on the database. I know with with ms sql at least, json is stored as plain text, therefore losing the ability to query and search field values.

– Isaac Vidrine
Mar 31 at 23:02





Well, it really depends on the database. I know with with ms sql at least, json is stored as plain text, therefore losing the ability to query and search field values.

– Isaac Vidrine
Mar 31 at 23:02













We're talking about mysql or mariadb because it's WordPress. But again you can query the DB for strings inside the JSON, and again in the example provided by the request he doesn't need to query values anyway. They are just storing configuration.

– Jordan Cauley
Apr 3 at 23:08





We're talking about mysql or mariadb because it's WordPress. But again you can query the DB for strings inside the JSON, and again in the example provided by the request he doesn't need to query values anyway. They are just storing configuration.

– Jordan Cauley
Apr 3 at 23:08













you can query the DB for strings inside the JSON.... and thats about all you can do. You cant say anything like "give me objects in this array whos values equal this". Idk about mariadb but mysql is this way as well, you have to store json as plain text. Yeah I get that its easy to just get the entire string, but with large data sets storing as json would be a nightmare.

– Isaac Vidrine
Apr 4 at 1:02






you can query the DB for strings inside the JSON.... and thats about all you can do. You cant say anything like "give me objects in this array whos values equal this". Idk about mariadb but mysql is this way as well, you have to store json as plain text. Yeah I get that its easy to just get the entire string, but with large data sets storing as json would be a nightmare.

– Isaac Vidrine
Apr 4 at 1:02









Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55347668%2fstore-an-array-to-wordpress-database%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript