Encountering difficulties connecting to the database within Vue data tables

My php script was working fine with vuetify data, but now every page is showing the error message:

Your search for "{{ search }}" found no results
.

It seems like this issue occurs when the script cannot fetch data from the database. Here is my database class.

class Database
{
    public $id;
    public $user;
    public $user_name;
    public $password;

    public static function db()
    {

      $host = 'localhost';
      $dbName = 'newdata';
      $userName = "root";
      $password = "";


        $db = "mysql:host=$host;dbname=$dbName";

        try {
            $pdo = new PDO($db, $userName, $password);
        } catch (PDOException $e) {
            throw new PDOException($e->getMessage());
        }
        return $pdo;
    }

}

The username and password are correct, as I can connect to SQL on my remote server using them.

Here is a snippet of the code that results in the error mentioned above.

<v-app>
                  <v-card>

                    <div class="row card-body">
                    <div class="col-sm-12">
                      <div class="row col-sm-12">

                        <div class=" col-sm-3">
                          <div class="form-group row">
                            <label for="inputEmail3" class="col-sm-2 col-form-label">TO</label>
                            <div class="col-sm-10">
                              <input type="date" class="form-control form-control-sm" v-model="endDate">
                            </div>
                          </div>
                        </div>

                        <div class="col-sm-2">
                          <button type="submit" class="btn btn-success btn-sm"  v-on:click="getReport(ts)" style="margin-top:-5px">Submit</button>
                        </div>
                      </div>
                    </div>
                  </div>
                    <v-card-title>
                      <b>Balance Report</b>
                      </details>
                      <v-spacer></v-spacer>
                      <v-text-field
                        append-icon="search"
                        label="Search"
                        single-line
                        hide-details
                        v-model="search"
                      "></v-text-field>
                    </v-card-title>
                    <v-data-table
                      :headers="headers"
                      :items="Report"
                      :search="search"
                    ">
                      <template slot="items" slot-scope="props">
                      
                        <td>{{ props.item.col1 }}</td>
                        <td>{ props.item.col2}}</td>
                        <td>{ props.item.col3}}</td>
                        <td>{ props.item.col4}}</td>
                        <td>{ props.item.col5}}</td>
                      </template>
                      <v-alert slot="no-results" :value="true" color="error" icon="warning">
                        Your search for "{{ search }}" found no results.
                      </v-alert>
                    "lt;/v-data-table>
                  </v-card>
                </v-app>

Can anyone suggest where it might be stuck? Apologies for not including the entire PHP code here, as it was functioning well for many days before suddenly encountering this issue.

Below is my Vue class structure:

var UsageReport = new Vue({
  el:'#UsageReport',
  data(){
    return{
      Report:[],
      search: '',
      headers: [
                    { text: 'value1', value: 'col1 ' },
        { text: 'value2', value: 'col2 ' },
        { text: 'value3', value: 'col3 ' },
        { text: 'value4', value: 'col4 ' },
        { text: 'value5', value: 'col5 ' },
      ],
      variabl1:'',
      variabl2:'',
      variabl3:'',
      variabl4:''

    }
  },

Answer №1

It appears that you have linked the value of v-alert to true.

<v-alert .... :value="true" color="error" icon="warning">

Instead of hardcoding "true", consider using a variable that can be set to "true" if there is no data returned from your XHR call.

For instance, if "Report" is an array of objects populated after your backend call, you can use this approach:

              <v-alert slot="no-results" :value="Report.length == 0" color="error" icon="warning">
                Your search for "{{ search }}" found no results.
              </v-alert>

Take note of how the value of v-alert is dependent on the length of the Report array. Make sure to populate the Report data in order to prevent the message from displaying.

var UsageReport = new Vue({
  el:'#UsageReport',
  data(){
    return{
      Report:['sample item1','sample item2'],
      search: '',
      headers: [
                    { text: 'value1', value: 'col1 ' },
        { text: 'value2', value: 'col2 ' },
        { text: 'value3', value: 'col3 ' },
        { text: 'value4', value: 'col4 ' },
        { text: 'value5', value: 'col5 ' },
      ],
      variabl1:'',
      variabl2:'',
      variabl3:'',
      variabl4:''

    }
  },

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

How to style an HTML table with just a bottom border

Is there a way to recreate the Staff Directory section of this page using only HTML, without having to rely on CSS and Javascript? Specifically, I want to create a table with only bottom borders/dividers for each line. Any suggestions on how to achieve thi ...

Obtain the contenteditable span's value

I'm facing an issue with a content editable span - I want to extract its value when the post button is clicked, but it's not working as expected. Please note that I am unable to convert the span to a textbox or div, I specifically need the value ...

Ways to ensure that both the Search text field and search button are of equal height

I am facing an issue with the layout of my HTML code within my ASP.NET MVC web application. Below is the snippet of code causing the problem: <form class="customSearch" method="GET" action="@Url.Action("Search", "Home")"> <input class="searchIn ...

Unable to utilize Vuex for storing the method function

I need to integrate Vuex into my methods function in the home.js file to fetch weather data from an API and display it on the browser. I attempted to use getters and computed properties but encountered some issues. Here is a snippet from my home.js file: ...

Tips for effective page management

After creating a navbar in my project, I've come to the realization that it requires a component for each page and subpage. This seems redundant especially when dealing with multiple navigation options like shown in this image. Is it necessary to crea ...

Menu navigation - ensuring the background color extends to cover the entire page, not just the viewport

I'm facing an issue with the left navigation bar's design. Specifically, I'd like the grey color of the bar to extend vertically across the entire page. Currently, the gray bar ends at the viewport's edge. Is there a way to make the ba ...

Generating a PDF from a CSS3 multi-column layout with the help of snappy (a wrapper for wkhtmltopdf)

I am attempting to create a PDF with three columns using barryvdh/laravel-snappy and wkhtmltopdf. Since the text that will populate these columns varies in length, I need a method that allows the text to flow freely within the columns. I have attempted to ...

Import information from a website into MATLAB, including embedded internal frames (iframes)

Recently, I've been using MATLAB's urlread function to fetch website content for further analysis. However, I encountered a specific site where the data I'm looking for is housed within an internal frame embedded in the main index.php file ...

Is it possible to invoke the created() function in Vue from another method?

Currently, I am developing an application in Vue. Upon loading the page, a cookie containing the user's zip code is retrieved and used to perform a search. However, users should also have the ability to change their zip code if it is incorrect. I woul ...

The environment variable process.env.variable works perfectly fine during local development, however, it seems to malfunction once the application is deployed to Heroku within

Currently, I am utilizing nuxt.js and attempting to display images dynamically. To achieve this, I have implemented the BASE_URL variable within the .env file, allowing me to access image files based on the set BASE_URL in my local environment. .env file ...

Error encountered: JSON data contains an unexpected character at line 1, column 2

One of my PHP scripts looks like this: $STL = array(); $filter = array(); $filter['sort_by'] = "date_added"; $filter['sale'] = "F"; $filter['per_page'] = "12"; $STL['filter'] = $filter; echo json_encode($STL); When ...

Retrieve JSON data by making a POST request to a website's API

Can you help me retrieve Json data from a website API using JavaScript? I'm trying to fetch quotes from the following website: for my quotes generator page. While I have some understanding of making GET requests, it seems that this API requires POST ...

Ways to extract an object from JSON into PHP

Can someone help me figure out how to extract an image link from this API ()? The API endpoint is https://en.wikipedia.org/w/api.php?action=query&prop=pageimages&format=json&piprop=original&titles=Minecraft&pilicense=any. I've tri ...

Is there a way to switch between showing and hiding all images rather than just hiding them one by one?

Is there a way I can modify my code to create a button that toggles between hiding and showing all images (under the user_upload class), instead of just hiding them? function hidei(id) { $('.user_upload').toggle(); Any suggestions would be grea ...

What issues are hindering the successful export of my Vue component packaged with npm?

I created a small local npm package called fomantic-ui-vue with the following main js file: import Vue from 'vue' // Import vue component import button from './elements/button/button.vue' import buttonGroup from './elements/butt ...

Using jQuery to make an AJAX request to a Java backend server in order to update and refresh an HTML list

As someone new to using jQuery / AJAX with a Java backend system, I'm looking for guidance on making my first call. I have an HTML list structured like this: <ul> <li>Test 1</li> <li>Test 2</li> <li>Te ...

Incorrect data retrieved for numeric (integer) fields via ODBC access

Currently, I am in the process of developing an application that requires the importation of Microsoft Access files. This application is built using PHP, and I followed a specific tutorial to configure the environment (https://gist.github.com/amirkdv/96728 ...

Enhancing jQuery Rating Plugin

Currently, I am working on customizing the jQuery Bar Rating System Plugin. You can view an example of the plugin by visiting this link: . The rating system on my end will resemble Example D. Rather than having the plugin based on user input, my goal is to ...

Having trouble showing information from axios response in a Vue component

The data fetched with axios isn't appearing in the Vue component, even though there is data showing up in vue-dev tools. I'm also encountering errors like: [Vue warn]: Error in render: "TypeError: Cannot read property 'logbook_id' of nu ...

What is the method of generating an HTML tag solely using CSS?

Looking to style HTML tags without altering them in any way? Consider this example: <div id="Code_G" class="editor-group"> editor-group<br /> <div id="Code_L" class="editor-label "> editor-label </div> < ...