Add Numbers to MySQL, HTML table in order [closed] - php

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 will try my best to explain what I am trying to do. Hopefully you can help me out. I have a database that holds links, these links are displayed in a table. I have the entries output properly in order from Points, but I am trying to add a rank number to the side so it says 1, 2, 3, 4, etc going down the page per entry.
Here is my attempt.
<table width = "1000" style='table-layout:fixed;'>
<tr>
// These are the numbers I need to add
<th>Rank</th>
// All these work fine.
<th>Host</th>
<th>Location</th>
<th>Points</th>
</tr>
<?php while($row1 = mysqli_fetch_array($result1)):;?>
<tr>
<td><?php echo $row1[0]; ?></td>
<td><?php echo $row1[1]; ?></td>
<td><?php echo $row1[2]; ?></td>
</tr>
<?php endwhile; ?>
</table>
Hopefully you understand what I am trying to do, if you need any more information let me know.
Thanks for your time.

you mean? :
<?php $rankId=0; while($row1 = mysqli_fetch_array($result1)){ ?>
<tr>
<td><?=$rankId++ ?></td>
<td><?=$row1[0] ?></td>
<td><?= $row1[1] ?></td>
<td><?=$row1[2] ?></td>
</tr>
<?php } ?>

Related

how to get the total of the earnings [closed]

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
the code is expected to calculate the total amount of the "Net Earning" row. How do i write a code to do that. The $stmt variable is associated to a query from the database
<div class="block-card-body">
<div class="my-table table-responsive">
<table class="table align-items-center table-flush mb-0">
<thead class="thead-light">
<tr>
<th>Order ID</th>
<th>Amount</th>
<th>Fee</th>
<th>Net Earning</th>
<th>Date</th>
</tr>
</thead>
<tbody>
<tr>
<?php
foreach ($stmt as $val) {
?>
<td><?php echo $val['PAY_ID']; ?></td>
<td class="text-color">$<?php echo $val['PAY_AMOUNT']; ?></td>
<td class="text-danger">$<?php echo ($val['PAY_AMOUNT']) * 0.1 ; ?></td>
<td class="text-success">$<?php echo $val['PAY_AMOUNT'] - (($val['PAY_AMOUNT']) * 0.1) ; ?></td>
<td><?php echo $val['PAY_DATE']; ?></td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</div><!-- end block-card-body -->
Create a variable to use as an accumulator, initialise it to zero.
Then in the loop, calulate the net and add it to your accumulator. How you display it is up to you later.
Also note, I moved the <tr> inside the loop so you get a well formed table row
<tbody>
<?php
$netTotal = 0;
foreach ($stmt as $val) {
?>
<tr>
<td><?php echo $val['PAY_ID']; ?></td>
<td class="text-color">$<?php echo $val['PAY_AMOUNT']; ?></td>
<td class="text-danger">$<?php echo ($val['PAY_AMOUNT']) * 0.1 ; ?></td>
<?php
$t = $val['PAY_AMOUNT'] - (($val['PAY_AMOUNT']) * 0.1);
$netTotal += $t;
?>
<td class="text-success">$<?php echo $t;?></td>
<td><?php echo $val['PAY_DATE']; ?></td>
</tr>
<?php
}
?>
</tbody>

how to remove unwanted characters in php webpage? i'm getting like "; "; "; characters by following code [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 4 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
<?php
$result = mysqli_query($con,'SELECT * FROM spray_chart ORDER BY id DESC LIMIT 5');
while($row = mysqli_fetch_array($result))
{?>
<tbody>
<tr>
<td><?php echo $row['date1']; ?></td>
<td><?php echo $row['operator_name']; ?></td>
<td><?php echo $row['equipment']; ?></td>
<td><?php echo $row['bio_chem_name']; ?></td>
<td><?php echo $row['appl_rate_ml']; ?></td>";
<td><?php echo $row['beds']; ?></td>";
<td><?php echo $row['comment1']; ?></td>";
</tr>
</tbody>
<?php } ?>
<td><?php echo $row['appl_rate_ml']; ?></td>";
<td><?php echo $row['beds']; ?></td>";
<td><?php echo $row['comment1']; ?></td>";
These three lines have an extra "; at the end.
try this code
<?php
$result = mysqli_query($con,'SELECT * FROM spray_chart ORDER BY id DESC LIMIT 5');
while($row = mysqli_fetch_array($result))
{?>
<tbody>
<tr>
<td><?php echo $row['date1']; ?></td>
<td><?php echo $row['operator_name']; ?></td>
<td><?php echo $row['equipment']; ?></td>
<td><?php echo $row['bio_chem_name']; ?></td>
<td><?php echo $row['appl_rate_ml']; ?></td>"
<td><?php echo $row['beds']; ?></td>"
<td><?php echo $row['comment1']; ?></td>"
</tr>
</tbody>
<?php } ?>

Change a string color from a json [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I have a json file that looks like this
[{
"name":"P90 | Asiimov (Field-Tested)",
"url":"http:\/\/steamcommunity.com\/market\/listings\/730\/P90%20%7C%20Asiimov%20%28Field-Tested%29\"id=\"resultlink_0",
"price":"<span style=\"color:white\">8.35 USD<\/span>\r\n","image":"http:\/\/steamcommunity-a.akamaihd.net\/economy\/image\/fWFc82js0fmoRAP-qOIPu5THSWqfSmTELLqcUywGkijVjZYMUrsm1j-9xgEObwgfEh_nvjlWhNzZCveCDfIBj98xqodQ2CZknz5rbbOKMyJYYl2STKFNVfw3-x7TBCI24dJuGoOy8-0EKgrv5YaVMbgkOIpJTcbSU_OFYwuo7UIxg_JafJCMqXvqjn_3ejBdkE3axU4\/62fx62f",
"quantity":"71",
"game":"Counter-Strike: Global Offensive"
}]
...
When i want to diplay it i use this code
...
<tr>
<td><?php echo $data->name; ?></td>
<td><img src="<?php echo $data->image; ?>" /></td>
<td><?php echo $data->game; ?></td>
<td style="background:black"><?php echo $data->price; ?></td>
<td><?php echo (int)str_replace(',','',$data->quantity); ?></td>
<td><a target="blank" href="<?php echo $data->url; ?>">Buy</a></td>
</tr>
...
Now the problem is that the color of price is always white, i tryed to change the style of table but color is not changeing.
Any ideas?
The string you are echoing contains colors in it for some reason. Just remove them first using php strip_tags() function.
<td style="background:black"><?php echo (strip_tags($data->price)); ?></td>
You can do it by css property color as below:
<td style="background:black;color:red;"><?php echo $data->price; ?></td>

Select count sql statement with php [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am going to develop a online ticket booking system. I have two database table coach_shedule and seat. coache_shedule contains the coach details information with coach_id as primary key and table seat contains seat that is booked from online.
table "coach_shedule"
coach_id cdate ctime coach_no route
table "seat"
seat_id name seat_no coach_id
I have three select field on browser that returns route, cdate and ctime
using this three field I have get coach_id from coach_shedule table using select query
and I save the seat in table seat that is booked from browser.
Every coach has 40 seat. I want to show on browser using php how many seat is booked of each coach coach.
Here is my problem,
In my code I wanted to show the number of seat of each coach that is booked and I have written code in the last column of html table named "seat booked". but it does not show the proper result. I think I explained my problem properly. Please help me. If you want to know specific point. Please ask me.
<form action="coach_time.php" method="post"><table width="100%" style="font- size:small">
<tr>
<td width="30"></td>
<td>Route</td><td>
<select name="route" size="1" class="selhead" id="cdate" onchange="this.form.submit()">
<option value="Dhaka-Barisal"<?php if($route=="Dhaka-Barisal") {echo "selected";} ?> onclick="this.parentNode.form.submit()">Dhaka-Barisal</option>
<option value="Barisal-Dhaka"<?php if($route=="Barisal-Dhaka") {echo "selected";} ?> onclick="this.parentNode.form.submit()">Barisal-Dhaka</option>
</select>
</td>
</tr></form>
<table width="100%" style="font-size:small">
<tr>
<th>Serial</th>
<th>Date</th>
<th>Time</th>
<th>Coach Type</th>
<th>Day Night</th>
<th>Fare</th>
<th>Seat booked</th>
</tr>
<?php
$sql=mysql_query("select * from coach_shedule where route='$route' and cdate='$cdate'");
$a=1;
while($data=mysql_fetch_row($sql))
{
?>
<tr>
<td align="center"><?php echo $a; ?></td>
<td><?php echo $data[1]; ?></td>
<td><?php echo $data[2]; ?></td>
<td><?php echo $data[4]; ?></td>
<td><?php echo $data[5]; ?></td>
<td><?php echo $data[6]; ?></td>
<td><?php
$coachid=$data[0];
$sql1=mysql_query("select seat_no from seat where coach_id='$coachid'");
$data1=mysql_num_rows($sql);
echo $data1;
?></td>
</tr>
<?php
$a++;
}
?>
</table>
You got an error here:
'$sql1=mysql_query("select seat_no from seat where coach_id='$coachid'");
$data1=mysql_num_rows(**$sql**);'
should be
$data1=mysql_num_rows(**$sql1**);'
You are using the wrong SQL there.
Edit: more explanation

Column wise sum in PHP from HTML table [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am trying to sum of a column
<table width="240" border="1">
<tr>
<td width="94">Name</td>
<td width="130">Current Amount</td>
</tr>
<?php
do {
?>
<tr>
<td><?php echo $row_Record['name']; ?></td>
<td><?php echo $row_Record['current_amount']; ?></td>
</tr>
<?php
}
while ($row_Record = mysql_fetch_assoc($Record));
?>
<tr>
<td colspan="2">Total = </td>
</tr>
</table>
I don't know how to do this kind of sum.
Please any one help me.
Thank you.
By using Jquery, you can do something like that
$(document).ready(function(){
var sum = 0
$(".sum").each(function(){
sum += parseFloat($(this).text());
});
alert(sum);
});
Jsfiddle
Alternatively, you can sum all the values by using PHP when fetching the values.
Something like that:
$sum = 0;
while($read = mysqli_fetch_array()){
$sum += $read['row'];
}
echo $sum; //total
<table width="240" border="1">
<tr>
<td width="94">Nmae</td>
<td width="130">Current Amount</td>
</tr>
<?php
$tmp=0;
do {
$tmp+=$row_Record['current_amount'];
?>
<tr>
<td><?php echo $row_Record['name']; ?></td>
<td><?php echo $row_Record['current_amount']; ?></td>
</tr>
<?php } while ($row_Record = mysql_fetch_assoc($Record)); ?>
<tr>
<td colspan="2">Total = <?php echo $tmp; ?></td>
</tr>
</table>

Categories