Displaying date from mysql in a Jquery Mobile dropdown - mysql

I started making an app with use of Jquery mobile(JQM) to be used for a customer database. You should be able to create a customer name, address etc. The information will then be stored in a MySQL database. The part I've got under control.
Now I want to do so that it is possible to retrieve customer number and name of the database again and show them in a drop down menu from JQM.
So something like:
"SELECT
kundenummer, navn
FROM
kundeskema
ORDER BY
id
DESC";
I have my database connection and my php page, but how do I get the information from where I make my sql statement and to my html page? Know it is using AJAX but dont understand how to do. I know it's a fairly simple task, but it's not for me.
plz help
Morten

You can create a PHP file which returns a JSON string of your data. Then do a jQuery ajax call to this PHP file and in the success callback create elements and add them the select element.
e.g.:
$.ajax({
url: myValues.php,
success: function(data) {
template = //create option elements
$('#mySelect').html(template);
}
});
Or
https://github.com/tkompare/projects/tree/master/ajaxexample
This is for a listview but the idea is the same

Related

How do i get the User Image from a lookup list on Sharepoint 2013?

I'm really stuck with getting the User image from a lookup list using AJAX with SharePoint 2013.
Ok so im getting my data from a Sp list called 'Comments', and im selecting a SP generated field called 'Created By' however on my SP its actually called 'Author'. This field only shows an ID so ive expanded it with OData to get the 'Author' details.
So what im trying to do is set up a custom comment section. So im taking data from the 'Author / Created By' column and outputting that on top of the persons comment. This all works fine!
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + "/DigiBlog/_api/web/lists/getbyTitle('Comments')/items?$select=Comment,Likes,BlogId,Created,Author/ID,Author/FirstName,Author/LastName,Author/Title&$expand=Author/Id",
type: "GET",
headers: {
'accept': 'application/json;odata=verbose'
},
success: function (data) {
for (var i = 0; i < data.d.results.length; i++) {
var item = data.d.results[i];
self.blogComments.push(item);
//item.FirstName = item.FirstName.toLowerCase();
//console.log(item);
}
console.log("Comment User Info Called");
},
error: function () {
console.log("Comment User Info Error");
}
});
What i want is the picture Url from that user, so i can output an image of that person next to each comment. My Sharepoint is part of big organisation so theres a tonne of restrictions in place, one of which means i can't view the list of users so i can't see what fields i can actually use. Ive seen people use 'Picture' value in the select field, however when i try that the Ajax fails.
url: _spPageContextInfo.webAbsoluteUrl + "/DigiBlog/_api/web/lists/getbyTitle('Comments')/items?$select=Comment,Likes,BlogId,Created,Author/ID,Author/FirstName,Author/LastName,Author/Title&$expand=Author/Id",
All im looking for is the Author Img URl, ive tried Author/[Picture, PictureUrl, PictureUri, Image, ImageUri... and so on]. Ive spent 2 days on this and im not getting anywhere fast!
I either want a way to get the Picture Url or a way to show all the avaiable fields of 'Author' using console so i can find the relevant field i need to select.
Can anyone help? Thanks in advance!
It seems that we could not get picture url directly.
Firstly,you could get user name.
/_api/web/lists/getbytitle('Comments')/items(1)?$select=Owner/Name&$expand=Owner
Secondly,you could use this rest api to get picture url.
/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=#v)?#v='domain\username'&$select=PictureUrl
The different versions of rest api versions are introduced here.
Tip:The username obtained in the first step may need to be processed as in the example.

Getting the value of a particular cell with AJAX

My goal is very simple and I would guess it is a very common goal among web developers.
I am creating a Rails (5.1) application, and I simply want to use AJAX to get the value of a specific cell in a specific row of a specific table in my database (later I am going to use that value to highlight some text on the current page in the user's browser).
I have not been able to find any documentation online explaining how to do this. As I said, it seems like a basic task to ask of jquery and ajax, so I'm confused as to why I'm having so much trouble figuring it out.
For concreteness, say I have a table called 'animals', and I want to get the value of the column 'species' for the animal with 'id' = 99.
How can I construct an AJAX call to query the database for the value of 'species' for the 'animal' with 'id' = 99 .
Though some DBs provide a REST API, what we commonly do is define a route in the app to pull and return data from the DB.
So:
Add a route
Add a controller/action for that route
In that action, fetch the data from the DB and render it in your preferred format
On the client-side, make the AJAX call to that controller/action and do something with the response.

Pass in user-specified parameters to query a database and return data

I am extremely new to Ruby on Rails, having only a couple days of experience. So far, I have created a new app, and loaded data into the database called name which is comprised of date:string, value:decimal, and unique_id:integer. So now, I can go to "(my local port)/name" and view the table successfully.
What I would like to do is this:
In a new html page, have a SIMILE Timeplot (http://www.simile-widgets.org/timeplot/) with an HTML drop-down list below it in order to select a unique_id and another drop-down box to select a year.
From there, I would like to search through the database and display all of the data on the Timeplot that matches the unique_id and that is in the specified year.
I believe I must make an HTTP GET request for a date_to, date_from, and unique_id, but I do not know how to implement this (admittedly I have been searching the web for ages, but could not figure out the solution).
Any help would be greatly appreciated! Thank you.
Edit: Even just advice on what component to tackle first
First you need to create a route for your search such as this:
match "name/search" to: "name#search" as: "name_search", via: :get
Then if you are using AJAX, and using jQuery you make an HTTP request like this:
$.get("/name/search", {
unique_id: <your_unique_id>,
date_from: <your_date_from>,
date_to: <your_date_to> },
function(result) {
// You do whatever you want with the result here
}
}
P.S:
The Javascript code might not be 100% correct, since I rarely use it.

Typo3: How to read from database to produce UL for view

OK, in good old fashioned PHP MVC, I might use a model to hit the DB, send info to my PHP controller that I pass on to the View. In the View, I might take that info (say i ajax'ed my controller for the info) and create a table or ul to display the data returned.
I've had trouble finding any modern (ver 6.1 is what i'm on) tutorial to show me how to preform this action in typo3.
Can anyone just "steer" me in the right direction? Perhaps provide an example via answer, or some links to further information that may compare it down to "old fashioned MVC"?
Extension has been suggested, but I'd like to know the very base process of what I'm asking before I try writing some extension, unless the extension is the only way. Although, my table is now on the SAME DB my typo3 is on, so shouldn't there be some command to just simply call my table and get the rows? Maybe send them to a ###sub-part###?
You can use a typoscript cObj content and the select option together with the function render_obj when your table name is like the typo3 nameing convention. The select pulls the record from the table and pass it to the render_obj function. It's a function that can apply to all cObj and iterate over the entire selection. stdWrap works only on the entire cObj. When you need to work through each record you need the render_obj function. For example:
10 = CONTENT
10 {
select {
pidInList = 1
where = colpos=1
orderBy = sorting
}
table = tt_content
renderObj.stdWrap.wrap = <li>|</li>
renderObj.stdWrap.required = 1
}
10.stdWrap.wrap = <ul>|</ul>
This gives you an unorderd list from the tt_content table with pid=1 and the content from the far left column.

How to do php operations in drupal

I am absolute beginner to drupal.
I have added a contact form (using Webform module).
Now I want to save the data entered in the form. But I am lost. I have searched over internet, found db_query() is used to query database.
But I dont know where to write the php code. Please help me or if you know any link,please give me.
The tables you'll be most interested in are webform, webform_submissions, webform_submitted_data and webform_component. Have a look at those tables and it becomes very obvious how they're linked together.
You'll want to look at the Drupal 7 Database API to learn how to use the query system but here's an example to get you going:
/* Get a list of all submissions from webform for the node with ID (`nid`) of 1 */
$nid = 1;
$submissions = db_select('webform_submissions', 'ws')
->fields('ws')
->condition('nid', $nid)
->execute();
/* If you want to use db_query and a plain old SQL statement instead you'd do it like this:
$submissions = db_query('SELECT * FROM webform_submissions WHERE nid = :nid', array('nid' => $nid)); */
/* Loop through the submissions and load up the submitted data for each */
$submission_data = array();
foreach ($submissions as $submission) {
$query = db_select('webform_submitted_data', 'wsa')
->fields('wc', array('name'))
->fields('wsa', array('data'))
->condition('sid', $submission->sid);
/* Join in the component table to get the element label */
$query->join('webform_component', 'wc', 'wc.nid = wsa.nid AND wc.sid = wsa.cid');
$submission_data[] = $query->execute()->fetchAllKeyed();
}
At the end of that code you'll have an array ($submission_data), which contains a list of arrays of submission data for the provided node. Each of those arrays' items has a key of the component label, and a value of the submitted user value.
Hope that helps
It's worth noting that for most normal use cases you'll never need to look at the databases or do any kind of coding. The UI allows you to view submissions of a form (and see what was submitted). You can also configure the Webform to send you a copy of each submission (via email)... There is a lot you can do without "looking under the hood" or messing with the database in any way.
If you are really new to Drupal and Webforms, I just thought I'd point that out. There are a lot of tabs in the UI which might easily be overlooked.
Webform has Views support, so you probably don't really need to write database queries to generate the report you want.