I have an array containing attributes of each store (this is just the first few kv pairs, there're 100 in total)
Array
(
[0] => Array
(
[id] => 1
[name] => 21st Century Fox 3
[category_id] => 1
[created_time] => 2018-06-03 11:01:54Z
[featured] => FALSE
)
[1] => Array
(
[id] => 2
[name] => 21st Century Fox 5
[category_id] => 1
[created_time] => 2021-05-02 11:22:04Z
[featured] => FALSE
)
[2] => Array
(
[id] => 3
[name] => Carrefour 3
[category_id] => 1
[created_time] => 2018-10-20 22:28:48Z
[featured] => FALSE
)
[3] => Array
(
[id] => 4
[name] => Coca-Cola Company 2
[category_id] => 1
[created_time] => 2020-09-19 19:14:29Z
[featured] => FALSE
)
[4] => Array
(
[id] => 5
[name] => Erickson
[category_id] => 1
[created_time] => 2021-01-23 00:58:07Z
[featured] => FALSE
)
[5] => Array
(
[id] => 6
[name] => Boeing 1
[category_id] => 2
[created_time] => 2019-11-26 11:17:17Z
[featured] => FALSE
)
and a select box (attribute name="letter-start") with each option as a character in the alphabet.
The goal is when I choose from the select box, it will display only the stores whose names are similar to that letter from the select option. For example, I choose "A" and it will only display the stores with [name] starting with A:
Array
(
[0] => Array
(
[id] => 12
[name] => AECOM 1
[category_id] => 3
[created_time] => 2020-12-29 12:57:25Z
[featured] => FALSE
)
[1] => Array
(
[id] => 20
[name] => Areon Impex 1
[category_id] => 3
[created_time] => 2019-11-09 22:43:32Z
[featured] => TRUE
)
[2] => Array
(
[id] => 21
[name] => Amazon.com 2
[category_id] => 4
[created_time] => 2019-10-19 21:30:39Z
[featured] => FALSE
)
Here's what I tried:
echo "<div class=\"flex-container\">";
$selected = $_GET['first-letter'];
foreach ($stores as $s) {
if ($selected === $s['name'][0]) {
$id = $s['id'];
$name = $s['name'];
//display the stores
echo "<div class=\"item\"><a href=\"store-home.php?id=$id\"><div class=\"image\"><img src=\"images/store.png\" alt=\"a store\"></div><h3 class=\"name\">$name</h3></a></div>";
}
}
echo "</div>";
But it doesn't receive the $_GET or $_POST value. You can refer to the full store list here and the function to read and store all data into array $stores here.
Edit: here's the select box
<form action="browse-store-1.php">
<label for="letter-start">Store names start with letter </label>
<select id="letter-start" name="letter-start">
<option id="all">All</option>
<option id="#" value="#">#</option>
<option id="a" value="A">A</option>
<option id="b" value="B">B</option>
<option id="c" value="C">C</option>
<option id="d" value="D">D</option>
<option id="e" value="E">E</option>
<option id="f" value="F">F</option>
<option id="g" value="G">G</option>
<option id="h" value="H">H</option>
<option id="i" value="I">I</option>
<option id="j" value="J">J</option>
<option id="k" value="K">K</option>
<option id="l" value="L">L</option>
<option id="m" value="M">M</option>
<option id="n" value="N">N</option>
<option id="o" value="O">O</option>
<option id="p" value="P">P</option>
<option id="q" value="Q">Q</option>
<option id="r" value="R">R</option>
<option id="s" value="S">S</option>
<option id="t" value="T">T</option>
<option id="u" value="U">U</option>
<option id="v" value="V">V</option>
<option id="w" value="W">W</option>
<option id="x" value="X">X</option>
<option id="y" value="Y">Y</option>
<option id="z" value="Z">Z</option>
</select>
</form>
when I choose from the select box, it will displayHow do you fetch the data ?. Share that code