Retrieve information from a PHP file using AJAX when the output is just a single line

I never thought I would find myself in this situation, but here I am, stuck. I just need a single result from this PHP file, so is using an array really necessary?

Despite my efforts to console.log(result) multiple times, all I get back is "null".

What could I possibly be doing wrong?

AJAX:

 $.ajax({
            url: "includes/getwinner.php", 
            success: (function (result) {
                 console.log(result);
               })
             })

PHP

include("../steamauth/db.php");

$result=mysqli_query($db, "select low_winner from pots");
$row=mysqli_fetch_assoc($result);

echo $row['low_winner'];

Answer №1

Give this a shot:

if ($data = mysqli_query($db, "select low_winner from pots")) {

    /* loop through results */
    while ($row = mysqli_fetch_assoc($data)) {
        echo $row["Title"];
    }

    /* release result set memory */
    mysqli_free_result($data);
}

Make sure to properly use the mysqli_free_result function, documentation available here.

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

PHP Inheritance failing to transfer data

I am struggling to pass values from a parent class. Despite trying basic examples, I can't seem to make it work. Your assistance would be greatly appreciated. class mother { public function __construct($db=""){ $this -> db = $ ...

Disabling a chosen option within a dropdown menu

`Hello there, I am just starting out with JavaScript and jQuery. Currently, I am developing a web application for ordering food and drinks. I have a dropdown menu for selecting breakfast items and the quantity. When the "add" button is clicked, a dynamic ...

Unanticipated string error triggered by setting jQuery cookie

While utilizing the jquery cookie plugin, I encountered an unexpected string error when trying to set it. jQuery('#select').change(function() { if(jQuery(this).val() == "defaultselect"){ jQuery.cookie('mycookie':'12345 ...

Verify if the term is present in an external JSON file

I am currently using tag-it to allow users to create tags for their posts. At the moment, users can type any word, but I have a list of prohibited words stored in JSON format. I am looking for a way to integrate this list into the tagit plugin so that if ...

Looking to display the "loading....." message on a PHP page?

I am working on a PHP webpage where I need to implement the following features: 1. Upon clicking "Say Thanks", it should change to "Done!". 2. Simultaneously, I would like to trigger an action in the indexController. 3. While this action is happening, I wa ...

Are there specific mathematical algorithms that lend themselves well to creating responsive HTML designs?

Tired of constantly guessing the percentage values to use with a specific number of divs and other elements in my design. I am looking to understand the mathematical calculations that determine the scaling required for different elements in order to main ...

Efficiently displaying multiple links with varying values in a D3.js force-directed graph

Issue with Displaying Overlapping Lines I attempted to showcase numerous connections between nodes using a multi-array format (Source, Target, Value). However, the lines are not displaying correctly and appear to be overlapping. You can view my example h ...

Replace all instances of the same word with the word "and" using regular expressions

If we look at the sentence below: Blue shirt blue hat Can regular expressions be used to detect 2 matching words and replace the second one with and so it reads: Blue shirt and hat Now, let's tackle a more complex example. In this case, we nee ...

Display a badge in the navbar on specific VueJS pages

I have embarked on the journey of creating a single page application using Vue 3, and I've encountered an interesting scenario where I want to display a badge in the navigation bar for specific pages. This is how my setup looks: // App.vue <templat ...

AngularJS - Showcase a dynamic list of information according to the value chosen

Seeking assistance from anyone willing. I have data in JSON format structured like this { state1: [ member1, member2], state2: [ member3,member4...], ... } There is a dropdown that displays the states listed in the JSON data. When a state is selected, I ...

Prevent regex from matching leading and trailing white spaces when validating email addresses with JavaScript

In my current setup, I utilize the following regular expression for email validation: /^[a-zA-Z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$/ My attempt to validate the email is shown below: if (!event.target.value.match(/^[a-zA-Z0-9._%+-]+@[a-z0-9.-]+\. ...

The error message states: "It is not possible to destructure the property 'createComponentInstance' of 'Vue.ssrUtils' as it is undefined for nuxt and jest."

I have been working on integrating the jest testing framework into my nuxt project, but I am facing a major obstacle. I am struggling to test a simple component and haven't been able to find a solution yet. If anyone has encountered the same issue, co ...

Utilizing JavaScript and jQuery to make a query to mySQL

Looking to solve a SQL database query challenge using JavaScript or jQuery? Here's the scenario: I have a SQL db and typically use the following query to retrieve data based on distance from specified coordinates: SELECT id, ( 3959 * acos( cos( rad ...

The DOM fails to reflect changes in the data variable in VueJS

I am facing an issue while trying to update an array of arrays and display it as a reactive variable, however the DOM does not seem to reflect those changes. To achieve this, I have two components - a parent component and a child component: Parent Compon ...

Vuetify - Implementing a search feature in a table that automatically navigates to the matching row

Currently, I am working with 2 Vuetify data tables that do not have pagination enabled. Each row in the second table corresponds to exactly one parent in the first table. My goal is to be able to click on an entry in the second table and have it automati ...

Angular 1: selecting all checkboxes within an extensive ng-repeat list

I am encountering a performance issue with a table that includes hundreds of rows, each containing a checkbox. When I use the "Check All" option at the top to select all checkboxes in one go, the browser becomes unresponsive, especially in IE11 which is th ...

Why isn't the selected option appearing first?

I have written a PHP code to display the specified div <div id="main_catsel"> <select id="maincat" > <option value="1">none</option> <option value="2">Computer</option> <option value="4">Refrigerator& ...

Maximizing the potential of typescript generics in Reactjs functional components

I have a component within my react project that looks like this: import "./styles.css"; type InputType = "input" | "textarea"; interface ContainerProps { name: string; placeholder: string; as: InputType; } const Conta ...

arrangement of a list with the specified information stored in each item

Presently, my task involves setting up a dynamic gallery page with multiple tabbed lists that are fetched from the database. Each list corresponds to a specific Gallery Name and is associated with a unique data-list-id. Furthermore, each gallery contains ...

Review Limited Screen Size for a Smartphone Website

I have been working on optimizing a mobile website and I utilized CSS to adjust the layout design for screen widths between 150px and 480px. However, during testing on an actual phone, the desktop layout is appearing instead of the custom layout set with C ...