Dynamic node php variable sites - php

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.

Related

Achieve dynamic ranking structure for sql data on a web page

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.

How to submit a value from a PHP defined table to a php page for further processing?

I am using a form to submit data to a php page and then presenting it as a table using the method which is working fine for me. Now I want to submit one of the data field ($row->id) to another php page for processing detailed user profile. I tried using the form method as shown in the code but it doesn't work and keeps submitting same value for every profile.
<tr>
<td><?php echo $n++; ?></td>
<td><?php echo $row->id; ?></td>
<td><?php echo $lang[$row->gender]; ?></td>
<td><?php echo $row->age; ?></td>
<td><?php echo $row->height; ?></td>
<td><?php echo $row->edn; ?></td>
<td><?php echo $lang[$row->income]; ?></td>
<td><form action= 'compact.php' method='post'>
<input type ='hidden' name='pid' value="<?php echo $row->id?>">
<input type='submit' name='submit' value='View Details'></td>
</tr>
Any help will be highly appreciated. Thanks
Based on suggestions in the comments to above question, I changed my script as follows and used GET instead of POST at compact.php and was able to successfully capture the posted variable for further processing:
<tr>
<td><?php echo $n++; ?></td>
<td><?php echo $row->id; ?></td>
<td><?php echo $lang[$row->gender]; ?></td>
<td><?php echo $row->age; ?></td>
<td><?php echo $row->height; ?></td>
<td><?php echo $row->edn; ?></td>
<td><?php echo $lang[$row->income]; ?></td>
<td><a href="compact.php?pid=<?php echo $row->id?>">
View details</a></td>
</tr>

Loop php values from an echo in HTML

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.

How to convert xml file to php array? [duplicate]

This question already has answers here:
How to convert XML into array in PHP?
(12 answers)
Closed 7 years ago.
I've got strange xml file like this http://xxx.pl/tmp/tabela.xml, and I don't know how to convert it into an array. I tried something like this:
<?php
$get = file_get_contents('http://xxx.pl/tmp/tabela.xml');
$arr = simplexml_load_string($get);
$data = $arr -> druzyna;
?>
<table>
<tr>
<th>pozycja</th>
<th>pkt</th>
<th>mecze</th>
<th>zwyciestwa</th>
<th>porazki</th>
<th>wygrane w domu</th>
<th>przegrane w domu</th>
<th>wygrane na wyjezdzie</th>
<th>przegrane na wyjezdzie </th>
<th>kosze zdobyte</th>
<th>kosze stracone</th>
<th>stosunek zdobytych punktów do straconych punktów</th>
<th>pelna nazwa klubu</th>
<th>logo klubu</th>
</tr>
<?php foreach($data as $row) : ?>
<tr>
<td><?php echo $row->pozycja ?></td>
<td><?php echo $row->pkt ?></td>
<td><?php echo $row->mecze ?></td>
<td><?php echo $row->zwyciestwa ?></td>
<td><?php echo $row->porazki ?></td>
<td><?php echo $row->wygrane_dom ?></td>
<td><?php echo $row->przegrane_dom ?></td>
<td><?php echo $row->wygrane_wyjazd ?></td>
<td><?php echo $row->przegrane_wyjazd ?></td>
<td><?php echo $row->kosze_zdobyte ?></td>
<td><?php echo $row->kosze_stracone ?></td>
<td><?php echo $row->stosunek_zdob_strac ?></td>
<td><?php echo $row->pelna_nazwa ?></td>
<td><?php echo $row->logo; ?></td>
</tr>
<?php endforeach;?>
</table>
but it's not working.
I read something about json solution, but i don't know how to use it, however I met first time xml format like that.
I think that this topic How to convert xml into array in php? isn't solution of my problem, because i've got another xml file..
simplexml_load_string returns an SimpleXMLElement object. You can query the object (search your data) by using the xpath() function.
Because of how your XML file is set up, the values are set as attributes.
So you need to retrieve the attributes before you can read them.
<?php
$get = file_get_contents('http://xxx.pl/tmp/tabela.xml');
$arr = simplexml_load_string($get);
$data = $arr->xpath('tabela/druzyna');
?>
<table>
<tr>
<th>pozycja</th>
<th>pkt</th>
<th>mecze</th>
<th>zwyciestwa</th>
<th>porazki</th>
<th>wygrane w domu</th>
<th>przegrane w domu</th>
<th>wygrane na wyjezdzie</th>
<th>przegrane na wyjezdzie </th>
<th>kosze zdobyte</th>
<th>kosze stracone</th>
<th>stosunek zdobytych punktów do straconych punktów</th>
<th>pelna nazwa klubu</th>
<th>logo klubu</th>
</tr>
<?php foreach($data as $row) : ?>
<?php
$row = $row->attributes();
?>
<tr>
<td><?php echo $row->pozycja ?></td>
<td><?php echo $row->pkt ?></td>
<td><?php echo $row->mecze ?></td>
<td><?php echo $row->zwyciestwa ?></td>
<td><?php echo $row->porazki ?></td>
<td><?php echo $row->wygrane_dom ?></td>
<td><?php echo $row->przegrane_dom ?></td>
<td><?php echo $row->wygrane_wyjazd ?></td>
<td><?php echo $row->przegrane_wyjazd ?></td>
<td><?php echo $row->kosze_zdobyte ?></td>
<td><?php echo $row->kosze_stracone ?></td>
<td><?php echo $row->stosunek_zdob_strac ?></td>
<td><?php echo $row->pelna_nazwa ?></td>
<td><?php echo $row->logo; ?></td>
</tr>
<?php endforeach;?>
</table>
It seems like a normal xml, please try this
$url = "http://example.com/tmp/tabela.xml";
$xml = file_get_contents($url);
$xml = simplexml_load_string($xml);
echo '<pre>';
print_r($xml);

Create looping table with variable from result

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++;
}

Categories