How do I display a single entry from an array from MYSQL
This works ...
How do I display just the entry with PID value of "5" from the array?
19 Replies
alternatively if you really have to do it in PHP:
I need the whole database in the array
I am then dynamically changing data on the screen
the if-statement I added would leave the array alone, but only print out info if
$pic['PID']
is 5oh right, i thought there would be an easier way like echo $pix[5, 'PID'];
5 being the 5th entry in the array
you can't guarantee the one with PID 5 will always be the fifth one though
so $pix[5,'title'] would be the title of the 5th entry
if all you want is the fifthsixth element, you can just do
$pix[5]['PID']
thoughahhhhh cool, it was getting the format correct 🙂
and remember arrays are 0-indexed, so 0 is the first element
just remember that there's no direct relation to a field in the database and the index of the array. If PID 2 is ever missing, all of a sudden you're getting the wrong element if you really need PID 5
oh yea, but PID was an example of being specific
i am listing titles in a <select> and when an option changes I want to display the elements for that opion
option*
when an option is selected, not changed
well, the syntax is like I said if you want to access elements inside an array, and you can chain the square brackets to go deeper if you have deeper arrays 🙂
Thank you kindly sir, that works a treat 🙂
no worries 🙂
if I know the title, can I display the corresponding data?
so if I have a picture called "Scream" ... would $pix['Scream']['filename'] work
oh wait, you think $pix[5]['PID'] filters the array and finds a record that has 5 as value for the PID?
what it's doing is accessing the $pix array, taking the sixth (starting from 0, 5 is the sixth element) element, and returning that. ['PID'] then gives you the value for that element's PID key
so no, $pix['Scream']['filename'] doesn't filter for elements with filename scream, it would try to take the 'Scream' element from the pix array, and then the filename element from that Scream array
i understand that $pix[5]['PID'] is taking the 6 line of the array
i was just wondering if i could use actualy data to find other data
actual*
so to find the date of when the picture "Scream" was posted for example
the result from
fetch_assoc
would contain indexed rows, and the rows themselves would have named keys, so no, $pix['Scream'] wouldn't work without some manipulation of the result from mysqlok, i understand, thank you
so my best bet is to simply put the array value in the <option> and use that 😉
so this works beautifully, thank you so much 🙂
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View