How to link to MySQL Database

Hi, So I am extremely extremely new to any web development, so please take it easy on me

I have setup framework7 with a wamps server, as form the tutorial link on this website.
I have a mysql database inside that wamps icon, which I have used, and set up a very basic database (going to fill the rest later date once i can get it working, but its just a list of councils atm)

I want to do 2 things, the first was my main page has a search bar at the top, and I want to generate the options below such that user can search and get the council they want quickly from the 400+ or so in the UK. I am thus wanting to populate the dropdown option from my sql database row by row.

I have followed this tutorial using PDO (https://www.youtube.com/watch?v=5ZRUN4ZUcT8) but doesnt work and im not skilled enough to resort, I have managed to connect however using sqli on a test.php file, this returns me a big list, but I cannot get it to link to my main website, because it seems to just throw a 404, which isn’t helpful and ive tried eveyrthign I can find but have little understanding so…

My SQL Database is currently hosted at localhost:port 3308 and my localhost that has my main PWA on, is port 8082

The second thing I want to do, is that once they have selected council, Ill have a button appear, which I should be fine to do, taking you to a new page, which retrieves further information form database, each council will has say Westminster, Y,Y,N,N,Y etc after it, correspinding to does it ahve a black bin for first location, blue for second, no green bin for 3rd etc… That sort of idea,
Then this data will determine which cards will be visible to the user.

But, I am having issue getting anything to come into my browser. If I go to http://localhost/EcoPal/test.php I can see the data it got from my PHP.
But I can’t get it into my website. I have no idea if it is to do with file structure? Ive kept it the same as the structure that came with framework7 vue. Ive no idea where to shove the test.php file

My PHP is:

<?php $ser="localhost"; $user="EcoPalUser"; $pass="TRWWSTW4e&e"; $db="authorities"; $con=mysqli_connect($ser,$user,$pass,$db,3308) or die("Connection Failed"); echo "Connected Sucess"; $received_data = json_decode(file_get_contents("php://input")); echo $received_data; $sql = 'SELECT * FROM `councils`;'; $result = mysqli_query($con,$sql); $resultCheck = mysqli_num_rows($result); if($resultCheck > 0){ echo "Result Found so now printing"; while($row = mysqli_fetch_assoc($result)){ echo $row['Name'],"
"; } } ?>

It Generates the following:
(Ignore the ddlesborough–will fix that eventually–its an issue with what I put in my mysql database)

Connected SucessResult Found so now printingddlesbrough
Hartlepool
Redcar and Cleveland
Stockton-on-Tees
Darlington
Halton
Warrington
Blackburn with Darwen
Blackpool
Kingston upon Hull, City of
East Riding of Yorkshire
North East Lincolnshire
North Lincolnshire
York…You get the idea, it goes on for several hundred items

My Main Homepage is:

<!-- Some function which will check to see if the user previously saved login on their device -->

   

<f7-navbar >

  <f7-nav-title title="EcoPal" subtitle ="Your Recycling Companion">

    

  </f7-nav-title>

  <f7-nav-right sliding>

        <f7-link href="/settings/">

          <f7-icon ios="f7-compass_fill" aurora="f7-compass_fill" md="material:settings" size = "32px" ></f7-icon>

        </f7-link>  

  </f7-nav-right>

  </f7-navbar>

    <f7-block>

                       

            <f7-list>

                <f7-list-item title="Select Area" smart-select :smart-select-params="{openIn: 'popup', searchbar: true, searchbarPlaceholder: 'Search for your area'}">

                    <select name="Council" v-model="select_council" @change="fetchCouncil">

                    <option value="">Select Authority</option>

                    <option v-for="data in council_data" :value="data.council_id">{{data.council_name}}</option>

                    </select>

                </f7-list-item>

            </f7-list>

    

    </f7-block>

My Router is:

import HomePage from ‘…/pages/home.vue’;

import AboutPage from ‘…/pages/about.vue’;

import LocalRecyclingInfo from ‘…/pages/localrecyclinginfo.vue’;

import FormPage from ‘…/pages/form.vue’;

import PrivacyPage from ‘…/pages/privacy-policy.vue’;

import DynamicRoutePage from ‘…/pages/dynamic-route.vue’;

import RequestAndLoad from ‘…/pages/request-and-load.vue’;

import NotFoundPage from ‘…/pages/404.vue’;

import PostCodeEntryPage from ‘…/pages/postcode-entry.vue’

import HomeOriginal from ‘…/pages/homeoriginal.vue’;

import SplashScreen from ‘…/pages/loading-page.vue’;

import LoginPage from ‘…/pages/login-page.vue’;

import Settings from ‘…/pages/settings.vue’;

import AboutCreators from ‘…/pages/about-creators.vue’;

var routes = [

{

path: '/',

component: HomePage,

},

{

path: '/login-page/',

component: LoginPage,

},

{

path: '/loading-page/',

component: SplashScreen,

},

{

path: ‘/about-creators/’,

component: AboutCreators,

},

{

path: '/settings/',

component: Settings,

},

{

path: '/about/',

component: AboutPage,

},

{

path: '/homeorignal/',

component: HomeOriginal,

},

{

path: '/localrecyclinginfo/',

component: LocalRecyclingInfo,

},

{

path: '/home/',

component: HomePage,

},

{

path: '/postcode-entry',

component: PostCodeEntryPage,

},

{

path: '/privacy-policy/',

component: PrivacyPage,

},

{

path: '/form/',

component: FormPage,

},

{

path: '/dynamic-route/blog/:blogId/post/:postId/',

component: DynamicRoutePage,

},

/*{

path: '/config/'

component: Config

},*/

{

path: '/request-and-load/user/:userId/',

async: function (routeTo, routeFrom, resolve, reject) {

  // Router instance

  var router = this;

  // Popup Instance

  var popup = app.popup.create({});

  // App instance

  var app = router.app;

  // Show Preloader

  app.preloader.hide();

  // User ID from request

  var userId = routeTo.params.userId;

  // Simulate Ajax Request

  setTimeout(function () {

    // We got user data from request

    var user = {

      firstName: 'Samuel',

      lastName: 'Rhodes',

      about: 'Hello, I am the Creator of EcoPal! I hope you like it!',

      links: [

        {

          title: 'EcoPal Website',

          url: 'http://framework7.io',

        },

        {

          title: 'EcoPal Blog',

          url: 'http://forum.framework7.io',

        },

      ]

    };

    // Hide Preloader

    app.preloader.show();

    // Resolve route to load page

    resolve(

      {

        component: RequestAndLoad,

      },

      {

        context: {

          user: user,

        }

      }

    );

  }, 1000);

},

},

{

path: '(.*)',

component: NotFoundPage,

},

];

export default routes;

My App.js is

// Import Vue

import Vue from ‘vue’;

// Import Framework7

import Framework7 from ‘./framework7-custom.js’;

// Import Framework7-Vue Plugin

import Framework7Vue from ‘framework7-vue/framework7-vue.esm.bundle.js’;

// Import Framework7 Styles

import ‘…/css/framework7-custom.less’;

// Import Axios For Http request etcs

import Axios from ‘axios’;

// Import Icons and App Custom Styles

import ‘…/css/icons.css’;

import ‘…/css/app.less’;

// Import App Component

import App from ‘…/components/app.vue’;

// Init Framework7-Vue Plugin

Framework7.use(Framework7Vue);

// Init App

new Vue({

el: ‘#app’,

render: (h) => h(App),

// Register App Component

components: {

app: App

},

});

My index.html is

EcoPal

This is what I get in my browser

Help please is really appreciated as im completely stumped and spent best part of 2 weeks trying to resolve this!

can you share hoy you call the backend from the app. the js code

1 Like

Hi, I’ve updated my above with the app.js files and the index as well, as far for the back end—there is literally very little, only the database which is imported into mysql via phpadmin and the test.php file which is above mentioned
If I have interpreted what you meant correctly that is, but feel free to correct me if there is anything else you need!
Thank you for helping me!
Cheers
Sam

did you mke a custom build? if not, import f7-bundle js

import Framework7 from 'framework7/framework7.esm.bundle.js';

or the components you need

https://framework7.io/docs/package.html

aside from that.
i didnt see your request code.

// something like:
this.$f7.request.get(url, data, success, error, dataType)

i see you import Axios, but never use it

Hi, Thank you very much for your help so far, I do appreciate it!

Ahh I see, I did do a custom build (mind you it was pretty much everything imported anyway)

Yeah I was told Axios would be a good way of doing requests, so I imported it and thought I was using it with the following method in my home build, but you might be right and I might be able to do it a different way? Like the this.$f7.request.get(url,data,sucess,error,dataType)–> I did try this before but couldn’t work out what my URL should be and where to stick my test.php file to get it working? I’m happy to try out this way, could you possibly help me a bit more please? I read the F7 document on it, but was confused a little.

Below is the home page vue—specifically where I thought I was using axios
fetchCouncil:function(){

        //Framework7.request.get('../js/test.php',this.council_data,text);

        axios.get("fetchdata",{

            request_for: "councils",

            

        }).then(function(response){

            this.council_data = response.data;

        });

Below is my F7 Custom Bundle
import Framework7, { Device, Request, Utils } from ‘framework7/framework7-lite.esm.js’;

import Appbar from ‘framework7/components/appbar/appbar.js’;

import Dialog from ‘framework7/components/dialog/dialog.js’;

import Popup from ‘framework7/components/popup/popup.js’;

import LoginScreen from ‘framework7/components/login-screen/login-screen.js’;

import Popover from ‘framework7/components/popover/popover.js’;

import Actions from ‘framework7/components/actions/actions.js’;

import Sheet from ‘framework7/components/sheet/sheet.js’;

import Toast from ‘framework7/components/toast/toast.js’;

import Preloader from ‘framework7/components/preloader/preloader.js’;

import Progressbar from ‘framework7/components/progressbar/progressbar.js’;

import Sortable from ‘framework7/components/sortable/sortable.js’;

import Swipeout from ‘framework7/components/swipeout/swipeout.js’;

import Accordion from ‘framework7/components/accordion/accordion.js’;

import ContactsList from ‘framework7/components/contacts-list/contacts-list.js’;

import VirtualList from ‘framework7/components/virtual-list/virtual-list.js’;

import ListIndex from ‘framework7/components/list-index/list-index.js’;

import Timeline from ‘framework7/components/timeline/timeline.js’;

import Tabs from ‘framework7/components/tabs/tabs.js’;

import Panel from ‘framework7/components/panel/panel.js’;

import Card from ‘framework7/components/card/card.js’;

import Chip from ‘framework7/components/chip/chip.js’;

import Form from ‘framework7/components/form/form.js’;

import Input from ‘framework7/components/input/input.js’;

import Checkbox from ‘framework7/components/checkbox/checkbox.js’;

import Radio from ‘framework7/components/radio/radio.js’;

import Toggle from ‘framework7/components/toggle/toggle.js’;

import Range from ‘framework7/components/range/range.js’;

import Stepper from ‘framework7/components/stepper/stepper.js’;

import SmartSelect from ‘framework7/components/smart-select/smart-select.js’;

import Grid from ‘framework7/components/grid/grid.js’;

import Calendar from ‘framework7/components/calendar/calendar.js’;

import Picker from ‘framework7/components/picker/picker.js’;

import InfiniteScroll from ‘framework7/components/infinite-scroll/infinite-scroll.js’;

import PullToRefresh from ‘framework7/components/pull-to-refresh/pull-to-refresh.js’;

import Lazy from ‘framework7/components/lazy/lazy.js’;

import DataTable from ‘framework7/components/data-table/data-table.js’;

import Fab from ‘framework7/components/fab/fab.js’;

import Searchbar from ‘framework7/components/searchbar/searchbar.js’;

import Messages from ‘framework7/components/messages/messages.js’;

import Messagebar from ‘framework7/components/messagebar/messagebar.js’;

import Swiper from ‘framework7/components/swiper/swiper.js’;

import PhotoBrowser from ‘framework7/components/photo-browser/photo-browser.js’;

import Notification from ‘framework7/components/notification/notification.js’;

import Autocomplete from ‘framework7/components/autocomplete/autocomplete.js’;

import Tooltip from ‘framework7/components/tooltip/tooltip.js’;

import Gauge from ‘framework7/components/gauge/gauge.js’;

import Skeleton from ‘framework7/components/skeleton/skeleton.js’;

import Menu from ‘framework7/components/menu/menu.js’;

import ColorPicker from ‘framework7/components/color-picker/color-picker.js’;

import Treeview from ‘framework7/components/treeview/treeview.js’;

import TextEditor from ‘framework7/components/text-editor/text-editor.js’;

import Elevation from ‘framework7/components/elevation/elevation.js’;

import Typography from ‘framework7/components/typography/typography.js’;

Framework7.use([

Appbar,

Dialog,

Popup,

LoginScreen,

Popover,

Actions,

Sheet,

Toast,

Preloader,

Progressbar,

Sortable,

Swipeout,

Accordion,

ContactsList,

VirtualList,

ListIndex,

Timeline,

Tabs,

Panel,

Card,

Chip,

Form,

Input,

Checkbox,

Radio,

Toggle,

Range,

Stepper,

SmartSelect,

Grid,

Calendar,

Picker,

InfiniteScroll,

PullToRefresh,

Lazy,

DataTable,

Fab,

Searchbar,

Messages,

Messagebar,

Swiper,

PhotoBrowser,

Notification,

Autocomplete,

Tooltip,

Gauge,

Skeleton,

Menu,

ColorPicker,

Treeview,

TextEditor,

Elevation,

Typography

]);

export default Framework7;

export { Device, Request, Utils };

I was trying to use Framework7 with Vue–>Will that have any complications? Might that be why if I try using something like ```
this.$f7.request.get(url, data, success, error, dataType)

since you are new. i wolud advice you to use f7-cli and start a f7-vue project with the cli, all set up for you.
https://framework7.io/cli/
then after you undersand how things work move to custom builds etc.

this is how you call the backend?

.get('../js/test.php',this.council_data,text);

it shouldend be something like:

.get('localhost/test.php',this.council_data,text);

if you are running apache on port 80

Hi,
Sorry in which case, I’ve unknowingly told you the wrong thing, I used that Framework7-cli to make the app in the first place, I thought you meant because I’d changed it so it used dark mode etc rather than the default setup that it was no longer default and htus custom.
But yes, I did use that to set it up.
I have tried (where vm is variable I set to equal the new vue) (And also tried this.$request…)
vm.$request.get(‘localhost/test.php’,this.council_data,text);
The file is there because in browser I can view it, but I get no response whatsoever on the website/pwa, it doesnt even appear in the network tab of dev tools as logging the get command?
I am using localhost at port 80 with apache yes, I also checked and there isn’t any firewall blocking my sql port either which is at 3308.
Do you have any idea as to why this might be?

if yo make a request without the app, using postman. did you get any response?

localhost/test.php

Framework7: https://www.youtube.com/playlist?list=PLSDxfTZT8FU6hG1SA_A9YlEHp8R2qRqBx

All you need.

Hi, Yeah I get a 200 OK and using RESTED plugin for firefox it shows up all of my things ok with
breaks between each of the columns, its just it then won’t go it for my app, nor does the 200 request appear in the networks tab when its called (by pressing a button atm)

Hi, Thank you for your help so far,
so update: I dont know whats changed because I havent changed anything, but not it fills the boxes with nothing but generates the boxes…See below…Any thoughts?
It also doesn’t populate eveyrthing, only about 10 items or so roughly rather than the full 300ish

My main framework7 code home.vue (The rest are unchanged)

<!-- Some function which will check to see if the user previously saved login on their device -->

   

<f7-navbar >

  <f7-nav-title title="EcoPal" subtitle ="Your Recycling Companion">

    

  </f7-nav-title>

  <f7-nav-right sliding>

        <f7-link href="/settings/">

          <f7-icon ios="f7-compass_fill" aurora="f7-compass_fill" md="material:settings" size = "32px" ></f7-icon>

        </f7-link>  

  </f7-nav-right>

  </f7-navbar>

    <f7-block>

                       

            <f7-list>

                <f7-list-item title="Select Area" smart-select :smart-select-params="{openIn: 'popup', searchbar: true, searchbarPlaceholder: 'Search for your area'}">

                    <select name="Council" v-model="select_council" @change="fetchCouncil">

                    <option value="">Select Authority</option>

                    <option v-for="data in council_data" :value="data.council_id">{{data.council_name}}</option>

                    </select>

                </f7-list-item>

            </f7-list>

            <f7-button round fill raised @click="fetchCouncil"></f7-button>

    

    </f7-block>

And the js script inside home.vue

(

import axios from ‘axios’;

//this.$axios.defaults.baseURL = “https://localhost:8082”;

export default {

data(){

select_council:''

council_data:''

return{

  council_data: 'Kirklees',

  

}

},

methods:{

    fetchCouncil() {

        //app.request.get('test.php', function (data) {

        //this.council_data = response.data; alert("Hey I worked");},function(){alert("Failed");});

        //Framework7.request.get('../js/test.php',this.council_data,text);

        

       alert(this.council_data);

        this.$f7.$request.get('localhost/EcoPal/test.php',function(){this.council_data = response.data;},this.council_data);

                                

    }

    

    //https://www.youtube.com/watch?v=5ZRUN4ZUcT8

    

},

}

</script

When it returns the test.php in postman (well RESTED on firefox) it appears like
dlesbrough
Hartlepool
Redcar and Cleveland
Stockton-on-Tees
Darlington
Halton
Warrington
Blackburn with Darwen
Blackpool
Kingston upon Hull, City of
East Riding of Yorkshire
North East Lincolnshire
North Lincolnshire
York
Derby
Leicester
Rutland
Nottingham
Herefordshire, County of
Telford and Wrekin
Stoke-on-Trent
Bath and North East Somerset
Bristol, City of
North Somerset
South Gloucestershire
Plymouth
Torbay
Swindon
Peterborough
Luton
Southend-on-Sea
Thurrock
Medway
Bracknell Forest
West Berkshire
Reading
Slough
Windsor and Maidenhead

Cheers
Sam

Hi, Thank you, I’ll give it a look and see what I can get from looking at their code because sadly I don’t speak (spanish?) but Ill see what I can manage! Thanks!