I have a SQL data displayed on a web page and I want to create a dynamic ranking structure for that data. The data will be updated as the new user logs in and updates his data and structure has to update their ranks based on their scores. Like, there are around 20 rows for each user and all the fields of one row should be compared with all the other users' rows and do it for all the rows and update the ranking system.
I have tried checking SQL ranking functions but they were limited to one row, do not know if there are any other options to try them out or there is a completely different way around.
<tr>
<th>Kanto</th>
<th>Johto</th>
<th>Hoenn</th>
<th>Sinnoh</th>
<th>Collector</th>
<th>Scientist</th>
<th>Backpacker</th>
<th>Battle Girl</th>
<th>Berry Master</th>
<th>Gym Leader</th>
<th>Idol</th>
<th>Great League Veteran</th>
<th>Ultra League Veteran</th>
<th>Master League Veteran</th>
<th>Jogger</th>
<th>Breeder</th>
<th>Pikachu Fan</th>
<th>Champion</th>
<th>Battle Legend</th>
<th>Pokemon Ranger</th>
<th>Gentleman</th>
<th>Pilot</th>
<th>Fisherman</th>
<th>Ace Trainer</th>
<th>Youngster</th>
<th>Cameraman</th>
</tr>
<?php
$result=$con->query("SELECT * from user") or die($con->error());
$i=0;
while($row = mysqli_fetch_array($result)){
?>
<tr>
<td><?php echo $row['kanto']; ?></td>
<td><?php echo $row['johto']; ?></td>
<td><?php echo $row['hoenn']; ?></td>
<td><?php echo $row['sinnoh']; ?></td>
<td><?php echo $row['collector']; ?></td>
<td><?php echo $row['scientist']; ?></td>
<td><?php echo $row['backpacker']; ?></td>
<td><?php echo $row['battle_girl'];; ?></td>
<td><?php echo $row['berry_master']; ?></td>
<td><?php echo $row['gym_leader']; ?></td>
<td><?php echo $row['idol']; ?></td>
<td><?php echo $row['great_league_veteran']; ?></td>
<td><?php echo $row['ultra_league_veteran']; ?></td>
<td><?php echo $row['master_league_veteran'];?></td>
<td><?php echo $row['jogger']; ?></td>
<td><?php echo $row['breeder']; ?></td>
<td><?php echo $row['pikachu_fan']; ?></td>
<td><?php echo $row['champion']; ?></td>
<td><?php echo $row['battle_legend']; ?></td>
<td><?php echo $row['pokemon_ranger']; ?></td>
<td><?php echo $row['gentleman']; ?></td>
<td><?php echo $row['pilot']; ?></td>
<td><?php echo $row['fisherman']; ?></td>
<td><?php echo $row['ace_trainer']; ?></td>
<td><?php echo $row['youngster']; ?></td>
<td><?php echo $row['cameraman']; ?></td>
</tr>
<?php
$i++;
} ?>
</table>
So, above is my table showing data. All the fields are numbers and I want the data to be structured dynamically considering all the values from all the rows.
Thanks in advance.
Related
I am new here, so forgive me for being new. I am working on a little site. I am setting up a database for some inventory. I have the below code working, which will create a working link to a html.
foreach($fetchData as $data){
$linkid = $data['lid']??'';
$linkaddress="editradio.php?radioID=$linkid"; ?>
<tr>
<td><?php echo $data['lid']??''; ?></td>
<td><?php echo $data['radio_typ']??''; ?></td>
<td><?php echo $data['user']??''; ?></td>
<td><?php echo $data['badge']??''; ?></td>
<td><?php echo $data['entity']??''; ?></td>
<td><?php echo $data['department']??''; ?></td>
<td><?php echo $data['radio_serial']??''; ?></td>
<td><?php echo $data['setup_date']??''; ?></td>
<td><?php echo $data['author']??''; ?></td>
<td><?php echo "<a href='$linkaddress'>Edit</a>"; ?></td>
<td></td>
I am wondering how I can create a template page which, when someone goes to that link, it will call up the variable in the SQL, and then fill out the page.
I'd prefer to not use a template engine or anything more complicated. Just a simple php template.
i just want data will show if ['stt']==1
Here is the code :
<?php do { ?>
<tr>
<td><?php echo $row_daftaruser['id']; ?></td>
<td><?php echo $row_daftaruser['nama']; ?></td>
<td><?php echo $row_daftaruser['email']; ?></td>
<td><?php echo $row_daftaruser['username']; ?></td>
<td><?php echo $row_daftaruser['password']; ?></td>
<td><?php echo $row_daftaruser['alamat']; ?></td>
<td><?php echo $row_daftaruser['tgl_lahir']; ?></td>
<td><?php echo $row_daftaruser['stt']; ?></td>
</tr>
<?php } while ($row_daftaruser = mysql_fetch_assoc($daftaruser)); ?>
Can somebody help me?
you could try this:
<?php do { ?>
<?php if($row_daftaruser['stt'] == 1): ?>
<tr>
<td><?php echo $row_daftaruser['id']; ?></td>
<td><?php echo $row_daftaruser['nama']; ?></td>
<td><?php echo $row_daftaruser['email']; ?></td>
<td><?php echo $row_daftaruser['username']; ?></td>
<td><?php echo $row_daftaruser['password']; ?></td>
<td><?php echo $row_daftaruser['alamat']; ?></td>
<td><?php echo $row_daftaruser['tgl_lahir']; ?></td>
<td><?php echo $row_daftaruser['stt']; ?></td>
</tr>
<?php endif ?>
<?php } while ($row_daftaruser = mysqli_fetch_assoc($daftaruser)); ?>
This code will only display values if stt is equal to 1.
Also, use mysqli not mysql because it mysql is obsolete.
Why do not you write the query this way?
SELECT * FROM TABLE WHERE stt = 1;
I have a little issue when I try to to loop my php values in HTML. So far this is what I tried but I have not excpected result.
If I remove the loop I only get the first entry. I would like to echo all the possibles entries from my research.
This is my code ( from an SQL request).
<html>
<table>
<tr>
<th>Name</th>
<th>Surname</th>
<th>Number</th>
<th>Adress</th>
<th>link</th>
<!--<th class="glyphicon glyphicon-pencil"></th>-->
</tr>
<tr>
<?php $rowG = oci_fetch_array($stid, OCI_RETURN_NULLS);?>
<?php foreach($array as $rowG=>$value): ?> <tr>
<td><?php echo $rowG[2]; ?></td>
<td><?php echo $rowG[1]; ?></td>
<td><?php echo $rowG[0]; ?></td>
<td><?php echo $rowG[3]?></td>
<td><?php echo "<a href='./consultation.php?Login=$rowG[2]'> Link </a>" ; ?></td>
<?php endforeach;}} ?>
</tr>
</table>
</html>
Do you know where I made my mistake ?
Thank you for your help
Edit : Finally I managed to do it by using a do{}while loop.
Thank you all for your help
RFlow
It's hard to guess what you are trying to do or even what actually happens, since I don't know what is assigned to $rowG, so I tried to hack meaning out of this from the code's errors and came up with that :
<?php
while ($rowG = oci_fetch_array($stid, OCI_RETURN_NULLS)) {
?>
<tr>
<td><?php echo $rowG[2]; ?></td>
<td><?php echo $rowG[1]; ?></td>
<td><?php echo $rowG[0]; ?></td>
<td><?php echo $rowG[3]; ?></td>
<td><?php echo ' Link '; ?></td>
</tr>
<?php
}
?>
If it doesn't work with you, you'll have to provide the informations that should have been included in your question since the begining.
This is basic iteration over query results:
while ($rowG = oci_fetch_array($stid, OCI_RETURN_NULLS)) {?>
<tr>
<td><?php echo $rowG[2]; ?></td>
<td><?php echo $rowG[1]; ?></td>
<td><?php echo $rowG[0]; ?></td>
<td><?php echo $rowG[3]?></td>
<td><?php echo "<a href='./consultation.php?Login=$rowG[2]'> Link </a>" ; ?></td>
</tr>
<?php
}
<?php foreach($array as $rowG=>$value): ?> <tr>
<td><?php echo $rowG[2]; ?></td>
<td><?php echo $rowG[1]; ?></td>
<td><?php echo $rowG[0]; ?></td>
<td><?php echo $rowG[3]?></td>
<td><?php echo "<a href='./consultation.php?Login=$rowG[2]'> Link </a>" ; ?></td>
<?php endforeach;}} ?>
Would be :
<?php foreach($rowG as $arr): ?> <tr>
<td><?php echo $arr[2]; ?></td>
<td><?php echo $arr[1]; ?></td>
<td><?php echo $arr[0]; ?></td>
<td><?php echo $arr[3]?></td>
<td><?php echo "<a href='./consultation.php?Login=$arr[2]'> Link </a>" ; ?></td>
<?php endforeach;}} ?>
Note the use of $arr instead of $rowG.
In the original code $array is not used.
I have a problem with my code.
This rule for my array loop:
I have tried like this :
$line_1=mysql_query("SELECT * FROM loading_plan WHERE line='1' ORDER BY id_load asc");
$total_hr_21 = Array();
while ($l1=mysql_fetch_array($line_1)){
$total_hr[] = $l1[total_hr];
}
This code just describes the array number, but I don't have any idea how to sum this "$l1[total_hr];" per row like in my rule.
[EDIT]
I was implement answer from Karthick Kumar to my coding, that just using array_sum($total_hr_21); and it's work for my rule. so this is my full code :
<?php
error_reporting(0);
include "../config/koneksi.php";
include "../config/library.php";
$today = date("Y-m-d");
$line_1=mysql_query("SELECT * FROM loading_plan WHERE line='1' ORDER BY id_loading asc");
$total_hr_21 = Array();
while ($l1=mysql_fetch_array($line_1)){
$est_time_wobal = $l1[qty_wo] / $l1[uph];
$est_time_wofk = $l1[bal_fk] / $l1[uph];
$total_hr = $est_time_wobal + $est_time_wofk + $l1[setup_time];
$kit_to_ship = ((abs(strtotime ($l1[ship_date]) - strtotime ($l1[susbstore_date])))/(60*60*24));
$balance_days = ((abs(strtotime ($l1[ship_date]) - strtotime ($tgl_sekarang)))/(60*60*24));
$q_days = ((abs(strtotime ($tgl_sekarang) - strtotime ($l1[susbstore_date])))/(60*60*24));
$total_hr_21[] = $total_hr;
?>
<tr>
<td><?php echo "Line#".$l1[line]; ?></td>
<td><?php echo $l1[no_run]; ?></td>
<td><?php echo $l1[susbstore_date]; ?></td>
<td><?php echo $l1[no_prog]; ?></td>
<td><?php echo $l1[product_number]; ?></td>
<td><?php echo $l1[product_desc]; ?></td>
<td><?php echo $l1[wo]; ?></td>
<td><?php echo $l1[qty_wo]; ?></td>
<td><?php echo $l1[bal_wo]; ?></td>
<td><?php echo $l1[bal_fk]; ?></td>
<td><?php echo $l1[uph]; ?></td>
<td><?php echo round($est_time_wobal,2); ?></td>
<td><?php echo round($est_time_wofk,2); ?></td>
<td><?php echo $l1[setup_time]; ?></td>
<td><?php echo round($total_hr,2); ?></td>
<td><?php echo $l1[type_solder]; ?></td>
<td><?php echo $l1[ship_date]; ?></td>
<td><?php echo $kit_to_ship; ?></td>
<td><?php echo $q_days; ?></td>
<td><?php echo array_sum($total_hr_21); ?></td>
<td><?php echo " "; ?></td>
<td><?php echo " "; ?></td>
</tr>
<?php } ?>
Thanks, For help :)
I have pulled some information from a site API and it is stored in $result. I would like to create a table with this information that loops x number of times (constant). Here is how I currently have it repeating by hand and it works. I just imagine there must be a better/easier way to do this then manually repeating it each time.
<tr>
<td><?php echo strtoupper($result['weapons']['0']['stat']['id']); ?></td>
<td><?php echo round($result['weapons']['0']['extra']['accuracy'],2); ?>%</td>
<td><?php echo round($result['weapons']['0']['extra']['kpm'],2); ?></td>
<td><?php echo number_format($result['weapons']['0']['stat']['shots']); ?></td>
<td><?php echo number_format($result['weapons']['0']['stat']['hits']); ?></td>
<td><?php echo number_format($result['weapons']['0']['stat']['kills']); ?></td>
<td><?php echo number_format($result['weapons']['0']['stat']['hs']); ?></td>
<td><?php echo round($result['weapons']['0']['extra']['hkp'],2); ?>%</td>
</tr>
<tr>
<td><?php echo strtoupper($result['weapons']['1']['stat']['id']); ?></td>
<td><?php echo round($result['weapons']['1']['extra']['accuracy'],2); ?>%</td>
<td><?php echo round($result['weapons']['1']['extra']['kpm'],2); ?></td>
<td><?php echo number_format($result['weapons']['1']['stat']['shots']); ?></td>
<td><?php echo number_format($result['weapons']['1']['stat']['hits']); ?></td>
<td><?php echo number_format($result['weapons']['1']['stat']['kills']); ?></td>
<td><?php echo number_format($result['weapons']['1']['stat']['hs']); ?></td>
<td><?php echo round($result['weapons']['1']['extra']['hkp'],2); ?>%</td>
</tr>
I just can't wrap my head around how I would loop this? I have searched and looked at many articles, I just can't seem to get anything to work.
If you'd like to run through every result the easiest way would be to use foreach
e.g.
foreach($result['weapons'] as $tr){ ?>
<tr>
<td><?= strtoupper($tr['stat']['id']) ?></td>
<td><?= round($tr['extra']['accuracy'],2) ?>%</td>
//... etc.
</tr>
<?php } //...
If you'd prefer to define the amount of loops just use "for"
for ($i = 0; $i <= 10; $i++) { ?>
<tr>
<td><?= strtoupper($result['weapons'][$i]['stat']['id']) ?></td>
<td><?= round($result['weapons'][$i]['extra']['accuracy'],2) ?>%</td>
<td><?= round($result['weapons'][$i]['extra']['kpm'],2) ?></td>
//.... etc.
</tr>
<?php }
it's very easy to use foreach loop lets assume you got your value in variable $result_api then loop through this array
$i=0;
foreach($result_api as $result)
{ ?>
<tr>
<td><?php echo strtoupper($result['weapons'][$i]['stat']['id']); ?></td>
<td><?php echo round($result['weapons'][$i]['extra']['accuracy'],2); ?>%</td>
<td><?php echo round($result['weapons'][$i]['extra']['kpm'],2); ?></td>
<td><?php echo number_format($result['weapons'][$i]['stat']['shots']); ?></td>
<td><?php echo number_format($result['weapons'][$i]['stat']['hits']); ?></td>
<td><?php echo number_format($result['weapons']['0']['stat']['kills']); ?></td>
<td><?php echo number_format($result['weapons'][$i]['stat']['hs']); ?></td>
<td><?php echo round($result['weapons'][$i]['extra']['hkp'],2); ?>%</td>
</tr>
<?php
$i++;
}