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 6 years ago.
Improve this question
I've run into a problem with php, I have this table:
<?php
$s=(" SELECT * FROM my_tbl");
$W=mysql_query($s);
?>
<table>
<tr>
<td> <center><strong>Member </strong></center></td>
</tr><tr>
<td> <center><strong> Total Meal </strong></center></td>
</tr>
<?php while ( $r=mysql_fetch_array($W)) {$i++; ?>
<tr > <td> <?= $r["name"]; ?> </td></tr>
<tr>
<td> <?= $r["tmeal"]; ?> </td>
</tr><?php } ?>
</table>
But I'm looking for this output:
How can I improve my code so I can get this result?
$conn = mysqli_connect('server','username','password',"DB NAme") or die("error");
$queryString = "select * from TableNAme";
$queryres = mysqli_query($conn, $queryString) or die("not fire");
echo "<table>";
while($row = mysqli_fetch_array($queryres))
{
echo "<tr><td>$row[0]</td><td>$row[0]</td><td>$row[0]</td></tr>";
}
echo "</table>";
This may help you
<?php
$con = mysql_connect("localhost", "root", "mypass") or
die("Could not connect: " . mysql_error());
mysql_select_db("your_db");
$s=(" SELECT * FROM my_tbl");
$W=mysql_query($s); ?>
<table>
<tr>
<td> <center><strong>Member </strong></center></td>
<td> <center><strong> Total Meal </strong></center></td>
</tr>
<?php while ( $r = mysql_fetch_assoc($W)) { ?>
<tr > <td> <? php echo $r['name']; ?></td>
<td> <? php echo $r['tmeal']; ?> </td>
</tr><?php } ?>
</table>
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 10 months ago.
Improve this question
I want to make a recapitulation of absent data, which I display using a table in CI. The problem that occurs to me is that the data that appears in the table is not in date order.
I want to make a report like this
enter image description here
The absence data does not match based on the date data above the table
How to display the data according to the date data that I called from the database?
Here is my code:
<tbody>
<tr class="text-center">
<td>Nip</td>
<td>Nama Lengkap</td>
<?php
foreach ($tampiltgl as $data) :?>
<td>
<?php echo $data['waktu']; ?>
</td>
<?php endforeach; ?>
</thead>
<tbody>
<?php
$no=1;
foreach ($tampil as $data) :?>
<tr>
<td><?php echo $data['nip']; ?> </td>
<td>
<?php echo $data['nm_lengkap']; ?>
</td>
<?php
date_default_timezone_set("Asia/Jakarta");
$timestamp = date('m');
$opd=$this->session->userdata('opd');
$tgl=$this->db->query ("SELECT DISTINCT waktu FROM absen_pagi where opd='$opd'AND MONTH(waktu) ='$timestamp'")->result_array();
$absen = $this->db->query ("SELECT DISTINCT waktu, status from absen_pagi where nip='".$data['nip']."' AND opd='$opd' AND MONTH(waktu) ='$timestamp'")->result_array();
foreach ($absen as $key) :?>
<td><?php echo $key['status']; ?> </td>
</td>
<?php endforeach; ?>
<?php endforeach; ?>
</tbody>
</table>
I think you're looking for this:
<table>
<thead>
<tr class="text-center">
<td>Nip</td>
<td>Nama Lengkap</td>
<?php
foreach ($tampiltgl as $data) :?>
<td>
<?php echo $data['waktu']; ?>
</td>
<?php endforeach; ?>
</tr>
</thead>
<tbody>
<?php
$no=1;
foreach ($tampil as $data) :?>
<tr>
<td><?php echo $data['nip']; ?> </td>
<td>
<?php echo $data['nm_lengkap']; ?>
</td>
<?php
date_default_timezone_set("Asia/Jakarta");
$timestamp = date('m');
$opd=$this->session->userdata('opd');
$tgl=$this->db->query ("SELECT DISTINCT waktu FROM absen_pagi where opd='$opd'AND MONTH(waktu) ='$timestamp'")->result_array();
$absen = $this->db->query ("SELECT DISTINCT waktu, status from absen_pagi where nip='".$data['nip']."' AND opd='$opd' AND MONTH(waktu) ='$timestamp'")->result_array();
foreach ($tampiltgl as $tampiltgldata) {
$celldata = '';
foreach ($absen as $key) {
if ($tampiltgldata['waktu'] == $key['waktu']) {
$celldata = $key['status'];
break;
}
}
echo "<td>$celldata</td>";
} ?>
</tr>
<?php endforeach; ?>
</tbody>
</table>
When displaying the $absen data from the database, loop over the $tampiltgl array that you used to print the dates in the header.
For each date in the $tampiltgl array, check if there is an entry in the $absen array with the same date. If a match is found, print the status. If no match was found print an empty table cell.
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 2 years ago.
Improve this question
I would like to develop a soccer player comparer website with php and mysql.
I search on google for many hours but I don't find any example.
Links:
https://pesdb.net/pes2021/?compare=4522+47179
https://www.pesmaster.com/pes-2021/compare/?id=1053098,1095755
I know how create one player stats from mysql but I don't know how create the comparer.
If you're using PHP PDO it is just a simple query to fetch the information about the players.
Example:
$get_player1_id = $_GET['p1'];
$get_player2_id = $_GET['p2'];
$query = $db->prepare("SELECT p.name, p.squad_number, p.position, p.offensive_awareness, p.ball_control, p.dribbling
FROM players AS p
WHERE p.p_id = :player1_id");
$query->bindValue(':player1_id', $get_player1_id, PDO::PARAM_INT);
$query->execute();
$num_rows = $query->rowCount();
if ($num_rows > 0) {
while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
$p1_name = $row['name'];
$p1_squad_number = $row['squad_number'];
$p1_position = $row['position'];
$p1_offensive_awareness = $row['offensive_awareness'];
$p1_ball_control = $row['ball_control'];
$p1_dribbling = $row['dribbling'];
}
}
$query = $db->prepare("SELECT p.name, p.squad_number, p.position, p.offensive_awareness, p.ball_control, p.dribbling
FROM players AS p
WHERE p.p_id = :player2_id");
$query->bindValue(':player2_id', $get_player2_id, PDO::PARAM_INT);
$query->execute();
$num_rows = $query->rowCount();
if ($num_rows > 0) {
while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
$p2_name = $row['name'];
$p2_squad_number = $row['squad_number'];
$p2_position = $row['position'];
$p2_offensive_awareness = $row['offensive_awareness'];
$p2_ball_control = $row['ball_control'];
$p2_dribbling = $row['dribbling'];
}
}
You then just need to know html to display the information.
Example:
<?php
echo '<html>
<head>
<title>Compare '.$p1_name.' vs. '.$p2_name.'</title>
</head>
<body>
<table>
<tr>
<td>
<label>Player Name:</label>
</td>
<td>
<p>'.$p1_name.'</p>
</td>
<td>
<p>'.$p2_name.'</p>
</td>
</tr>
<tr>
<td>
<label>Squad Number:</label>
</td>
<td>
<p>'.$p1_squad_number.'</p>
</td>
<td>
<p>'.$p2_squad_number.'</p>
</td>
</tr>
<tr>
<td>
<label>Position:</label>
</td>
<td>
<p>'.$p1_position.'</p>
</td>
<td>
<p>'.$p2_position.'</p>
</td>
</tr>
<tr>
<td>
<label>Offensive Awareness:</label>
</td>
<td>
<p>'.$p1_offensive_awareness.'</p>
</td>
<td>
<p>'.$p2_offensive_awareness.'</p>
</td>
</tr>
<tr>
<td>
<label>Ball Control:</label>
</td>
<td>
<p>'.$p1_ball_control.'</p>
</td>
<td>
<p>'.$p2_ball_control.'</p>
</td>
</tr>
<tr>
<td>
<label>Dribbling:</label>
</td>
<td>
<p>'.$p1_dribbling.'</p>
</td>
<td>
<p>'.$p2_dribbling.'</p>
</td>
</tr>
</table>
</body>
</html>';
?>
To get the correct variables you need your URL to be like this:
www.example.com/compare?p1=1000&p2=1001
With 1000 and 1001 being the unique id assigned to the players in your database.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I m trying to run two loops the first query in retrieves the column .The second query takes the primary id of the first table and executes the query.
Final result should be like given in the image
Im not able to give the proper alignment
Below is the code
<table width="100%" border="1" cellspacing="1" cellpadding="1" >
<tr>
<td>Col1</td>
<td>col2</td>
<td>col3</td>
<td>col4/td>
</tr>
<?php
$mast = mysql_query("select * from table1 where av_master_id='".$_REQUEST['id']."'");
while($res_mas= mysql_fetch_assoc($mast))
{
?>
<tr>
<td><?php echo $res_mas['col1'];?></td>
<?php
$room= mysql_query("SELECT * FROM `table2` WHERE av_room_id='".$res_mas['av_room_id']."'");
while($res_room= mysql_fetch_assoc($room))
{
?>
<td><?php echo $res_room['col2'];?></td>
<td><?php echo $res_room['col3'];?></td>
<td><?php echo $res_room['col4'];?></td>
</td>
</tr><tr>
<?php }?>
</tr>
<?php } ?>
</table>
This should do it:
<table width="100%" border="1" cellspacing="1" cellpadding="1" >
<tr>
<td>Col1</td>
<td>col2</td>
<td>col3</td>
<td>col4/td>
</tr>
<?php
$mast = mysql_query("select * from table1 where av_master_id='".$_REQUEST['id']."'");
while($res_mas = mysql_fetch_assoc($mast)) {
$room = mysql_query("SELECT * FROM `table2` WHERE av_room_id='".$res_mas['av_room_id']."'");
$count = 0;
while($res_room= mysql_fetch_assoc($room)) {
$count += 1;
?>
<tr>
<td><?php echo $count === 1 ? $res_mas['col1'] : "";?></td>
<td><?php echo $res_room['col2'];?></td>
<td><?php echo $res_room['col3'];?></td>
<td><?php echo $res_room['col4'];?></td>
</tr>
<?php } } ?>
</table>
(untested)
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
<tbody>
<?php foreach($result as $row){ ?>
<?php foreach($result1 as $row1) {?>
<tr>
<td >
<span><?php echo $row->state; ?></span>
</td>
<td >
<span><?php echo $row->breakdown_grants; ?></span>
</td>
<td >
<span><?php echo $row1->breakdown_grants; ?></span>
</td>
</tr>
<?php } ?>
<?php } ?>
</tbody>
I need to display my coding in table format.in that first foreach contain state and breakdown_grants value.
state actual provisional
$row->state $row->breakdown_grants $row1->breakdown_grants
this is my table format.what i need to change in my foreach.in $result and $result1 i'll get different data.
Better you use for loop like
<?php for($i=0;$i<count($result);$i++) { ?>
<tr>
<td>
<span><?php echo $result[$i]->state; ?></span>
</td>
<td>
<span><?php echo $result[$i]->breakdown_grants; ?></span>
</td>
<td>
<span><?php echo $result1[$i]->breakdown_grants; ?></span>
</td>
</tr>
<?php } ?>
Make sure that $result and $result1 are of same indexes and of same lengths.
I am doing questionnaire on php, I am new to php. When I try to show the answers, it only shows the first two questions. After the two questions, answers are not shown. I have attached the source here.
Please use the following link to view the page.
http://itsupportsrilanka.com/uaquiz/quiz.php
<body>
<form action="test.php" method="POST">
<?php
$result = select("SELECT * FROM questions ");
//$row = mysql_fetch_array($result);
?>
<?php
$i=1;
while($row = mysql_fetch_array($result))
{
?>
<table width="581" height="299" border="1">
<tr>
<td>Union Assurance Questionnaire</td>
</tr>
<tr>
<td><?php echo $i.'.' .$row['questions']; ?>
<?php $i++; ?>
</td>
</tr>
<tr>
<td>
<?php $qId=$row['question_id'];
$result1=select("SELECT * FROM answers WHERE questionId='$qId' ORDER BY RAND()");
while($row1=mysql_fetch_array($result1)){
?>
<input type="radio" name="answers" value="<?php echo $row1['answers'];?>" / ><?php echo $row1['answers']; ?><br/>
<?php
} ?>
</td>
</tr>
<tr>
<td> </td>
</tr>
</table>
<?php
}
?>
</form>
</body>
Replace
$result = select("SELECT * FROM questions "); with $result = mysql_query("SELECT * FROM questions ");
and
$result1=select("SELECT * FROM answers WHERE questionId='$qId' ORDER BY RAND()"); with
$result1=mysql_query("SELECT * FROM answers WHERE questionId='$qId' ORDER BY RAND()");
and try again