I finished my studies but now I need to develop a project and I thought about creating a web app for a gym, but I'm stuck on the schedule module. I need it to get the info from a database like this:
+--------+------------+--------+----------+------+-----------+------------+
| ID_Act | HoraInicio | Dia | Duracion | Sala | DNI_Prof | Dificultad |
+--------+------------+--------+----------+------+-----------+------------+
| 1 | 09:00:00 | LUNES | 45 | 1 | 12345678A | 2 |
| 1 | 09:00:00 | MARTES | 45 | 1 | 12345678A | 3 |
| 1 | 10:30:00 | LUNES | 45 | 1 | 12345678A | 1 |
+--------+------------+--------+----------+------+-----------+------------+
ID_Act: Activity ID
HoraInicio: Start time
Dia: Day
Duración: Duration
Sala: Room
DNI_Prof: Teacher ID
Dificultad: Level
I've been trying to create the whole schedule using a for loop so I don't have to copy&paste 50 rows. I can create the whole schedule with the loop but I can not print the values that I need to have in the proper cell.
This is the code of what I've been trying:
<?php session_start(); ?>
<?php
include("connbd.php");
$consulta="SELECT actividades.nombre AS Actividad, ID_Act, HoraInicio, Dia, Duracion, Sala, Dificultad FROM horarios
JOIN actividades WHERE actividades.id LIKE ID_Act;";
$resultado=mysqli_query($conn,$consulta);
$hora = array("09:00","09:15","09:30","09:45","10:00","10:15","10:30","10:45","11:00","11:15","11:30",
"11:45","12:00","12:15","12:30","12:45","13:00","13:15","13:30","13:45","14:00","14:15","14:30","14:45",
"15:00","15:15","15:30","15:45","16:00","16:15","16:30","16:45","17:00","17:15","17:30","17:45","18:00",
"18:15","18:30","18:45","19:00","19:15","19:30","19:45","20:00","20:15","20:30","20:45","21:00");
?>
<div id=contenidoHorarios class="contenidoHorarios">
<div id=contenidoHorariosTabla class="contenidoHorariosTabla">
<div id=contenidoHorariosTablaHoras class="contenidoHorariosTablaHoras">
<table border="1px" id="contenidoHorariosTablaTabla" class="contenidoHorariosTablaTabla">
<tr>
<th width="5%"></th>
<th width="13.57%">Lunes</th>
<th width="13.57%">Martes</th>
<th width="13.57%">Miércoles</th>
<th width="13.57%">Jueves</th>
<th width="13.57%">Viernes</th>
<th width="13.57%">Sábado</th>
<th width="13.57%">Domingo</th>
</tr>
<?php
foreach ($hora as $horatupla) {
?>
<tr>
<th><?php echo $horatupla; ?></th>
<td id="<?php
while ($row=$resultado->fetch_assoc())
{
$id = $row['ID_Act'];
$horainicio = substr($row['HoraInicio'],0,-3);
$dia = $row['Dia'];
$duracion = $row['Duracion'];
$sala = $row['Sala'];
$dificultad = $row['Dificultad'];
$actividad = $row['Actividad'];
if($dia=='LUNES'){echo $dia . $horatupla;} ?>" rowspan="<?php if($duracion=='15' || $duracion==''){echo '1';} if($duracion=='30'){echo '2';} if($duracion=='45'){echo '3';} ?>"
<?php
if ($horatupla==$horainicio)
{
echo $actividad;
}
}
?>>
</td>
</tr>
<?php } ?>
</table>
</div>
</div>
</div>
I hope you understand what I'm saying, but to help you, I give you a example of what I do want to do (no spam).
http://www.go-fit.es/Horarios/Index
Related
I am trying to build a web page (using css) that shows me values for today and tomorrow. I can successfully get the values for today but cannot see / get the values for tomorrow which are on the next row. I require the next row column Fajr Begins on my webpage (php code).
Mysql query:
select * from prayers where Date IN (CURDATE(), DATE_ADD(CURDATE(), INTERVAL 1 DAY)) LIMIT 2;
output:
| Date | Day | Fajr Begins | Fajr Jamaat | Sunrise | Zohr Begins | Zohr Jamaat | Asr Begins | Asr Jamaat | Magrib Begins | Magrib Jamaat | Isha Begins | Isha Jamaat | Jumah 1 | Jumah 2 | Day of week |
+------------+------+-------------+-------------+---------+-------------+-------------+------------+------------+---------------+---------------+-------------+-------------+---------+---------+-------------+
| 2021-10-15 | Fri | 05:33 | 06:00 | 07:23 | 12:50 | * | 15:33 | 16:15 | 18:11 | 18:16 | 19:59 | | 13:20 | 14:15 |
| 2021-10-16 | Sat | 05:34 | 06:15 | 07:24 | 12:50 | 13:30 | 15:32 | 16:00 | 18:09 | 18:14 | 19:57 | | 13:20 | 14:15 |
+------------+------+-------------+-------------+---------+-------------+-------------+------------+------------+---------------+---------------+------------+
All the column names are the same so I cannot alias them (which wouldve been easy)..
Here is my PHP Script (I've only taken a small snippet from the first entry of the html table):
<?php
include "dbConn.php"; // Using database connection file here
$records = mysqli_query($db,"select * from prayers where Date IN (CURDATE(),
DATE_ADD(CURDATE(), INTERVAL 1 DAY)) LIMIT 2;" ); // fetch data from database
while($data = mysqli_fetch_array($records))
{
?>
<div class="u-table u-table-responsive u-table-1">
<table class="u-table-entity">
<colgroup>
<col width="100%">
</colgroup>
<tbody class="u-table-body">
<tr style="height: 118px;">
<td class="u-align-center u-table-cell u-table-cell-1"><?php echo $data['Fajr
Begins']; ?></td>
</tr>
</tbody>
</table>
</div>
<div class="u-table u-table-responsive u-table-2">
<table class="u-table-entity">
<colgroup>
<col width="100%">
</colgroup>
<tbody class="u-table-body">
<tr style="height: 118px;">
<td class="u-align-center u-table-cell u-text-palette-3-base u-table-cell-2"><?php
echo $data['Fajr Jamaat']; ?></td>
</tr>
</tbody>
</table>
</div>
<div class="u-table u-table-responsive u-table-3">
<table class="u-table-entity">
<colgroup>
<col width="100%">
</colgroup>
<tbody class="u-table-body">
<tr style="height: 72px;">
**<td class="u-align-center u-table-cell u-text-palette-2-base u-table-cell-3">Tommorrow Data</td>**
</tr>
</tbody>
</table>
</div>
<?php
}
?>
<?php mysqli_close($db); // Close connection ?>
Webpage attached.
I've exhausted all my options searching but cannot find what the solution.
Please help pro's!
Your query is returning the correct data and is limited to two rows. When you come to create the HTML tables your while loop is only reading one row at a time, so you never see tomorrow's data.
However, there's no guarantee which order the data is returned in, so you need to add an ORDER BY Date ASC clause.
Since you're only returning two rows you don't need a while statement. You just need two successive fetches, something like this:
<?php
include "dbConn.php"; // Using database connection file here
// Query updated to include an ORDER BY clause
$records = mysqli_query($db,"select * from prayers where Date IN (CURDATE(),
DATE_ADD(CURDATE(), INTERVAL 1 DAY)) ORDER BY Date ASC LIMIT 2;" ); // fetch data from database
// read first row with today's data
$todaysData = mysqli_fetch_array($records);
// Create table for today here
// Now read second row, with tomorrow's data.
$tomorrowData = mysqli_fetch_array($records);
// Create table for tomorrow here.
mysqli_close($db); // not strictly required since PHP will do this anyway
I have a table name "scores"
+----+-------+-------+-------------------+
| id | score | level | username |
+----+-------+-------+-------------------+
| 1 | 65 | one | dustyrydberg |
| 2 | 56 | one | dustyrydberg |
| 3 | 34 | one | pointedshrill |
| 4 | 50 | one | witchrage |
| 5 | 41 | one | spacetimeken |
| 6 | 44 | one | harperhetton |
| 7 | 65 | one | witchrage |
| 8 | 70 | one | paladino |
| 9 | 50 | one | chimpanzer |
| 10 | 22 | one | yahooligan |
| 11 | 672 | one | blueCrow |
| 12 | 120 | one | sleepyDolphin |
| 13 | 43 | one | gothicNightingale |
| 14 | 22 | one | phonyPuppy |
| 15 | 23 | one | phonyPuppy |
| 16 | 24 | one | phonyPuppy |
| 17 | 31 | one | darlingFairy |
| 18 | 36 | one | starkVoid |
+----+-------+-------+-------------------+
I am trying to list the top 10 highscores without duplication of usernames. I am doing this using php and mysql. I have a functions.php file which includes the following function:
function find_all_scores() {
global $connection;
$query = "SELECT MIN(score), username ";
$query .= "FROM scores ";
$query .= "GROUP BY username ";
$query .= "ORDER BY MIN(score) ASC";
$score_set = mysqli_query($connection, $query);
confirm_query($score_set);
return $score_set;
}
Which is called on in the all_highscores.php file
<?php require_once("../includes/session.php"); ?>
<?php require_once("../includes/db_connection.php"); ?>
<?php require_once("../includes/functions.php"); ?>
<?php
$score_set = find_all_scores();
$ranking = 1;
?>
<?php $layout_context = "score"; ?>
<?php include("../includes/layouts/header.php"); ?>
<div id="main">
<div id="navigation">
</div>
<div id="page">
<?php echo message(); ?>
<h2>Your Highscores</h2>
<p>Here are <?php echo htmlentities($_SESSION["username"]); ?>'s best scores.</p>
<table>
<tr>
<th style="text-align: left; width: 200px;">Position</th>
<th style="text-align: left; width: 200px;">Username</th>
<th style="text-align: left; width: 200px;">Level</th>
<th colspan="2" style="text-align: left;">Score</th>
</tr>
<?php while($score = mysqli_fetch_assoc($score_set)) { ?>
<tr>
<td><?php echo $ranking; ?></td>
<td><?php echo htmlentities($score["username"]); ?></td>
<td><?php echo htmlentities($score["level"]); ?></td>
<td><?php echo htmlentities($score["score"]); ?></td>
<?php
$ranking = $ranking + 1; /* INCREMENT RANKING BY 1 */
?>
</tr>
<?php } ?>
</table>
</div>
</div>
<?php
// 4. Release returned data
//mysqli_free_result($result);
?>
<?php include("../includes/layouts/footer.php"); ?>
However I keep ending up with either a query failure or nothing displays in the HTML browser. Please help!
I am trying to display a table by school year using PHP. I it seems not working very well because the school year displays redundantly.
How to simply display it like this?
No | SY | Student ID | Student Name | Gender | Section Code | Subject
-----------------------------------------------------------------------------
2015-2016 SEMESTER 1
-----------------------------------------------------------------------------
1 | 2 | 0011941 | Cocos, Scrappy S. | Male | IT15B | IT15
-----------------------------------------------------------------------------
1 | 2 | 1212211 | asasas, sasas a. | Male | IT15B | IT15
-----------------------------------------------------------------------------
2015-2016 SEMESTER 2
-----------------------------------------------------------------------------
1 | 2 | 0011941 | Cocos, Scrappy S. | Male | IT15B | IT15
-----------------------------------------------------------------------------
1 | 2 | aSAsaSA | dsdsadsad.ssasasas | Male | IT15B | IT15
-----------------------------------------------------------------------------
2016-2017 SEMESTER 1
-----------------------------------------------------------------------------
1 | 2 | 0011941 | Doo, Scooby D. | Male | IT15B | IT15
-----------------------------------------------------------------------------
2016-2017 SEMESTER 2
-----------------------------------------------------------------------------
1 | 2 | 0011941 | Doo, Scooby D. | Male | IT15B | IT15
here's my code:
<tr>
<th>No</th>
<th>SY</th>
<th>Student ID</th>
<th>Student Name</th>
<th>Gender</th>
<th>Section Code</th>
<th>Subject</th>
<th colspan="2">Update</th>
</tr>
$sql= "SELECT sts.stud_id, sts.fname, sts.lname, sts.mi, sts.gender, sub.section_code, sub.subject_name, ets.sem, ets.enroll_num, ets.sy
FROM students sts
JOIN enrollments ets ON(sts.stud_id = ets.stud_id)
JOIN subjects sub ON (sub.section_code = ets.section_code)
GROUP BY sts.stud_id, sub.section_code ORDER BY ets.stud_id ASC";
$sql_sel=mysql_query($sql);
$num_rows = mysql_num_rows($sql_sel);
if($num_rows==0)
{
echo "No results found. Please try again";
}
$i=0;
while($row=mysql_fetch_array($sql_sel)) //for the first query
{
$i++;
$color=($i%2==0)?"lightblue":"white";
?>
<th colspan="8"><?php echo $row['sy'];?></th> //this thing here
<tr bgcolor="<?php echo $color?>">
<td><?php echo $i;?></td>
<td><?php echo $row['sem'];?></td>
<td><?php echo $row['stud_id'];?></td>
<td width="200"><?php echo $row['lname'].", ".$row['fname']." ".$row['mi'].".";?></td>
<td><?php echo $row['gender'];?></td>
<td><?php echo $row['section_code'];?></td>
<td><?php echo $row['subject_name'];?></td>
<td align="center" width="82"><img src="picture/update.png" /></td>
<!----<td align="center"><img src="picture/delete.png" /></td>-------->
</tr>
<?php
}
?>
First you need to order by year and semester in your query:
$sql= "SELECT sts.stud_id, sts.fname, sts.lname, sts.mi, sts.gender, sub.section_code, sub.subject_name, ets.sem, ets.enroll_num, ets.sy
FROM students sts
JOIN enrollments ets ON(sts.stud_id = ets.stud_id)
JOIN subjects sub ON (sub.section_code = ets.section_code)
GROUP BY sts.stud_id, sub.section_code ORDER BY ets.sy ASC, ets.sem ASC, ets.stud_id ASC";
Then you only write the year row when you detect a change of year:
$i=0;
$yr=null;
while($row=mysql_fetch_array($sql_sel)) //for the first query
{
if ($yr != ($row['sy'] . ' SEMESTER ' . $row['sem'])) {
$yr = $row['sy'] . ' SEMESTER ' . $row['sem'];
print ('<th colspan="8">' . $yr . '</th>');
}
$i++;
$color=($i%2==0)?"lightblue":"white";
?>
<tr bgcolor="<?php echo $color?>">
<td><?php echo $i;?></td>
<td><?php echo $row['sem'];?></td>
<td><?php echo $row['stud_id'];?></td>
<td width="200"><?php echo $row['lname'].", ".$row['fname']." ".$row['mi'].".";?></td>
<td><?php echo $row['gender'];?></td>
<td><?php echo $row['section_code'];?></td>
<td><?php echo $row['subject_name'];?></td>
<td align="center" width="82"><img src="picture/update.png" /></td>
<!----<td align="center"><img src="picture/delete.png" /></td>-------->
</tr>
<?php
}
There is a text field and a table. If we put a value in that text field the corresponding name needs to be displayed on the table from data base:
<form method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
<center><table>
<tr><td>no</td><td><input type="text" name="no" autofocus></td></tr>
</table></center>
<br>
<br>
<center>
<table cellpadding="0" cellspacing="0" width="60%" border='1' bgcolor="#999999">
<thead>
<tr>
<th> Element_Number</th>
</tr>
</thead>
<?php
if(isset($_POST['no']))
{
$c=mysql_connect("localhost","root","");
mysql_select_db("test");
if(!$c)
{
echo "db prob".mysql_error();
}
$no=$_POST['no'];
$qry=mysql_query("select name from opt where no='$no'");
if(!$qry)
{
echo "ret".mysql_error();
}
if(mysql_num_rows($qry)!=0)
{
$row=mysql_fetch_array($qry);
$name=$row['name'];
}
else
{
echo "query Invalid";
}
echo "<td>" .$name."</td></tr>" ;
}
?>
when I tried this code output like this-->
no--001
|element no |
| aaa |
no--002
|element no |
| bbb |
what I want to do to get an output like this--->
no--001
|element no |
| aaa |
no--002
|element no |
| aaa |
| bbb |
no--003
|element no |
| aaa |
| bbb |
| ccc |
I have problems when numbering the tables using CodeIgniter framework with libraary pagination. below are the table..
+------------------------------------------+
| num| NIP | Name | Category | Type |
+------------------------------------------+
| 1 | 12345 | udin | A | A1 |
+------------------------------------------+
| | | | B | B1 |
+------------------------------------------+
| | | | C | C1 |
+------------------------------------------+
| 2 | 54321 | JHON | B | B2 |
+------------------------------------------+
| | | | C | C1 |
+------------------------------------------+
the issue is on the next page in the table below..
+------------------------------------------+
| num| NIP | Name | Category | Type |
+------------------------------------------+
| 1 | 54321 | JHON | F | F2 |
+------------------------------------------+
| | | | G | G3 |
+------------------------------------------+
| | | | G | G4 |
+------------------------------------------+
| | | | I | I3 |
+------------------------------------------+
| | | | J | J1 |
+------------------------------------------+
I want the next page numbering sequential numbering starting from the end of the previous value. Supposedly in figure 2 numbering number "2" instead of "1".
code in the controller:
$this->load->library('pagination');
$data['judul'] = 'Report Data Attachment';
$start_row = $this->uri->segment(3);
$per_page = 10;
if (trim($this->uri->segment(3)) == '')
{
$start_row = '0';
}
$config['base_url'] = base_url().'report/index/';
$config['total_rows'] = $this->lampiran_m->lampiran_karyawan_semua_page_conter()->num_rows();
//$config['uri_segment'] = '3';
$config['per_page'] = $per_page;
$config['full_tag_open'] = '<p class="page">';
$config['full_tag_close'] = '</p>';
$this->pagination->initialize($config);
$data['pagination'] = $this->pagination->create_links();
$data['lampiran'] = $this->lampiran_m->lampiran_karyawan_semua_page($start_row,','.$per_page);
$data['no'] = '';
$data['last'] = '';
$this->template->display('tabel_report',$data);
and code in my Model :
public function lampiran_karyawan_semua_page($offset='',$limit='')
{
$qry = "select distinct lampiran.id_category,name_category,tipe,lampiran.nip from lampiran
left join employee on (lampiran.nip = employee.nip)
left join category on (lampiran.id_category=category.id_category) where lampiran.id_category = category.id_category and lampiran.nip=employee.nip order by lampiran.nip desc limit $offset $limit";
return $this->db->query($qry);
}
and this code in view :
<table border="1" width="100%" cellpadding="0" cellspacing="0" id="product-table" >
<tr>
<th class="table-header-repeat line-left minwidth-1"> No</th>
<th class="table-header-repeat line-left minwidth-1"> NIP</th>
<th class="table-header-repeat line-left minwidth-1"> Name</th>
<th class="table-header-repeat line-left minwidth-1"> Category Attachment</th>
<th class="table-header-repeat line-left minwidth-1">Type Attachment </th>
<th class="table-header-repeat line-left minwidth-1">Page </th>
</tr>
<?php
foreach($lampiran->result_array() as $k) {
$now=$k['nip'];
if($last!=$now ) {
$no++;
echo "<tr><td>$no</td><td>$k[nip]</td><td>".$this->employee_m->get($k['nip'])->nama."</td><td>$k[name_category]</td><td>$k[tipe]</td><td>"; ?>
<?php foreach($this->lampiran_m->conter_tabel_semua($k['id_category'],$k['tipe'],$k['nip'])->result() as $row) :?>
<?php echo $row->nilai;?>
<?php endforeach;
echo "</td></tr>";
}else{
echo "<tr><td> </td><td> </td><td> </td><td>$k[name_category]</td><td>$k[tipe]</td><td>"; ?>
<?php foreach($this->lampiran_m->conter_tabel_semua($k['id_category'],$k['tipe'],$k['nip'])->result() as $row) :?>
<?php echo $row->nilai;?>
<?php endforeach;
echo "</td></tr>";
}
$last = $k['nip'];
}
?>
<tr><td colspan="5" style="text-align: center;"><b>Jumlah Total</b></td><td>
<?php foreach($this->lampiran_m->jumlah_semua_lampiran()->result() as $row) :?>
<?php echo "<b>$row->jumlah</b>";?>
<?php endforeach; ?>
</td></tr>
</table>
I hope someone can help me on this issue .. thanks
before foreach you have to add
$no = $this->uri->segment(3)+1;
No
NIP
Name
Category Attachment
Type Attachment
Page
</tr>
<?php
//before foreach you have to add
$no = $this->uri->segment(3)+1;
foreach($lampiran->result_array() as $k) {
$now=$k['nip'];
if($last!=$now ) {
$no++;
echo "<tr><td>$no</td><td>$k[nip]</td><td>".$this->employee_m->get($k['nip'])->nama."</td><td>$k[name_category]</td><td>$k[tipe]</td><td>"; ?>
<?php foreach($this->lampiran_m->conter_tabel_semua($k['id_category'],$k['tipe'],$k['nip'])->result() as $row) :?>
<?php echo $row->nilai;?>
<?php endforeach;
echo "</td></tr>";
}else{
echo "<tr><td> </td><td> </td><td> </td><td>$k[name_category]</td><td>$k[tipe]</td><td>"; ?>
<?php foreach($this->lampiran_m->conter_tabel_semua($k['id_category'],$k['tipe'],$k['nip'])->result() as $row) :?>
<?php echo $row->nilai;?>
<?php endforeach;
echo "</td></tr>";
}
$last = $k['nip'];
}
?>
<tr><td colspan="5" style="text-align: center;"><b>Jumlah Total</b></td><td>
<?php foreach($this->lampiran_m->jumlah_semua_lampiran()->result() as $row) :?>
<?php echo "<b>$row->jumlah</b>";?>
<?php endforeach; ?>
</td></tr>
</table>
please put below line before foreach statement
$currentffset = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$slno_start = (($currentffset / $per_page) * per_page) + 1;
after that use $slno_start as serial number for each item inside foreach at last line of foreach just increment it
$slno_start++;
Minor improvement from above answers.Thanks both of u guys
$count =$this->uri->segment(3)+1;
foreach($records as $rec){echo $count; $count++;}