I was able to get the issue (POST request) from my previous forum question working with much appreciated help from Gerry @metamezzo in order to get data from wordpress page posted into a database table. Thank you so much Gerry for your help!! Now, I’m trying to get the GET request working in order to get data from database table into my wordpress page.
If someone can take a look and see where I’m going wrong, it would be very appreciated! As I mentioned in previous post, I’ve spent so much time trying to figure this out myself but almost everything that I find is just posting using a form. There seems to be very little on how to use WordPress hooks beyond the documentation, which I’ve tried in vain to figure out.
Below is the relevant code for what I’m trying to do: get the value ‘1000’ from ‘adapt’ column of database table (MLT_Exam_db) and retrieve it and display it on wordpress page <div> where id = #retrieveAdapt.
Thanks!
Will S.
// ——— HTML Widget ———
//left out top part of html document
<body>
<button id="getFromDbButton" onclick="getFromDbButtonFxn()" >Get from Database</button>
<div>Value retrieved from db: <span id="retrieveAdapt"></span></div>
</body>
// ——— functions.php ———
//left out the code for child hello theme
function register_flashcard_scripts2() {
wp_register_script('flashcard_settings2', get_stylesheet_directory_uri() . '/scripts/getFromDB.js', array('jquery'));
wp_localize_script('flashcard_settings2', 'FlashcardApp2', array(
'ajaxurl' => admin_url('admin-ajax.php'),
'user_id' => get_current_user_id()
));
wp_enqueue_script('flashcard_settings2');
}
add_action('wp_enqueue_scripts', 'register_flashcard_scripts2');
function save_flashcard_settings2() {
global $wpdb;
$adaptValueFromDb = intval($_GET['adapt']); // TRYING TO GET 'adapt' VALUE FROM DB
$query = "SELECT adapt FROM MLT_Exam_db WHERE adapt=' .$adaptValueFromDb. '";
$result = $wpdb->query($query);
}
add_action('wp_ajax_save_flashcard_settings2', 'save_flashcard_settings2');
add_action('wp_ajax_nopriv_save_flashcard_settings2', 'save_flashcard_settings2');
// ——— getFromDB.js ———
jQuery(document).ready(function ($) {
var $flashcard_exit_btn2 = $('#getFromDbButtonFxn');
if ($flashcard_exit_btn2.length !== 0) {
$flashcard_exit_btn2.on('click', function (e) {
if(confirm('Warning:')) {
$.ajax({
type: 'GET',
dataType: 'json',
url: FlashcardApp2.ajaxurl,
aync: false,
data: {
action: 'save_flashcard_settings2', // RUN PHP SCRIPT:
adaptValueFromDb: document.querySelector('#retrieveAdapt').innerHTML,
adaptValueFromDb: $adaptValueFromDb
},
error: function(xhr, textStatus, error) {
window.location.reload();
},
success: function(data) {
window.location.reload();
}
});
e.preventDefault();
} else {
window.location.reload();
}
});
}
});
]]>live
is used. This function was deprecated in 1.7 and removed in 1.9. I believe it would be trivial to update the script to use on
instead, which was introduced to replace live
https://www.ads-software.com/plugins/yakadanda-instagram/
]]>Thanks!
https://www.ads-software.com/extend/plugins/woocommerce-dynamic-gallery/
]]>need to call ‘jquery-1.3.2.js
javascrip:
<script type="text/javascript">
$(function() {
var d=300;
$('#navigation a').each(function(){
$(this).stop().animate({
'marginTop':'-80px'
},d+=150);
});
$('#navigation > li').hover(
function () {
$('a',$(this)).stop().animate({
'marginTop':'-2px'
},200);
},
function () {
$('a',$(this)).stop().animate({
'marginTop':'-80px'
},200);
}
);
});
</script>
the site is zatheka.com, really appreciate some help
]]>so far:
I have put the css my user user.css, I have put the html list under the get header tag in home.php and uploaded the jquery file and reffered to it im my header.php
problem: I appologise inadvance because something tells me Im asking something very obvious and simple to the rest of you but Im still learning all this, whats completely ruined my day is I have no idea where Im supposed to put the javascript part of the menus setup. Any help will be very appreciated. cheers
]]>