D
D
danila_prokopenko2021-04-28 20:39:39
React
danila_prokopenko, 2021-04-28 20:39:39

How to display pictures from the mysql database in the img tag (I can easily take text data, but there is a problem with images)?

I store the images on the client's local img folder. zTuU21aLbyo.jpg?size=429x568&quality=96&sign=14f896fc207d3dafdf3be88730c4c434&type=album

Image data in database. ilKr3ZGY3h0.jpg?size=1513x110&quality=96&sign=aabc8d40779313a6cd0290266ecf4759&type=album
How to pull an image from the img folder by name from the database? and insert like this? H8rmBkHVzoc.jpg?size=463x59&quality=96&sign=f1723875892db446abb8daedb39de28f&type=album
but already from the database, taking the name of
the text, I calmly endure it, but I don’t know about the pictures.

const OurTours = () => {
  const [planets, setPlanet] = useState([]);

  useEffect(() => {
    async function loadPlanets() {
      const result = await axios.get("http://localhost:4000/api/get");
      setPlanet(result.data);
      console.log("Стейт planet", result.data)
    }
    loadPlanets()
  }, []);

  return (
    <div className="content">
      <div className="wrapper">
        <div className="main-content">
          <div className="container">
            <Heading />

            {planets.map((planet, index) => (
              <div className="planet-cart">
                <div className="information">
                  <div className="under-text">
                    {planet.name}

                  </div>
                  <div className="bottom-text">
                    {planet.shot_discription}
                  </div>

                  <div className="button-for-cart-planet">
                    <div className="text-for-button">
                      <Link to={`/planet/${planet.id}`}>
                        Отправиться
                    </Link>
                    </div>
                  </div>
                </div>
                <div className="planeta">
                  <img src="../../img/planets_image/mars.png" alt="" />
                </div>
              </div>
            ))}
          </div>
        </div>
      </div>
    </div>
  );
};

I did it in php, but here is a dead end.
Pictures, I know, are imported from folders by name, but I don’t know how to apply it and how to implement the issuance of images from the database at all?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Steppp, 2021-04-28
@Steppp

Your project is running in the public folder. Index.html is also there. Look for photos from him

<img src={("./planets_image/" + planet.planet_image + ".png")} alt="" />

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question