0

here's a part of code that i wrote using reactjs where i am using 3 dropdown lists. Actually i am giving data manually (Source1, Source2, Source3, tech1,tech2,tech3...) but now i won't to get them from database 'Mysql' how can i transform my code in order to read them directly and dynamically?

import React, { Component } from 'react';
import {
  Container, Col, Form,
  FormGroup, Label, Input,
  Button, Dropdown, 
} from 'reactstrap';

import './App.css';
import loupe from'./loupe.png';
class App extends Component {
  render() {
    return (
          
     <div className="box"> 
           
          <div className="element sourcedropdown" >
            <label>Source :</label>
            <select className="form-control" name="Sources" onChange={this.handleInputChange}>
              <option selected>Select Source</option>
              <option value="1">Source1</option>
              <option value="2">Source2</option>
              <option value="3">Source3</option>
            </select>
          </div>
          <div className="element Techdropdown">
            <label>Technology :</label>
            <select className="form-control" name="Tech" onChange={this.handleInputChange}>
              <option selected>Select Technology</option>
              <option className="dropdown-item" value="1">Tech1</option>
              <option className="dropdown-item" value="2">Tech2</option>
              <option className="dropdown-item" value="3">Tech3</option>
            </select>
          </div>
          
          
          <div id="contrat" className="element contrat">
          <label>Contract :</label>
            <select className="form-control" name="Tech" onChange={this.handleInputChange}>
              <option selected>Select contract</option>
              <option className="dropdown-item" value="1">Cont1</option>
              <option className="dropdown-item" value="2">Cont2</option>
              <option className="dropdown-item" value="3">Cont3</option>
              <option className="dropdown-item" value="3">Cont4</option>
            </select>
          </div>
          <div id="checkbox" className ="element checkbox">
          <label check>
          <input type="checkbox" />{' '}
          All
         </label>
          </div>
          </div>  
         
      
    );
  }
}

export default App;

1 Answer 1

1

That's a bigger question than you think. React is just a JS library, a language in which you design how your app will look in your browser; we call it "frontend".

Accessing a database, i.e. a mysql one, is one of most popular tasks performed by "backend", part of your app that performs logic tasks "in the background". If you want to stick to JS it can be Express.js + Node.js.

You can think of them as two separate apps, communicating via endpoints. I suggest you read about the concept of backend/frontend :)

Sign up to request clarification or add additional context in comments.

3 Comments

Hello, thank u for your answer, i read about routes and axios.. , so when i send a request to my database in order to get those information then i will have them in a struct isn't it? then how can i do a sort of loop in order to make each content of that struct into <option>?
When you get your data with the response, in the form of an array, all you have to do is use a js map() function over it.
Okayy, Thank uu so much!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.