I want to display certain DIVs to certain users. To do that I have a column in phpMyAdmin, called “UserType” which indicates if the user is above or below 18. Based on that, if the user is below 18, I want to hide all DIVs with ID “18+”. Here’s an example of two different DIVs that contain products:
<div id="18+" class="content">
<a href= "pulpfiction.html"><img src="img/2.jpg" style="width:100%"></a>
<p>Pulp Fiction</p>
<p>£8.90</p>
<hr>
</div>
<div id="13+" class="content">
<a href= "blueexorcist.html"><img src="img/blueexorcist.jpg" style="width:100%;"></a>
<p>Blue Exorcist</p>
<p>£8.90</p>
<hr>
</div>
What I’m trying now is:
<?php
$userQuery = mysqli_query($con, $sql="SELECT UserType FROM users;");
$user = mysqli_fetch_assoc($userQuery); //gets user data as an array
?>
<script>
function toggleDivAdult(){
var x = document.getElementById("13+");
var y = document.getElementById("18+");
if ($user['UserType'] == 'M') { x.style.display = "none"; }
else if ($user['UserType'] == 'C') { y.style.display = "none"; }
</script>
‘M’ means mature user and ‘C’ means child
2
Answers
i just add “.adult” class and check it
The
forEach()
method executes a provided function once for each array element.The
call()
method calls a function with a given this value and arguments provided individually.Considering you are using phpMyAdmin and SQL, I would recommend you use PHP to decide which div is printed to the page.
Example: