Skip to content

u/ReasonFighter

In this archive from Nov 2017 to Dec 2023

0
posts
6
comments
0
media
12
score

Top comments

It kind of feels like you are asking to the wrong forum. Maybe go to a Python forum and ask there? This is the PHP forum, which exists for those of us who think PHP is the right language for the job. Asking here if you should change to a different language is like going to a Ford dealership to ask them if you should buy a Chevrolet car...

5 points

There are two easy approaches to this:

  1. Do it all in the browser.
    a) Retrieve all the data for all your horses (including image urls) from PHP.
    b) Store all that data in a javascript array of horse records.
    c) Program your page's javascript such that, when a horse is selected from your select element, the horse's data is retrieved from your javascript array of horse records, which includes its image's url.
    d) Then you can display that image wherever you want.

  2. Use Ajax.
    a) Your initial PHP remains the same.
    b) Add an "onchange" event to your select element such that, when a user selects a new horse, a javascript function is invoked.
    c) In that function, perform an Ajax call to a (new) PHP script on your server, passing along the selected horse's id (or name, or unique identifier).
    d) That new PHP script will receive the selected horse's identifier, retrieve that horse's data from the database and return that data to the javascript function that performed the call.
    e) Your javascript function, then, can display the selected horse's data (including its image) wherever you want.

Both methods have advantages and disadvantages, but both work perfectly and are valid. Some considerations are:

  • If you are dealing with a couple dozen horses, the first method might be quicker for you. If your database contains thousands of them though, having your javascript dealing with huge amounts of data might slow down the page.
  • If you are dealing with a couple dozen horses, the second method might be unnecessarily demanding, because Ajax entails performing additional online requests to your server. If your database contains thousands of records though, Ajax is a much better approach because it makes your page load faster and react faster to user interactions.

As /u/gonatee said, you want to learn Ajax regardless of which approach you take. Ajax is a very useful approach to data transportation on the internet used by virtually everybody nowadays from blogs to banks.

2 points

Subreddits

Keyboard shortcuts

Move and act

jork
Next / previous post or comment
Enteroro
Open the post
f
Open the media viewer
s
Save
h
Hide (the toast has Undo)
Tab
Right after an action: the toast's Undo
x
Collapse the comment
v
Next layout: cards, compact, grid

Go to

/
Search
gthenh
Home
gthena
All
gthens
Subreddits
gthenl
Library
?
This list
Esc
Close a menu or this list

In the viewer

←or→
Previous / next file
↑or↓
Previous / next post
korj
Previous / next post
Space
Play / pause
m
Mute
z
Zoom
s
Save
o
Open the post (on its own page: back to it)
Esc
Close

Keys do nothing while you type in a box.