Hi all i have one table there i need to display the course report so every course has one stage so that i have 16 types of stages ex: On Hold,Asset Incomplete,SME Discussion..etc..Like 16 types i have So i would like to display 16 types in mt td column
<table class="table table-bordered">
<thead>
<tr><th class="center">#</th>
<th class="center">PHY</th>
<th class="center">CHE</th>
<th class="center">ZOO</th>
<th class="center">BOT</th>
<th class="center">MATH</th>
<th class="center">Total</th>
</TR>
</thead>
<tbody>
<tr>
<td>On Hold</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td>
</tr>
</tbody>
</table>
Remaining td's i have to get count of every course and to display
Can anyone help me how can i do that.
Thanks in advance.
You can do it by taking all your static string as an associative array for example
$arr = array(0=>'On Hold',1=>'Asset Incomplete',2=>'SME Discussion');
and your td should be
<?php $i = 0;
foreach($data as $dt){ ?>
<td><?php echo $arr[$i]; ?></td>
<?php $i++; } ?>
If you want to pass a variable from your controller to your view, you do so in the $data variable.
//Controller
$this->load->model('mymodel);
$data['var1'] = "Some value";
$data['var2'] = "Some value";
$data['query'] = $this->mymodel->thefunction();
//Model = mymodel
//function = thefunction(), you have to obviously create the class and function, if you don't know how to do that, let me know
$sql = "SELECT Count(courseid) as 'statusCount'";
$query = $this->db->query($sql);
When you now want to display those variables in your view template, call the variable by it's name, without the "$data part"
//In your view
<?php
foreach($query->result() as $row) {
echo "<td>" . $row->statusCount . "</td>";
}
?>
Please set the array with two fields.
One for Id,another for course name.
Then use forech() for write <td> in view.html.
For example:
forech($array as $item){
echo('<td><a href="ProjectView.php?course_id=".$item["id"]>$item["name"]'</a></td>') ;
}
Related
After succeeding to input new table inside a key in php firebase, now i want to display the result.
I've tried using this
<table>
<tr>
<th>Course Code</th>
<th>Discriptive Title</th>
<th>Unit</th>
<th>Pre-Requisite</th>
<th>Grade</th>
</tr>
<?php
include('dbcon.php');
if(isset($_GET['id']))
{
$key_child = $_GET['id'];
$ref_table = 'User/'.$key_child.'/Grades/1st Year/1st Sem';
$row = $database->getReference($ref_table)->getChild($key_child)->getChild($key_child)->getValue();
if($row > 0 )
{
?>
<tr>
<input type="hidden" name = "id" value = "<?=$key_child;?>">
<td><?=$row['Course_Code']; ?></td>
<td><?=$row['Desc_title']; ?></td>
<td><?=$row['Unit']; ?></td>
<td><?=$row['Pre-Req']; ?></td>
<td><?=$row['Grade']; ?> </td>
</tr>
<?php
}
}
else
{
?>
<td colspan = "5"> No Record found </td>
<?php
}
?>
</table>
but the result was blank instead of returning "No Record found" as stated in the else code
I am trying to display the result from this grandchild table:
here are the href codes that will lead to the blank table if knowing it would help solve the problem
View
this link below will be the one that leads to the above table that doesnt work
samplegrades
after having found the data in a table the function displays the information without missing, with a td tag only the first word which displays the others after the space are not displayed.
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>Service </th>
<th>Prix</th>
<th >Quantite</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
$reqq = "SELECT * FROM service WHERE client = '$clientId' AND dossier = '$dossier' ";
$results = $connect->query($reqq);
?>
<?php if($results->num_rows > 0){ ?>
<?php
foreach($results as $data){ ?>
<?php echo $data['nom']; ?>
<tr>
<td> <?php print $data['nom']; ?>
<td><?= $data['prix']?></td>
<td><?= $data['quantite']?></td>
<td>Supprimer</td>
</tr>
</tbody>
</table>
the result is
Inside the table the last field have Franchise Procedure the table only display the first word which is Franchise
Help me find the solution please.
Try with:
<td> <?php echo htmlspecialchars($data['nom']); ?> </td>
Often, text stored in databases can contains reserved characters in HTML like "<" or "&" which should be replaced by html entities
That's what the PHP function htmlspecialchars was invented for.
I am calling a for loop to get data from database with this code which is working fine but only with one problem
<table class="table" style="color:#000 !important;">
<tbody>
<tr>
<th>Question</th>
<th>User Answer</th>
</tr>
<tr>
</<?php
for ($x = 0; $x <= 30; $x++) {
?> <td><?= $info['ans_' . $x]; ?></td>
</tr>
<tr>
<?php
$sales_quiz = mysqli_query($conn_quiz, "SELECT * FROM `sales_quiz` where `que_no` = '$x'");
$sales_que = mysqli_fetch_array($sales_quiz); ?>
<td><?= $sales_que['que']; ?></td>
<?php }; ?>
</tr>
</tbody>
</table>
The result is first td of 2nd data which is que is blank and for loop start counting it from 2nd row
I do create a separate for loop for question and answer but then the table becomes broken.
If you need new rows in a table for every loop then you need to add the tr within the loop.
Also all tds that need to be on the same row has to be within one tr.
So remove the extra <tr> and bring them inside the loop.
<table class="table"
style="color:#000 !important;">
<tbody>
<tr>
<th>Question</th>
<th>User Answer</th>
</tr>
<?php
for ($x = 0; $x <= 30; $x++) {
?>
<tr>
<td><?= $info['ans_' . $x]; ?></td>
<!-- </tr> Remove these-->
<!-- <tr>-->
<?php
$sales_quiz = mysqli_query($conn_quiz, "SELECT * FROM `sales_quiz` where `que_no` = '$x'");
$sales_que = mysqli_fetch_array($sales_quiz);
?>
<td><?= $sales_que['que']; ?></td>
</tr>
<?php
} # the semi-colon (;) at the end is unnecessary
?>
</tbody>
</table>
You need to move your </tr><tr> to after the last td, and probably swap your $info['ans_'.$x]; and $sales_que['que']; since it seems like it should go question then answer, and the variable names make me think you are doing answer then question.
<table class="table" style="color:#000 !important;">
<tbody>
<tr>
<th>Question</th>
<th>User Answer</th>
</tr>
<tr>
<?php
for ($x = 0; $x <= 30; $x++) {
?> <td><?= $sales_que['que']; ?></td>
<?php
$sales_quiz = mysqli_query($conn_quiz, "SELECT * FROM `sales_quiz` where `que_no` = '$x'");
$sales_que = mysqli_fetch_array($sales_quiz); ?>
<td><?= $info['ans_'.$x]; ?></td>
</tr>
<tr>
<?php }; ?>
</tr>
</tbody>
</table>
I think it might be the "</" in the 10th line of your code, before the first <?php . There is any reason for that "</" to be there? From my perspective that creates a empty <tr></tr> on the resultant html file, and thats why you have that empty cell on your table. I might be wrong, just check it out and tell me if it works.
i'm new on using codeigniter, i want to ask how to make dynamic table so when i select data from anytable form database it can be fit with the table, even the field is different.
so, in normally i show table like this :
<table class="table table-striped">
<thead>
<tr>
<th scope="col">#Number</th>
<th scope="col">Field</th>
</tr>
</thead>
<tbody>
<?php
$no = 1;
foreach ($data as $row) {?>
<tr>
<th scope="row"><?php echo $no++?></th>
<td><?php echo $row->COLUMN_NAME ?></td>
</tr>
<?php } ?>
</tbody>
</table>
but the problem when i using 3 field or more field it can't be fit, so any suggestion for it?
Your problem:
You are fetching data from database.
And want to display it in table but, not sure how many columns are there.
Solution:
Say, you have a multi-dimensional array with n records.
First get the first element (which is a database row, a table row)
Get count of it.
Now loop over the array.
Use foreach() language construct.
It will take care of every thing.
Note: This solution assumes that the individual array (database records) are having same number of columns.
<?php
if (! empty($arr)) {
foreach ($arr as $elem) {
?>
<tr>
<?php
if (! emtpy($elem)) {
foreach($elem as $td) {
?>
<td><?php echo $td;?></td>
<?
}
}
</tr>
<?
}
}
Here's the thing. I'm trying to sort my Comics collection. So far, I have two tables, one for the titles and type of comics (ID, prefix, title, type) and another one with individual information for each issue (ID, title, volume, issue number, value).
First thing I do is associate the title from the issues with the appropriate titles from the title table.
I do something like that:
SELECT * FROM comics, comicstitles WHERE comics.comTitle = comicstitles.titID ORDER BY comicstitles.titTitle ASC
What I get is a neat bunch of rows that I organize, and I get results like:
<table class='simple-list'>
<thead>
<tr>
<th>Title</th>
<th>Volume</th>
<th>Issue</th>
<th>Value</th>
</tr>
</thead>
<tbody>
<tr>
<td>Alpha Flight</td>
<td>1</td>
<td>1</td>
<td>$4.00</td>
</tr>
<tr>
<td>Alpha Flight</td>
<td>1</td>
<td>2</td>
<td>$3.00</td>
</tr>
<tr>
<td>Machine Man</td>
<td>2</td>
<td>1</td>
<td>$2.00</td>
</tr>
<tr>
<td>Wolverine</td>
<td>1</td>
<td>2</td>
<td>$35.00</td>
</tr>
<tr>
<td>Wolverine</td>
<td>1</td>
<td>1</td>
<td>$60.00</td>
</tr>
<tr>
<td>The X-Men</td>
<td>1</td>
<td>115</td>
<td>$100.00</td>
</tr>
<tr>
<td>The X-Men</td>
<td>1</td>
<td>116</td>
<td>$100.00</td>
</tr>
<tr>
<td>The X-Men</td>
<td>1</td>
<td>111</td>
<td>$100.00</td>
</tr>
<tr>
<td>The X-Men</td>
<td>1</td>
<td>114</td>
<td>$100.00</td>
</tr>
<tr>
<td>The X-Men</td>
<td>1</td>
<td>109</td>
<td>$160.00</td>
</tr>
<tr>
<td>The X-Men</td>
<td>1</td>
<td>112</td>
<td>$100.00</td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan='4'><h3>Total: $764.00</h3></td>
</tr>
</tfoot>
Now, what I would like to do is a foreach, which would give me something like:
For each title, print the title once and all the individual issues underneath.
I would end up with something like:
TITLE
Issue number
Cover
Issue number
Cover
TITLE
Issue number
Cover
TITLE
Issue number
Cover
Issue number
Cover
Issue number
Cover
Issue number
Cover
I tried looking over and over, but I always end up on Wordpress, Joomla or Drupal sites.
And any other results is either WAY too abstract or uses numbers.
You can easily group the items visually by title by keeping track of the title and comparing it to the current one.
Something like (simple example):
// before your loop
$title = '';
// in your loop
if ($row['title'] === $title) {
// title already shown, do nothing or echo an
} else {
// new title, set and print it
$title = $row['title'];
echo htmlspecialchars($title);
}
You don't mention covers anywhere, so it's impossible to help with that until you've tried it, show the code and what the exact problem is.
There are several approaches for what you are trying to do. One approach is you also read the comic-id and then you "for-each" the result and put them in an array with the ID as Array-Index.
foreach ($rows as $row)
$arr[$row['titID']][] = $row;
If you do NOT have the need for further use of the data, you could just do
$active_id = $titID;
foreach ...
//if the current eached title-id has changed (not = $active_id)
//then set $active_id = new-title-id and start a new row
You could have an array in which each title has an array for itself.
$titles = array();
while ($row == $result->fetch_assoc()) {
if (array_key_exists($row['Title'], $titles)) {
array_push($titles[$row['Title']], $row);
}
else {
$titles[$row['Title']] = array($row);
}
}
foreach ($titles as $title=>$rows) {
echo $title . '<br>';
foreach ($rows as $row) {
echo $row['IssueNumber'] . '<br>' . $row['Cover'] . '<br>';
}
}
//Database Connection
mysql_connect("localhost", "username", "password") or die(mysql_error());
//Database selection
mysql_select_db("Database_Name") or die(mysql_error());
//your query
$data = mysql_query("SELECT * FROM comics, comicstitles WHERE comics.comTitle = comicstitles.titID ORDER BY comicstitles.titTitle ASC")
or die(mysql_error());
$temp_title="";
while($info = mysql_fetch_array( $data ))
{
$temp_title = $info['comicstitles'];
if(($temp_title == $info['comicstitles']))
{
echo "<tr>";
echo "<td>".$info[comics]."</td>";
echo "</tr>";
}
else
{
echo "<tr>"
echo "<td>".$info[comicstitles]."</td>"
echo "</tr>"
echo "<tr>";
echo "<td>".$info[comics]."</td>";
echo "</tr>";
}
}