I am trying to generate Tabs from 1st while loop and within that table from second while loop.
I will fetch the records date wise from my 1st table ie, treatment from that i am generating Tab, In another table called treatment_litems i have stored all the line items for treatment table records. So for 1st date (Tab) from treatment table, i want to display all the related records from treatment_litems in table format.
I am getting records but Tabs are not getting added, but everytime new Tabs are generating.
here is my code
<ul class="nav nav-tabs">
<?php $i=1; while($tt2 = mysqli_fetch_array($tt1)) { ?>
<li>
<?php echo $tt2['date']; ?>
</li>
</ul>
<div class="tab-content">
<div class="tab-pane fade active in" id="tab_1_<?php echo $i; ?>">
<?php $l1 = mysqli_query($con, "SELECT * FROM treatment_litems WHERE tid=".$tt2['tid'].""); ?>
<table class="table">
<thead><tr><th>Drugs</th><th>Route</th><th>Dosage</th></tr></thead>
<tbody>
<?php
while($l2 = mysqli_fetch_array($l1)) { ?>
<tr><td><?php echo $l2['drugs']; ?></td>
<td><?php echo $l2['route']; ?></td>
<td><?php echo $l2['dosage']; ?></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
<?php $i++ ; } ?>
</div>
Here is the image
**** EDITED ******
<ul class="nav nav-tabs">
<?php
while($tt2 = mysqli_fetch_array($tt1)) { ?>
<li>
<?php echo $tt2['date']; ?>
</li>
</ul>
<?php } ?>
<div class="tab-content">
<div class="tab-pane fade active in" id="tab_1_<?php echo $tt2['tid']; ?>">
This is my working code, you can get hints by this:
<div id="tabs" style="float:left">
<ul>
<?php $getlang=mysql_query("select * from language where Mid='$mid' and status='1' order by LanguageName asc");
if(mysql_num_rows($getlang)>0){
while($arr=mysql_fetch_array($getlang)){?>
<li><?php echo $arr['LanguageName']; ?></li>
<?php }}?>
</ul>
<?php $getlang=mysql_query("select * from language where Mid='$mid' and status='1' order by LanguageName asc");
if(mysql_num_rows($getlang)>0){
while($arr=mysql_fetch_array($getlang)){?>
<div id="tabs-<?php echo $arr['LanguageID'] ?>">
<input type="hidden" name="LanguageId[]" class="langID" value="<?php echo $arr['LanguageID']; ?>">
<input type="hidden" name="mid" value="<?php echo $mid; ?>">
<div class="rows">
<label>Notification Text</label><br/>
<textarea rows="3" cols="10" name="description[]" id="" maxlength="1000" style="width:700px; height:100px;" required="required"></textarea>
</div>
</div>
<?php } }
Check and do let me know.
Related
The final lists are looking like this and by clicking the green button I need to add class only to the list above. Only PHP is allowed
Click here
<ul class='wrapper'>
<?php foreach ($items as $item) : ?>
<li class="note" id='<?= $item['id'] ?>'>
<div class="details">
<p><?= $item['title']."<span class='currentDate'>".$item['currentDate']."</span>"?></p>
<p class ="importance"><?= $item['importance'] ?></p>
<div class="border"></div>
<span><?= $item['text'] ?></span>
</div>
<div class="bottom-content">
<span>Do: <?= date('d.m.Y', strtotime($item['date'])) ?></span>
<form method="post">
<button name="doneButton" value='<?= $item['id'] ?>' type="submit">ā
</button>
</form>
<?php
if(isset($_POST['doneButton'])) {
//
//
}
?>
<form method="post" >
<button value="<?= $item['id'] ?>" name="deleteButton" type="submit">šļø</button>
</form>
<?php
if(isset($_POST['deleteButton'])){
db_remove_note($_POST['deleteButton']);
header("Location: list-notes.php");
}
?>
</div>
</li>
<?php endforeach; ?>
</ul>
I want to add a class to li with the specific ID ($item['id']) using that doneButton. I need to use PHP only, with no JavaScript or MySQL.
Just add the condition to the li class attribute. Iād personally use a ternary operator as below to add MYNEWCLASS on the condition that $_POST['doneButton']) is set:
<li class="note<?=(isset($_POST['doneButton'])?" MYNEWCLASS":"");?>" id='<?= $item['id'] ?>'>
EDIT: To select an LI by a certain ID:
<?php
<ul class='wrapper'>
<?php foreach ($items as $item) : ?>
<?php
$class = ""; //Declare an empty $class
if (isset($_POST['doneButton']) && $_POST['doneButton'] == $item['id']){
// If $_POST['doneButton'] is set, and $_POST['doneButton'] is equal to the id of the current iteration then set $class to "MYNEWCLASS"
$class = " MYNEWCLASS"; //THE SPACE IS IMPORTANT
}
?>
<li class="note<?=$class;?>" id='<?= $item['id'] ?>'>
<div class="details">
<p><?= $item['title']."<span class='currentDate'>".$item['currentDate']."</span>"?></p>
<p class ="importance"><?= $item['importance'] ?></p>
<div class="border"></div>
<span><?= $item['text'] ?></span>
</div>
<div class="bottom-content">
<span>Do: <?= date('d.m.Y', strtotime($item['date'])) ?></span>
<form method="post">
<button name="doneButton" value='<?= $item['id'] ?>' type="submit">ā
</button>
</form>
<form method="post" >
<button value="<?= $item['id'] ?>" name="deleteButton" type="submit">šļø</button>
</form>
<?php
if(isset($_POST['deleteButton'])){
db_remove_note($_POST['deleteButton']);
header("Location: list-notes.php");
}
?>
</div>
</li>
<?php
endforeach;
?>
</ul>
I'm trying to create a dynamic content field where each data is in a separate accordion and am having a bit of trouble.
Result is the first accordion only works even i am having different id's for each accordion.
Can anyone help me on this
while ($row = mysqli_fetch_assoc($sql_result))
{
$i=1;
?>
<div class="container-fluid border">
<table width=100%>
<tr>
<td><img src="/images/vehicles/<?php echo strtolower($row['vtype']); ?>.jpg" width="75" heigth="75" alt=""></td>
<td align="center"><b><?php echo $row['vtype']; ?> A/C </b> - <?php echo $row['nos']; ?> Seater<br>
<b>ā¹ <?php if($duration=='8hrs') { $basefare=$row['8hrs']; } elseif($duration=='10hrs') { $basefare=$row['10hrs']; } else { $basefare=$row['12hrs']; } $base=$basefare+($basefare*5/100); echo number_format($base,2,".",","); ?> </b></td>
<td align="right">Book</td>
</tr>
</table>
</div>
<div id="accordionfare<?php echo $i; ?>">
<div class="card">
<div class="card-header" align="right">
<a class="card-link" data-toggle="collapse" href="#collapsefare<?php echo $i; ?>">Fare Details</a>
</div>
<div id="collapsefare<?php echo $i; ?>" class="collapse" data-parent="#accordionfare<?php echo $i; ?>">
<div class="card-body">
<p align="center"><b>Fare Details: </b>Base Fare: ā¹ <?php echo number_format($basefare,2,".",","); ?> | GST # 5%: ā¹ <?php echo number_format(round($base*5/100),2,".",","); ?> | Extra Hr Fare: ā¹ <?php echo number_format($row['extrahr'],2,".",","); ?>/Hr | Extra Km Fare: ā¹ <?php echo number_format($row['extrakm'],2,".",","); ?>/Km</p>
<?php $i++; ?>
</div>
</div>
</div>
</div><br>
<?php
}
?>
I've tested your code replacing your data and it works as expected. Check you PHP error log in case there are errors which might brake the loop in some way.
Here is a sandbox where you can Execute my test code and check the HTML result
P.S. You must have accordions with different ids in order to open each one separately.
I am getting the data in a view page. Now I want to search it with some data coming form a text box in the same view page.
What should I do? Can I use ajax or jQuery?
This is my view page
<li class="">Doctors</li>
</ol>
<div class="list col-xs-8">
<div class="col-md-8 col-md-offset-2">
<?php echo $this->session->flashdata('msg'); ?>
</div>
<ul>
<input type="text" name="search_data" placeholder="Search ..." class="form-control" id="search_data" onkeyup="ajaxSearch();"style=" height: 50px; width: 200px !important;">
<?php
if(isset($doc)):
foreach ($doc as $row):
?>
<li>
<div class="imgt"><img src="<?php echo base_url("./resources/images/"); if($row->dr_img) echo $row->dr_img;
else echo "no-img.jpg"; ?>" height="90px" width="82px">
</div>
<div class="text">
<h3><b>Dr. <?php echo $row->dr_name;?></b><br></h3>
<p><?php echo $row->spec_specialise; ?><br><?php echo $row->district;?><br><?php echo $row->state;?></p>
</div>
<div class="text"></div>
<div class="link">
<i class="ace-icon fa fa-eye sym"></i>View</div>
</li>
<?php endforeach;
endif;
?>
</ul>
<div class="space"></div>
</div>
</div>
<div class="pdt_rightt">
<center>
</center>
</div>
In the title of your post you say you want to "sort" the data, but in the description you say you want to "search" it.
I would recommend doing this without Ajax to begin with to get an understanding of the fundamentals.
Your View could look like this:
<?php echo form_open( current_url() ); ?>
<h2>Search</h2>
<input type="text" name="search" placeholder="Enter search word" />
<button>Search</button>
<?php echo form_close(); ?>
<?php if (isset($docs)) : ?>
<p>
<a href="<?php echo current_url(); ?>?sort=dr_name&search=<?php echo html_escape( urlencode( $search ) ); ?>">
Sort by name
</a>
</p>
<ul>
<?php foreach ($docs as $row) : ?>
<li><?php echo html_escape( $row->dr_name ); ?></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
Then your Controller would be like this:
public function index() {
$search = $this->input->get_post('search');
$sort = $this->input->get('sort');
$docs = $this->doc_model->get_docs( $search, $sort );
$data = array(
'search' => $search,
'sort' => $sort,
'docs' => $docs
);
$this->load->view('docs', $data);
}
Your Model will then need to fetch all Doctors if $search is null, or query the Doctors' names by $search if it's not null. Likewise if $sort is null then you'd order by a default field (date created for example).
If you have lots of results then you'd also want to look at CI's Pagination class to span the results over several pages.
You can achieve all of this using Ajax but if you have lots of results you are still going to need to call your Controller and Model, similar to the above, to do the heavy lifting.
I have a page called MemberArea.php that use bootstrap tab to change its content according to div id.
<div id="tabs-1" class="tab-pane fade in active">
<div class="tabbable tabs-left">
<br />
<ul class="nav nav-tabs" id="maincontent" role="tablist">
<li class="active"><a data-toggle="tab" href="#tabs-5" role="tab">Basic Information</a></li>
<li><a data-toggle="tab" href="#tabs-6" role="tab">View Team</a></li>
</ul>
<div class="tab-content">
<div id="tabs-5" class="tab-pane active">
<?php include("information.php"); ?>
</div>
<div id="tabs-6" class="tab-pane">
<?php include("viewTeam.php"); ?>
</div>
<div id="tabs-14" class="tab-pane">
<?php include("EditSinging.php"); ?>
</div>
<div id="tabs-15" class="tab-pane">
<?php include("EditSpeech.php"); ?>
</div>
<div id="tabs-16" class="tab-pane">
<?php include("EditStory.php"); ?>
</div>
</div>
</div>
In ViewTeam, it's to display all registered team
<?php
$query="select * from etj12singing where etj12id=$id AND etj12Pay ='Yes' ";
$result =mysql_query($query);
while($row= mysql_fetch_array($result))
{
$SIidnumber=$row['etj12idnum'];
$SIidtype = $row['etj12idtype'];
$SIfullName = $row['etj12fullname'];
$SIgender = $row['etj12gender'];
$SIemail = $row['etj12email'];
$SIphone = $row['etj12phone'];
$SIvege = $row['etj12vege'];
$SIpay = $row['etj12Pay'];
$SIidsinging = $row['etj12idsinging'];
?>
<tr>
<td><?php echo $SIidnumber; ?></td>
<td><?php echo $SIidtype; ?></td>
<td><?php echo $SIfullName; ?></td>
<td><?php echo $SIgender; ?></td>
<td><?php echo $SIemail; ?></td>
<td><?php echo $SIphone; ?></td>
<td><?php echo $SIvege; ?></td>
<td><?php echo $SIpay; ?></td>
<td>
<a data-toggle="tab" href="?idSIE=<?php echo $SIidsinging; ?>#tabs-14" role="tab">
<input type="submit" value="Edit" class="btn-warning"/>
</td>
</tr>
My problem is I cannot pass the value to tabs-14(EditSinging.php)
Here is how i get the value in tabs-14(EditSinging.php)
$idsinging=$_GET['idSIE'];
UPDATE
Here is the code in EditSinging.php
PHP :
$idinst = $_SESSION['id'];
$idsinging=$_POST['idSIE'];
$query = "SELECT * FROM etj12singing WHERE etj12id=$idinst AND etj12idsinging=$idsinging";
$result = mysql_query($query);
if($row=mysql_fetch_array($result))
{
$idNum = $row['etj12idnum'];
$idtype = $row['etj12idtype'];
$fullname = $row['etj12fullname'];
$gender = $row['etj12gender'];
$email = $row['etj12email'];
$phone = $row['etj12phone'];
$vege = $row['etj12vege'];
}
Below is the form to edit the value that i got from the query above
<table style="width:100%;height:auto;border-spacing:10px;border-collapse:separate">
<tr>
<td>Id Number<br/>
<span style="font-style:italic;">(Nomor Identitas)</span>
</td>
<td>
<input type="text" id="IdNumber" name="IdNumber" value="<?php echo $idNum; ?>" class="textbox_register"/>
<input type="hidden" name="idSIC" value="<?php echo $idsinging; ?>" class="textbox_register"/>
<br/><label id="err1" class="error"></label>
</td>
</tr></table>
In your ViewTeam file the query:
$query="select * from etj12singing where etj12id=$id AND etj12Pay ='Yes' ";
this content ($id) witch not defined in file;
you must give the string (id) a value.
so your query return null results.
I think this is the problem you have.
I have two tables listed (on screen) in PHP and the left should be hyperlinked so when click on it the right table will show a query. So at the beginning it should be empty then when clicked refresh the page with the selected listname's result.
unfortunately I have no experience with these things so i don't know the concept of it yet, but I am happy to learn:)
<form method="post" action="test.php">
<div id="left"><table>
<?php
$left="SELECT * FROM groups";
$resultleft=mysql_query($left);
while ($resultleft=mysql_query($left)) {
echo "<tr><td>".$left['id'].'</td><td>'.$left['listname']."</td></tr>";
}
?>
</table></div>
<div id="right"><table>
<?php
$right="SELECT * FROM grouplink WHERE grouplink.group_id= ";
$resultright=mysql_query($right);
while ($resultright=mysql_query($right)) {
echo "<tr><td>'.$right['people_name']."</td></tr>";
}
?>
</table></div>
<?php
if (isset($_POST('???'))){
echo "<meta http-equiv=\"refresh\" content=\"0;URL=test.php\">";
}
?>
</form>
any help would be appreciated
Can for example link to table.php?gid=n, where n would be the group id. You can then check if $_GET['gid'] isset, and if it is, take that id and put it in your query.
if(isset($_GET['gid']))
$right = sprintf("SELECT * FROM grouplink WHERE grouplink.group_id=%u", $_GET['gid']);
You need mysql_fetch_assoc
instead of mysql_query
in:
while ($resultleft=mysql_query($left)) {
echo "<tr><td>".$left['id'].'</td><td>'.$left['listname']."</td></tr>";
}
and also in:
$resultright=mysql_query($right);
while ($resultright=mysql_query($right)) {
echo "<tr><td>'.$right['people_name']."</td></tr>";
so this will be:
while ($left=mysql_fetch_assoc($resultleft)) {
echo "<tr><td>".$left['id'].'</td><td>'.$left['listname']."</td></tr>";
}
and similar issue with right
Thanks to Svish here is my new working code:
<?php include("db_con1.php");?>
<html>
<head>
</head>
<body>
<form method="post" action="test.php">
<div id="left">
<?php
$queryl = $pdo->prepare('SELECT id, name FROM test1 ORDER BY name ASC');
$queryl->execute();
?>
<ul>
<?php foreach ($queryl as $i => $rowl) { ?>
<li>
<?php if ($i)?>
<input name="checkbox_add[]" id="test_<?php echo $i ?>" type="checkbox" value="<? echo $rowl['id']; ?>"/>
<label for="test_<?php echo $i ?>"><?php echo $rowl['name']; ?></label>
</li>
<?php } ?>
</ul>
</div>
<div id="right">
<?php
if(isset($_GET['gid'])) {
$gid=$_GET['gid'];
$queryr = $pdo->prepare('SELECT test3.name FROM test1, test2, test3 WHERE test1.id=test2.groupid AND test3.id=test2.peopleid AND test1.id='.$gid.' ORDER BY test3.name ASC');
$queryr->execute();
}
?>
<ul>
<?php foreach ($queryr as $i => $rowr) { ?>
<li>
<?php if ($i)?>
<input name="checkbox_del[]" id="test_<?php echo $i ?>" type="checkbox" value="<? echo $rowr['id']; ?>"/>
<label for="test_<?php echo $i ?>"><?php echo $rowr['name']; ?></label>
</li>
<?php } ?>
</ul>
</div>
</form>
</body>
</html>