Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Okay so what I am after for here is to check if a checkbox has been ticked, if it has, then I would like to add the text into a <ul> class named, let's say, "confirmed", so <ul class="confirmed">,
If it hasn't been checked, then I would add the text to a <ul> class named "unconfirmed". Now I have the php code that checks if the checkbox has been confirmed (seen below), but I don't know what to add inside the statements. This is where I need help/guidance.
PHP IF code (Check if checkbox is ticked):
<?php
if (isset($_POST["checkbox1"])){
//write to <ul> class confirmed
} else {
//write to <ul> class unconfirmed
}
?>
Here's my HTML Code:
<body>
<div id="content">
<div class="jumbotron">
<h1>Is there football on Wednesday?</h1>
<h2>Yes.</h2>
</div>
<div class="alert alert-info" role="alert">Confirmed Players</div>
<ul class="list-group">
<li class="list-group-item">
<!--this is where to result of the php code would go if the checkbox is checked-->
Lorem Ipsor
</li>
</ul>
<div class="alert alert-danger" role="alert">Unconfirmed Players</div>
<li class="list-group-item">
<!--this is where to result of the php code would go if the checkbox is not checked-->
Lorem Ipsor
</li>
</div>
<!--form-->
<form action="check.php" method="POST">
<input type="checkbox" name="checkbox1">
<input type="submit"></input>
</form>
</body>
Sorry if I seem to be confusing you, as I said, I'm not too well. Any help/guidance would be great!
Alright so when you tick a checkbox it should return a value through the $_POST which is 1 or 0 on submit. You may modify your template like this:
<?php
if ($_POST['checkbox1']) {
$class = 'confirmed';
}
else {
$class = 'unconfirmed';
}
?>
<body>
<div id="content">
<div class="jumbotron">
<h1>Is there football on Wednesday?</h1>
<h2>Yes.</h2>
</div>
<div class="alert alert-info" role="alert">Confirmed Players</div>
<ul class="list-group <?php echo $class; ?>">
<li class="list-group-item">
Lorem Ipsor
</li>
</ul>
<div class="alert alert-danger" role="alert">Unconfirmed Players</div>
</div>
<!--form-->
<form action="check.php" method="POST">
<input type="checkbox" name="checkbox1" />
<input type="submit" />
</form>
</body>
To be sure you can always var_dump the $_POST to see what is coming through in it and modify your if statement to be more accurate, it should return 1 or 0 iirc.
Without using AJAX you can try nesting php code like this:
<ul class="list-group">
<li class="list-group-item">
<?php
if (isset($_POST["checkbox1"])){
//write to <ul> class confirmed
}
?>
</li>
</ul>
<div class="alert alert-danger" role="alert">Unconfirmed Players</div>
<li class="list-group-item">
<?php
if (!isset($_POST["checkbox1"])){
//write to <ul> class unconfirmed
}
?>
</li>
Related
I am creating a module for Question and Answers and I need to fetch the data separatedly each.
I created a Tab where I'll click the Question I want to answers, and its children or the answer should match.
For visual reference, here is my problem
I have this data that are all fetched, which should not be. That is why I created Tabs and Pills so I can separate questions and answers
12 and 13 are the id number of each data
So in Tabs and Pills, I got this
The problem of this, is that I cannot fetch the data dynamically, it just shows ID 13 data for question and answer. How can I change this dynamically so I can click back and forth the tabs and show the right data by its id?
I need to fetch the ID 12 of the 1st Tab
So here is my view
<ul class="nav nav-tabs" role="tablist">
<?php foreach($questions as $question){ ?>
<?php echo $question->id; ?>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#<?php echo $question->id ?>" role="tab"><h4><?php echo $question->question ?></h4></a>
</li>
<?php } ?>
</ul>
<!-- Tab panes -->
<div class="tab-content">
<div class="tab-pane" id="13" role="tabpanel">
<div class="card" style="border:2px solid black;">
<div class="card-body">
<?php foreach($this->question_model->findAnswersByQuestion($question->id) as $answer){ ?>
<?php if($answer->type_id==0): ?>
<input type="radio" name="question_<?php echo $question->id; ?>" value="<?php echo $answer->answer ?>" required/>
<?php echo $answer->answer; ?><hr>
<?php endif; ?>
<?php if($answer->type_id==1): ?>
<div class="input-group input-group-lg">
<input type="text" class="form-control col-md-6" placeholder="Enter Answer" name="question_<?php echo $question->id; ?>" required/>
</div>
<?php endif; ?>
<?php } ?>
</div>
</div><br>
</div>
</div>
Fix the tabs structure, your looping over questions for nav-item, but not looping over for tab-pane which is why clicking the tab link does nothing.
<ul class="nav nav-tabs" role="tablist">
<?php foreach($questions as $question){ ?>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#tab-<?php echo $question->id ?>" role="tab"><h4><?php echo $question->question ?></h4></a>
</li>
<?php } ?>
</ul>
<!-- Tab panes -->
<div class="tab-content">
<?php foreach($questions as $question){ ?>
<div class="tab-pane" id="tab-<?= $question->id ?>" role="tabpanel">
<div class="card" style="border:2px solid black;">
<div class="card-body">
<?php foreach($this->question_model->findAnswersByQuestion($question->id) as $answer){ ?>
<!-- form input $answer / item -->
<?php } ?>
</div>
</div>
</div>
<?php } ?>
</div>
I've made a section in HTML, but I want to be visible only to people who are if($Admin >= 1) from my database.
But I don't know how to write it.
This is my HTML so far.
!-- ADM SECTION -->
<div class="backimg" id="section-10">
<div class="bghover wow fadeInUp" data-wow-duration="1.5s" data-wow-delay=".5s">
<div class="grid flex16">
<div class="row paddtop5">
<h3 class="paraw wow fadeInUpBig" data-wow-duration="2s" data-wow-delay=".5s">ADMIN SECTION</h3>
<div class="admin">
<h3 data-wow-duration="2s" data-wow-delay=".5s"> Alege opțiunea </h3>
</div>
<!-- ban -->
<style>
ul.b {list-style-type: square;}</style>
<div class="ban">
<ul class="b">
<li>BAN SYSTEM</li>
<br>
<li>KICK SYSTEM</li>
<br>
<li>ADMIN JAIL SYSTEM</li>
<br>
</ul>
</div>
<div class="ban2">
<ul class="b">
<li>SEARCH SYSTEM</li>
<br>
<li>LOG SYSTEM</li>
<br>
<li>AWARD SYSTEM</li>
<br>
</ul>
</div>
<div class="ban3">
<ul class="b">
<li>MANAGAMENT SYSTEM</li>
<br>
<li>UNBAN SYSTEM</li>
<br>
<li>UNJAIL SYSTEM</li>
<br>
</ul>
</div>
Shall I add if($Admin >= 1) echo ? I want to show nothing to who has $admin lower than 1. And who has higher or equal than 1, to show that HTML part.
<?php if($Admin >= 1) { ?>
<!-- ADM SECTION -->
<div class="backimg" id="section-10">
<div class="bghover wow fadeInUp" data-wow-duration="1.5s" data-wow-delay=".5s">
<div class="grid flex16">
<div class="row paddtop5">
<h3 class="paraw wow fadeInUpBig" data-wow-duration="2s" data-wow-delay=".5s">ADMIN SECTION</h3>
<div class="admin">
<h3 data-wow-duration="2s" data-wow-delay=".5s"> Alege opțiunea </h3>
</div>
<!-- ban -->
<style>
ul.b {list-style-type: square;}</style>
<div class="ban">
<ul class="b">
<li>BAN SYSTEM</li>
<br>
<li>KICK SYSTEM</li>
<br>
<li>ADMIN JAIL SYSTEM</li>
<br>
</ul>
</div>
<div class="ban2">
<ul class="b">
<li>SEARCH SYSTEM</li>
<br>
<li>LOG SYSTEM</li>
<br>
<li>AWARD SYSTEM</li>
<br>
</ul>
</div>
<div class="ban3">
<ul class="b">
<li>MANAGAMENT SYSTEM</li>
<br>
<li>UNBAN SYSTEM</li>
<br>
<li>UNJAIL SYSTEM</li>
<br>
</ul>
</div>
<?php } ?>
You can make use of SESSION variables in php. You can check for that value and put a if statement.
Where Admin will be one of the attributes for user in your user table.
If truthy show your html section.
if (isset($_SESSION['Admin'])) {
// show your content
}
Checking for Admin level:
if ($_SESSION['Admin'] >= 1) {
// show your content
}
You can use if else in html like so
<?php if ($Admin === 1) : ?>
<h1> show admin html </h1>
<?php else if ($Admin < 1) : ?>
<h1> do smth else </h1>
<?php else : ?>
<h1> do thmth else </h1>
<?php endif : ?>
In your html file, you can write down like this ,
<?php if ( $admin>=1 ): ?>
<div>
Here you can put all of your html
code for admin.
</div>
<?php endif;?>
A Lot of imporoments have to be done for the coding. Follow following steps.
Create a PHP file ex:index.php
Add all your HTML code within that PHP file.
Write following code for display this section.
Procedure 1.
<?php
if($Admin > 1) {
?>
//write your html code here.
<?php
}
?>
while($recor1=mysql_fetch_assoc($res1))
{
?>
<ul>
<li class="col-md-3 col-sm-3"><div class="dest-list"><?php echo $recor1['sub_destination']; ?></div> </li>
</ul>
<div class="clearfix"></div>
<?php
}
it displays the result horizontally i want it vertically please give me soluation
there are a number of things wrong with your code, why are you adding a new list for every item with only one list item, that makes no sense. Also do not add block elements inside inline elements (div inside a). Also if you what the list items under each other then why add the col-... class?
<ul>
<?php while($recor1=mysql_fetch_assoc($res1)) {?>
<li class="">
<a href="#">
<?php echo $recor1['sub_destination']; ?>
</a>
</li>
<?php } ?>
</ul>
this gives you the right html structure, and you can then style it as you see fit
if you dont want to display a list horizontally remove col-sm-3 class of your li, which changes your code like below
while($recor1=mysql_fetch_assoc($res1)) { ?>
<div class="col-md-3 col-sm-3">
<ul>
<li >
<a href="#">
<div class="dest-list">
<?php echo $recor1['sub_destination']; ?>
</div>
</a>
</li>
</ul>
</div>
<div class="clearfix"></div>
<?php
}
take a look at this example
Well, as the title says, I am not able to display the content in the tabs.
What I am doing is I am fetching the data from MySQL table and displaying it in tabs (successfully fetched).
What I am facing the problem is when the page is done with loading, I have to click one of the tabs in order to display all the contents of the tabs.
Here's the code for the tabs:
<div class="tabbable">
<ul class="nav nav-tabs">
<li class="active">
Description
</li>
<li>
Terms and Conditions
</li>
<li>
Returns and Cancellation
</li>
</ul>
<div class="tab-content">
<div class="tab-pane" id="description">
<p class="lead text-justify" style="margin: 10px 5px;">
<?php echo $descrip; ?>
</p>
</div>
<div class="tab-pane" id="terms">
<p class="lead text-justify" style="margin: 10px 5px;">
<?php echo $termsAndCond; ?>
</p>
</div>
<div class="tab-pane" id="returns">
<p class="lead text-justify" style="margin: 10px 5px;">
<?php echo $returnsAndCan; ?>
</p>
</div>
</div>
</div>
The data is displayed once clicked on either of the tabs from the code above. I don't know where I have made the mistake. Kindly help me out in rectifying it.
Thank You in advance.
Next to setting the Description tab active which you did by setting <li class="active"> you also have to set the Description tabs content active. I think you forgot to do this.
Add the class active to the first tab-pane, so change it from <div class="tab-pane" id="description"> into <div class="tab-pane active" id="description">.
See http://getbootstrap.com/javascript/#tabs for more documentation about Bootstraps tab component.
I am trying to read information from a css-styled web page and send it to a PHP script to be handled. However I can not figure how to do it.
This is the menu button located on the page
<ul class="vmenu">
<li> <span class="l"></span><span class="r"></span><span class="t">Group 1</span> </li>
<li> <span class="l"></span><span class="r"></span><span class="t">Group 2</span> </li>
</ul>...
and this is how I am trying to do it, but it changes it to a visible button and does not fit the styling.
<form name="sidemenu" action="index.php" method="post">
<ul class="vmenu">
<?php while (!empty($categoryname[$categointeger])) { ?>
<li> <input type="submit" name="categoryname" class="button" value="<?php echo"$cateid[$categointeger]"?>"></li>
<?php } ?>
</ul>
</form>
How can I read the information without touching the styling of the page and not using <a href="#">.