guys i have the following code, but when i execute it on my site, the site give me internal server error 500
$Data = $con->prepare("SELECT Example1,Example2,Example3,Example4 FROM SITES WHERE Email=:Email");
$Data->execute(array(
':Email' => $Email,
));
if ($Data->rowCount() > 0) {
$Rows = $Data->rowCount();
$CL = 1;
$Result = $Data->fetch(PDO::FETCH_ASSOC);
while ($CL <= $Rows) {
$Example1 = $Result['Example1'];
$Example2 = $Result['Example2'];
$Example3 = $Result['Example3'];
$Example4 = $Result['Example4'];
$CL = $CL++;
echo
'<tr class="tr">
<td class="td"><?=$Example1?></td>
<td class="td"><?=$Example2?></td>
<td class="td"><?=$Example3?></td>
<td class="td"><?=$Example4?></td>
<td class="td"></td>
</tr>';
}
}
I want that for every row where email=:email php will print an html row of an existing table.Thanks in advice, have a good day!
Try this {Let's us know if it works for you}
$Data = $con->prepare("SELECT Example1,Example2,Example3,Example4 FROM SITES WHERE Email=:Email");
$Data->execute(array(
':Email' => $Email,
));
if ($Data->rowCount() > 0) {
$Rows = $Data->rowCount();
$CL = 1;
$Result = $Data->fetch(PDO::FETCH_ASSOC);
while ($CL <= $Rows) {
$Example1 = $Result['Example1'];
$Example2 = $Result['Example2'];
$Example3 = $Result['Example3'];
$Example4 = $Result['Example4'];
//$CL = $CL++; This is bad;
$CL++;
echo
'<tr class="tr">'; <?
<td class="td"><?php echo $Example1 ;?></td>
<td class="td"><?php echo $Example2 ;?></td>
<td class="td"><?php echo $Example3 ;?></td>
<td class="td"><?php echo $Example4 ;?></td>
<td class="td"></td>
<?php
echo '</tr>';
}
}
Related
Excuse me,
I have source for get value from table
foreach ($hard->result() as $row) {
$ha[] = $row->bek;
}
(bek is name of column and $hard isi name of variable return query)
then I wanna write the result with lopping too.
<?php
'<tr>';
$d = 0;
$g = 0;
$s = 0;
foreach ($mon->result() as $row) {
?>
<td class="tg-yw4l"><?php echo $row->sNama;?></td>
<td class="tg-yw4l"><?php echo $norm[$d++];?></td>
<td class="tg-yw4l"><?php echo $ha[$g++];?></td>
<td class="tg-yw4l"><?php echo $urg[$s++];?></td>
<td class="tg-yw4l"></td>
</tr>
<?php
}
?>
my question is : how to give '0', when the result from db doesn't give a value (null)
Can someone help me please,,
Thanks before
You can try this
<?php
'<tr>';
$d = 0;
$g = 0;
$s = 0;
foreach ($mon->result() as $row) {
?>
<td class="tg-yw4l"><?php isset($row->sNama) ? echo $row->sNama : echo '0'; ?></td>
<td class="tg-yw4l"><?php isset($norm[$d++]) ? echo $norm[$d++] : echo '0'; ?></td>
<td class="tg-yw4l"><?php isset($ha[$g++]) ? echo $ha[$g++] : echo '0'; ?></td>
<td class="tg-yw4l"><?php isset($urg[$s++]) ? echo $urg[$s++]] : echo '0'; ?></td>
<td class="tg-yw4l"></td>
</tr>
<?php
}
?>
<?php
$res = $mon->result();
if($res && count($res)>0){
$d = 0;
$g = 0;
$s = 0;
foreach ($res as $row) { ?>
<tr>
<td class="tg-yw4l"><?php echo $row->sNama;?></td>
<td class="tg-yw4l"><?php echo $norm[$d++];?></td>
<td class="tg-yw4l"><?php echo $ha[$g++];?></td>
<td class="tg-yw4l"><?php echo $urg[$s++];?></td>
<td class="tg-yw4l"></td>
</tr>
<?php }
}
?>
thanks for all your attention to answer my case,
my problem is how to manipulate value from the table even when the value is empty
after I tried all way, I knew my case can't be fixed if I don't change my query because when I tried to loop with index 0, the result isnot still give '0'
foreach ($hard->result() as $row) {
$ha[0] = $row->bek;
}
<td class="tg-yw4l"><?php echo $ha[0];?></td>
because of that I knew, I should change my query in order if the result is empty it must give value '0'
My question is:
If you look at where it would display "
<td>1ST<?php echo $first ?></td>
"
How do I ensure that if the row associate to variable '$first' or all the others if they are empty nothing shows. Also that the '1st' doesn't show?
Have tried various things I am stumped on this!
<h2><?php echo $show_title ?></h2>
<h4>Show Date: <span class="glyphicon glyphicon-time"> </span><?php echo $show_date ?></h4>
<hr>
</a>
<hr>
<?php
// SO UPDATE THE QUERY TO ONLY PULL THAT SHOW'S DOGS
$query = "SELECT * FROM result
WHERE first IS NOT NULL";
$result = mysqli_query($connection, $query) or trigger_error
("Query Failed! SQL: $query - Error: ". mysqli_error
($connection), E_USER_ERROR);
if ($result) {
while ($row = mysqli_fetch_assoc($result)) {
$dog_name = $row['dog_name'];
$placement = $row['placement'];
$class_name = $row['class_name'];
$entries = $row['entries'];
$absentee = $row['absentee'];
$entries = $row['entries'];
$first = $row['first'];
$second = $row['second'];
$third = $row['third'];
$RES = $row['RES'];
$VHC = $row['VHC'];
$DCC = $row['DCC'];
$RDCC = $row['RDCC'];
$BCC = $row['BCC'];
$RBCC = $row['RBCC'];
$BOB = $row['BOB'];
$BP = $row['BP'];
$BJ = $row['BJ'];
?>
<table class="table" border="0"></div>
<tr>
<td><strong><?php echo $class_name ?></strong> - <h6>Entries: <?php echo $entries ?> Absentees: <?php echo $absentee ?></h6></td>
<td></td>
</tr>
<tr>
<td>DCC</td>
<td><?php echo $DCC ?></td>
</tr>
<tr>
<td>RDCC</td>
<td><?php echo $RDCC ?></td>
</tr>
<tr>
<td>BCC</td>
<td><?php echo $BCC ?></td>
</tr>
<tr>
<td>RBCC</td>
<td><?php echo $RBCC ?></td>
</tr>
<tr>
<td>BOB</td>
<td><?php echo $BOB ?></td>
</tr>
<tr>
<td>BP</td>
<td><?php echo $BP ?></td>
</tr>
<tr>
<td>BJ</td>
<td><?php echo $BJ ?></td>
</tr>
<tr>
<td>1ST</td>
<td><?php echo $first ?></td>
</tr>
<tr>
<td>2ND</td>
<td><?php echo $second ?></td>
</tr>
<tr>
<td>3RD</td>
<td><?php echo $third ?></td>
</tr>
<tr>
<td>RES</td>
<td><?php echo $RES ?></td>
</tr>
<tr>
<td>VHC</td>
<td><?php echo $VHC ?></td>
</tr>
</table>
You're doing well, just apply a filtering function to each row you recieve:
// SO UPDATE THE QUERY TO ONLY PULL THAT SHOW'S DOGS
$query = "SELECT * FROM result
WHERE first IS NOT NULL";
$result = mysqli_query($connection, $query);
if (!$result) {
trigger_error("Query Failed! SQL: $query - Error: ". mysqli_error($connection), E_USER_ERROR);
} else {
// Fetch results into array
$data = mysqli_fetch_all($result, MYSQLI_ASSOC);
// If results array is not empty
if ($data) {
echo '<table class="table" border="0"></div>
<tr>
<td>
<strong><?php echo $class_name ?></strong> - <h6>Entries: <?php echo $entries ?> Absentees: <?php echo $absentee ?></h6>
</td>
<td></td>
</tr>';
// Now let's walk through every record
array_walk($data, function($dogRecord) {
// Here we apply array_filter to each dog record, so that empty values (i.e. those evaluating to false) are filtered out
$dogRecord = array_filter($dogRecord);
// Now loop throw $dogRecord to build table
$collation = [
'DCC' => 'DCC',
'RDCC' => 'RDCC',
'BCC' => 'BCC',
'RBCC' => 'RBCC',
'BOB' => 'BOB',
'BP' => 'BOB',
'BJ' => 'BOB',
'1ST' => 'first',
'2ND' => 'second',
'3RD' => 'third',
'RES' => 'RES',
'VHC' => 'RES'
];
foreach ($dogRecord as $property => $value) {
echo '<tr>
<td>'.$collation[$property].'</td>
<td>'.$value.'</td>
</tr>';
}
});
echo '</table>';
}
}
Note that instead of simple foreach loop I'm using array_walk function. This is because since you extract variables for each record, you want undeclared (i.e. unoccupied) varables every time.
What about this:
if(mysqli_num_rows($result) > 0){
while($row = mysqli_fetch_assoc($result)){
// Show the table-row
}
}
The following code will iterate through each row in the result (while loop) and each key => value within each row (foreach loop); it will then check if a value is not null or the key is not equal to 'first' (if statement) and echo the results in the table element. I'm not sure I fully understood your question but I hope this helps in some small way.
<table>
<?php
if($result){
while($row = mysqli_fetch_assoc($result))
foreach($row as $key => $value){
if($value != null && $key != 'first'){
echo '<tr>';
echo '<td>' . $key . '</td>';
echo '<td>' . $value . '</td>';
echo '</tr>';
}
}
}
?>
</table>
user_reservation.php
<thead>
<tr>
<th scope="col">Number of Guest</th>
<th scope="col">Type of Service</th>
<th scope="col">Date</th>
<th scope="col">Time</th>
<th scope="col">Status</th>
<th scope="col">Edit</th>
</tr>
</thead>
<tbody>
<?php
include 'include/db_config.php';
$result = $dbs->prepare("SELECT * FROM service_info WHERE id = :id");
$result->bindParam(':id', $_SESSION['id']);
$result->execute();
for($i=0; $row = $result->fetch(); $i++){
?>
<tr class="record">
<td><?php echo $row['no_guest']; ?></td>
<td><?php echo $row['type_service']; ?></td>
<td><?php echo $row['datepicker']; ?></td>
<td><?php echo $row['t_time']; ?></td>
<td><?php echo $service['status']; ?></td>
<td> edit </td>
</tr>
<?php
}
?>
</tbody>
</table>
<b>STATUS</b><br>
<?php
include 'include/db_config.php';
$result = $dbs->prepare("SELECT * FROM service_info WHERE id = :id");
$result->bindParam(':id', $_SESSION['id']);
$result->execute();
for($i=0; $row = $result->fetch(); $i++){
?>
<!--<td><?php //echo $row['datepicker']; ?></td>-->
<?php
$today = date("Y-m-d H:i:s");
$startdate = $row['datepicker'];
$offset = strtotime("+2 day");
$enddate = date($startdate, $offset);
$today_date = new DateTime($today);
$expiry_date = new DateTime($enddate);
$status = ($expiry_date < $today_date) ? 'Expired' : 'Active' ;
$result = $dbs->prepare("UPDATE Customers SET status = :status WHERE id = :id");
$result->bindParam(':id', $_SESSION['id']);
$result->bindParam(':status', $status);
$result->execute();
?>
<?php
}
?>
This is my whole code on user_reservation. All i wanted on my admin_reservation was to fetch whats inside of my status database . but as you can see i cant still insert the status data in my database
Add a column 'status' in your table 'service_info' using phpMyAdmin for example,
then in your time verification :
include 'include/db_config.php';
$result = $dbs->prepare("SELECT * FROM service_info WHERE id = :id");
$result->bindParam(':id', $_SESSION['id']);
$result->execute();
for($i=0; $row = $result->fetch(); $i++){
?>
<?php
$today = date("Y-m-d H:i:s");
$startdate = $row['datepicker'];
$offset = strtotime("+2 day");
$enddate = date($startdate, $offset);
$today_date = new DateTime($today);
$expiry_date = new DateTime($enddate);
$status = ($expiry_date < $today_date) ? 'Expired' : 'Active' ;
$result = $dbs->prepare("UPDATE Customers SET status = :status WHERE id = :id");
$result->execute(array(':status'=>$status, ':id'=>$_SESSION['id']));
then in your table, just output the status column :
<tr class="record">
<td><?php echo $customers[$key]['firstname'];?></td>
<td><?php echo $service['no_guest']; ?></td>
<td><?php echo $service['type_service']; ?></td>
<td><?php echo $service['datepicker']; ?></td>
<td><?php echo $service['t_time']; ?></td>
<td><?php echo $service['status']; ?></td>
I have a wordpress loop retriving a table like this:
I want to check if the name repeats it self and if so do a sum of partial values to show the total.
On my screenshot the 1st and 3rd rows have the same "nome" so the global value should be 85, can any one tellme how to do this ?
my php :
<?php while( have_rows('wallet_repeater') ): the_row();
echo '<div class="promotoras_item_wallet"> ';
echo '<div class="promnames_wallet"> ';
// vars
$adicionados = get_sub_field('wallet_promotora');
foreach($adicionados as $post) :
$nome = simple_fields_values("pname1");
$im = simple_fields_values("ftotop");
$cp=$adicionados ;
$imatop = $im;
$data=get_sub_field('wallet_data');
$evento=get_sub_field('wallet_evento');
$obs=get_sub_field("wallet_obs");
$numeros_horas = get_sub_field("Wallet_n_horas");
$valor_horas = get_sub_field("wallet_valorh");
$evento = get_sub_field("wallet_evento");
$horarios = get_sub_field("wallet_horario");
$total_parcial = $valor_horas * $numeros_horas."€";
$ii = wp_get_attachment_image($imatop[0]);
?>
<table id="wallet_table1" width="900px" border="0" cellspacing="2" cellpadding="0">
<tbody>
<tr>
<tr onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';">
<td class="wallet_data_img" width="5"><div class="w_promotora_images"><?php echo wp_get_attachment_image($imatop[0]); ?></td>
<td class="wallet_data_data" width="20"><?php echo the_sub_field('wallet_data'); ?> </td>
<td class="wallet_data_nome" width="200"><?php echo $nome[0];$nomes[]=$nome[0];?></td>
<td class="wallet_data_evento" width="10"> <?php echo the_sub_field("wallet_evento"); ?></td>
<td class="wallet_data_horarios" width="10"><?php echo the_sub_field("wallet_horario"); ?></td>
<td class="wallet_data_obs" width="10"><?php echo the_sub_field("wallet_obs"); ?></td>
<td class="wallet_data_horas" width="10"><?php echo the_sub_field("Wallet_n_horas")."h"; ?></td>
<td class="wallet_data_valorh" width="5"><?php echo the_sub_field("wallet_valorh")."€"; ?></td>
<td class="wallet_data_props" width="5"><?php echo the_sub_field("wallet_props"); ?></td>
<td class="wallet_data_total" width="5">Parcial: <?php echo $total_parcial; ?> global:
</td> </tr></tbody></table>
<?php
Stuff the query data into an associative array and after that output it.
You can do it like that:
$qry = new WP_Query('post_type' => 'your_post_type', 'posts_per_page' => -1)
$arr = array();
while($qry->have_posts()) {
$qry->the_post()
$nam = //Get the name data;
$val = //Get the «global» data;
if($qry[$nam]) {
$qry[$nam]['global'] += $val;
}
else {
$qry[$nam] = array(
'foto' => //Photo data of the current post,
'name' => //Photo data of the current post,
//and so on
'global' => $val,
);
}
}
foreach($qry as $key => $data) {
//Output your table here
}
I have this code:
<?php
if( isset($_POST['groups'])){
$groups = $_POST['groups'];
$subject = $_POST['subject'];
$sql="SELECT
a.groupcode, a.groupstudents, a.studentid,
b.groupcode, b.coursename, b.studentid, b.date, b.class1, b.attend, b.attendno
FROM table_1 a, table_2 b
WHERE b.groupcode = '$groups' AND b.coursename = '$subject' AND
(a.studentid = b.studentid AND a.groupcode = b.groupcode)";
$result=mysqli_query($GLOBALS["___mysqli_ston"], $sql); ?>
<table width="100%" border="1" cellspacing="0" cellpadding="3" >
<tr>
<td align="center"><strong><font size="2">Students</font></strong></td>
<td align="center"><strong><font size="2">Date</font></strong></td>
<td align="center"><strong><font size="2">Attendance</font></strong> </td>
</tr>
<?php
while($rows=mysqli_fetch_array($result)){
$date = $rows['date']; $date2 = date("d-F-Y", strtotime($date));
$class1 = $rows['class1'];
if ($class1 == 0) $class1 = "No Class"; if ($class1 == 1) $class1 = "Absent";
if ($class1 == 3) $class1 = "Present"; if ($class1 == 2) $class1 = "Late";
?>
<tr>
<td align="center"><font size="2"><?php echo $rows['groupstudents']; ?></font> </td>
<td align="center"><strong><font size="2"><?php echo $date2; ?></font></strong> </td>
<td align="center"><font size="2"><?php echo $class1; ?></font></td>
</tr>
<?php
}
?>
which gives the below output.
Now my question is how to modify my code (use nested loops?!) so the output is:
Thank you kindly.
NB: Sorry, I do not have enough reputation to attach images. I have uploaded them on an external site.
It may not be the best solution, but I cannot think of something better right now.
In the pre-execution I create the grid you want, and in the layout this grid-array is displayed.
<?php
if( isset($_POST['groups'])){
$groups = $_POST['groups'];
$subject = $_POST['subject'];
$sql="SELECT
a.groupcode, a.groupstudents, a.studentid,
b.groupcode, b.coursename, b.studentid, b.date, b.class1, b.attend, b.attendno
FROM table_1 a, table_2 b
WHERE b.groupcode = '$groups' AND b.coursename = '$subject' AND
(a.studentid = b.studentid AND a.groupcode = b.groupcode)";
$result=mysqli_query($GLOBALS["___mysqli_ston"], $sql);
$dates = array();
$display = array();
while ($rows=mysqli_fetch_array($result)) {
if (!isset($display[$rows['groupstudents']])) {
$display[$rows['groupstudents']] = array();
}
if (!isset($dates[strtotime($rows['date'])])) {
$dates[strtotime($rows['date'])] = count($dates);
}
$class1 = $rows['class1'];
if ($class1 == 0) $class1 = "No Class"; if ($class1 == 1) $class1 = "Absent";
if ($class1 == 3) $class1 = "Present"; if ($class1 == 2) $class1 = "Late";
$display[$rows['groupstudents']][$dates[strtotime($rows['date'])]] = $class1;
}
echo '<table width="100%" border="1" cellspacing="0" cellpadding="3">';
echo '<tr>';
echo '<td align="center"><strong><font size="2">Students</font></strong></td>';
foreach ($dates as $date => $reversedIndex) {
echo '<td align="center"><strong><font size="2">' . date("d-F-Y", $date) . '</font></strong></td>';
}
echo '</tr>';
foreach ($display as $student => $row) {
echo '<tr>';
echo '<td align="center"><font size="2">' . $student . '</font></td>';
foreach ($dates as $date => $index) {
echo '<td align="center"><font size="2">';
if (isset($row[$index])) {
echo $row[$index];
} else {
echo '';
}
echo '</font></td>';
}
echo '</tr>';
}
echo '</table>';
?>