.Toggle function with php on mobile
I've made notes in the code below, on my mobile site I would like to hide information unless a user taps on the name. There will be anywhere from 3 to 100 "Names" on the screen at a time depending on what the user is searching for, and each one will need to have information hidden until the name is tapped. This should be a simple toggle, however, each line item is being dynamically pulled from a database so I can't hard code the toggle function. Any thoughts on how I could fix this?
- //I've cut down the code for the sake of ease of reading.
- //Set Mobile CSS
- $iphone = strpos($_SERVER['HTTP_USER_AGENT'],"iPhone");
- $android = strpos($_SERVER['HTTP_USER_AGENT'],"Android");
- $blackberry = strpos($_SERVER['HTTP_USER_AGENT'],"BlackBerry");
- $ipod = strpos($_SERVER['HTTP_USER_AGENT'],"iPod");
-
- if ($iphone || $android || $ipod || $blackberry)
- {
- $mobile = TRUE;
- $namecss = "mobileName";
- }
- else {
- $namecss = "Name";
- }
- //Loop through database
- while($row = mysql_fetch_array($result)){
- if ($mobile) {
- $fullname = $row['title'] . $row['name'];
- //Show the name
- echo "<div id='" . $namecss . "' class='" . $align . "'>[" . $row['title'] . "] " . $row['name'] . "</div>";
- //Make script to toggle() the hidden layer
- echo "<script>$( '#" . $namecss ."' ).click(function() { $( '#" . $fullname . "' ).toggle();});</script>";
- //hidden layer
- echo "<div id='" . $fullname . "'>" . $row['price'] . "</div>";
- }
- }