The Date_Format field in the JSON-Data is not displaying

Greetings and apologies for my limited English skills :-)

I am facing a challenge with my JSON data.

In my MySQL database, I have stored dates in the format YYYY.MM.DD. However, I require the format DD.MM.YYYY. So, I modified the query as follows:

$rs = mysql_query("SELECT event_name, DATE_FORMAT(beginn,'%d.%m.%Y'), DATE_FORMAT(ende,'%d.%m.%Y') FROM party WHERE ende >= CURDATE() ORDER BY beginn ASC");

Now, I receive the string with the correct date format

{"summer":[{"event_name":"testevent","DATE_FORMAT (beginn, '%d.%m.%Y')":"28.01.2015","DATE_FORMAT (ende, '%d.%m.%Y')":"30.01.2015"}]}

However, I am facing an issue with my JavaScript code. Previously, when using DATE_Format (beginn,'%d.%m.%Y'), I was able to retrieve the date (albeit not in the desired format). Now, I am receiving no output.

Below is my JavaScript code:

var url="party.php";
var activitydetail = sessionStorage.activitydetail;
$.getJSON(url,function(json){

$.each(json.summer,function(i,item){
$('<li><a href="#'+item.event_name+'"> '+item.DATE_FORMAT (beginn, '%d.%m.%Y')+' - '+item.event_name+'</a></li>').appendTo('#accor2');
});

});

The function is no longer working with '+item.beginn+' and

'+item.DATE_FORMAT(beginn, '%d.%m.%Y')+'

Does anyone have a solution?

Thank you in advance :-)

Answer №1

Your json string needs some improvements, as it currently looks like this:

{"sommer":[{"event_name":"testevent","DATE_FORMAT (beginn, '%d.%m.%Y')":"28.01.2015","DATE_FORMAT (ende, '%d.%m.%Y')":"30.01.2015"}]}

This means that the property name is "DATE_FORMAT (ende, '%d.%m.%Y')"

However, in your js code, you are trying to access:

item.beginn which does not make sense.

My suggestion is to modify your json string (probably on the php side) to:

{"sommer":[{"event_name":"testevent","beginn":"28.01.2015","ende":"30.01.2015"}]}

You could potentially make this change directly in the sql query, considering how you are currently handling it:

mysql_query("SELECT event_name, DATE_FORMAT(beginn,'%d.%m.%Y') as beginn, DATE_FORMAT(ende,'%d.%m.%Y') as ende FROM party WHERE ende >= CURDATE()ORDER BY beginn ASC");

By making these adjustments, fixing your js code should become much easier.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Ensure that the extension is only loaded once Angular has fully loaded

I am currently working on a Chrome extension that incorporates event listeners to elements within a page utilizing Angular 1.2.10. The following code snippet is an example of what I have: window.addEventListener("load", (event) => { var switchButton = ...

To trigger the action of any button in Ionic/Angular, I need to double-click

I am encountering an issue with an app that I developed using the Ionic framework. While the app works perfectly on Android devices, I am facing a peculiar situation on iOS. Every time I click a button in the Simulator or on an actual iOS device, I have t ...

Parsley.js now supports the use of the attribute `data-parsley-errors

Currently, I am attempting to integrate the errors container (e.g., data-parsley-errors-container="#ErrorSummary") with parsley.js. Most aspects are functioning properly, but I've encountered an issue. Specifically, I am looking to solely adjust the ...

Ways to create a table with columns from various fields obtained through an API call

Looking to preprocess data received from an API, the raw data is structured as follows: https://i.sstatic.net/a9Q2Z.png Desiring to dynamically generate a table with columns based on the fields task_name and saved_answers. It's important to note tha ...

Employing plain Javascript (without the use of jQuery) to concatenate information from two JSON strings - encountering an error due to the absence of

Having a JSON stringified form data like this: {"name":"jack miller", "address":"123 main st"} I aimed to append more records but encountered an error saying "append is not a function." The desired outcome is to have both sets of records in this format: ...

Slerping with quaternions in Three.js can produce undesirable outcomes when near the poles

Check out this video example: https://drive.google.com/file/d/18Ep4i1JMs7QvW9m-3U4oyQ4sM0CfIFzP/view In the demonstration, I showcase how I determine the world position of a ray hitting a globe under the mouse cursor. By utilizing lookAt() with a THREE.Gr ...

Python JSON Tokenizer Error: Troubleshooting Tokenization Issue

I have been trying out a highly recommended tutorial, but I encountered an error that has been persistent and I can't seem to find a solution for it. My setup includes PyCharm and Python3.6. Any help or guidance on this would be greatly appreciated. C ...

Is there a way to organize a specific column based on user selection from a drop down menu on the client side?

When selecting Timestamp from the drop-down menu, I expect the TimeStamp to be sorted in either ascending or descending order. Similarly, if I choose Host, the Host should be sorted accordingly. Despite using the Tablesorter plugin, sorting doesn't s ...

Seeking assistance with updating a mysql record through a php form. Can anyone lend a hand?

I am working on updating a row in my MySQL database using a form. I have successfully created a search retrieval script to locate the record, but I am facing an issue when trying to update it. After submitting the form, I receive a confirmation that the p ...

Is it possible to load the response from the $.post function, which contains GIF content, into a JavaScript Image object

How can I preload an image that the server only returns on a POST request? I want to load the image before displaying it. How can I store the result in a JavaScript object? $.post('image.php', {params: complexParamsObject}, function(result) { ...

How come the likes are not being refreshed when the button is clicked in my mongoose schema?

I am currently working on an express app using nodejs and mongoose. My main goal is to implement a JavaScript function that can update the number of likes on a post in a database directly from my ejs file. However, I have encountered troubles with this tas ...

Choose the rows that meet various criteria

To provide a clearer explanation of my issue, I have created a SQL fiddle: http://sqlfiddle.com/#!9/3122282/1 Within this fiddle, there are 3 tables where one table links the other two. I am attempting to retrieve products based on specific criteria suc ...

Is it possible for a JSON schema to require that a number array property must have its elements in ascending order?

Imagine having a property schema like this: "Points": { "type": "array", "items": { "type": "number", "minimum": 0, "maximum": 10 }, "minItems": 6, "maxItems": 30 ...

Find all records in the database where the value is either PHP or MySQL

Consider having an array stored in a MySQL row: a:3:{i:1;a:3:{i:0;s:1:"1";i:1;s:1:"3";i:2;s:1:"5";}i:4;a:3:{i:0;s:2:"21";i:1;s:2:"25";i:2;s:2:"29";}i:5;a:1:{i:0;s:2:"33";}} This array looks like this: Array ( [1] => Array ( [0 ...

Encountering difficulties in importing TailwindCSS

Having trouble importing TailwindCSS and applying CSS? Here's how it's included in my package.json: "devDependencies": { "autoprefixer": "^10.2.4", "css-loader": "^5.1.1", "postc ...

What is the memory allocation for null values in arrays by node.js?

Continuing the discussion from this thread: Do lots of null values in an array pose any harm? I experimented with node.js by doing this: arr=[] arr[1000]=1 arr[1000000000]=2 arr.sort() However, I encountered the following error: FATAL ERROR: JS Alloca ...

In ReactJS, the radio button in Material UI selects the value of the previous button

In my ReactJS app, I've implemented a radio button group. However, I am encountering an issue where logging the value results in the previous button's value rather than the current one. For instance, if I switch from "all" to "awaited," the log s ...

Error in Angular2: Internet Explorer 11 is having trouble accessing the property 'apply' because it is either undefined or null

After upgrading my angular2 packages to the latest versions, I encountered the following error: @angular/common": "^2.3.1 @angular/compiler": "^2.3.1 @angular/core": "^2.3.1 @angular/forms": "^2.3.1 @angular/http": "^2.3.1 @angular/platform-browser": ...

Transferring retrieved information from one division to another

This snippet of code demonstrates the process of fetching names from a MySQL database using PHP and Ajax. Updated Code index.php <html> <head> <script language="javascript"> function showresult( ...

Modify an individual attribute in a local JSON file using a put request in Angular 8

I am looking to make updates to my JSON file located in the assets folder. Specifically, if I want to update just one property of my JSON object, I would like it to only affect that particular property without impacting any others: For example, in the sam ...