In general, at present, pure php reads data from the database and generates an html page with a table. In the table there is a BLOB field with a picture for each row, it will be displayed in a tooltip when you move the mouse over the table and change on each row. Naturally, loading is not an option. I think, do I need to load as needed? What is the best way to do this? (I understand that just html is not enough here, can js deal with it or what technologies are used for such dynamic purposes?) And I would like to make a table in the future, filter by all fields ...

PS: Correct the question, I do not know how to formulate it more precisely

  • @Visman, I agree. But I'm still interested to see what you can "squeeze" with this approach. Let's say it will work locally and we do not think about traffic. How much "friendly" will it look when booting from the database or will there be strong glitches and nothing can be done about it? It's just more convenient for me to have everything in one file. - Isaev
  • I keep pictures in the database - I did not observe any problems - Anton Shchyrov

1 answer 1

Write some kind of script

// image.php function process(): bool { $id = $_GET['id'] ?? ''; if (!is_numeric($id)) return false; $sql = <<<'SQL' SELECT ph.`photo`, typ.`name` FROM `photos` ph LEFT JOIN `mime_types` typ ON ( ph.`mime_type_id` = typ.`id` ) WHERE ph.`id` = ? SQL ; } $db = new db(); $stmt = $db->prepare($sql); $stmt->bind_param('i', $id); $photo = ''; $mime = ''; $stmt->bind_result($photo, $mime); $stmt->execute(); if (!$stmt->fetch()) return false; header('Cache-Control: public'); header(sprintf('Content-type: %s', $mime)); header('Content-Transfer-Encoding: binary'); header('Content-Length: ' . strlen($photo)); echo $photo; return true; } if (!process()) header($_SERVER['SERVER_PROTOCOL'] . ' 400 Bad Request'); 

When moving the mice show

 <img src="image.php?id=XXX" /> 

where instead of XXX id you need a picture.

Of course, you do not show right away when the mouse moves, but with a delay, in case the user changes his mind and removes the mouse.

  • one
    Edak and DB server can be easily reloaded by creating a simple script for searching IDs from zero to ~ ... - Daniel Protopopov
  • @Anton Shchyrov, But surely, img can give out a separate php ... Something I did not even think in this direction. All ingenious is simple! Thanks, as I will try, I will unsubscribe ) - Isaev
  • @Daniel Protopopov, in my case it is not relevant, but to see your proposal in the light of this observation would not be superfluous) - Isaev
  • 2
    If you still need to store their images in the database, then you can make the image identifier not just an integer, but a uuid. In the example above, it will protect against brute force by id + 1. And use the database query cache. But when storing images in the database, its size will grow very strongly - RaZik
  • @RaZik size is not scary. I have 200 records there and two times more will not be very soon ... There will be 2-3 pictures for each record ... Not deadly! At the expense of "use the query cache" can be more? - Isaev