PHP Table - Get URL addition from table row [closed] - php

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
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.
Closed last month.
Improve this question
I have the following table which pulls information from a MySql database and shows in the table perfectly.
However, I am trying to get the image in rows 'Edit Record' and 'Link to Record' to be URL
'''a href="editcandidatecard.php?pr=6050'''
The following:
'''
<?php
if(!$employee_details)
{
echo '<tr>No data found</tr>';
}
else{
foreach($employee_details as $key=>$value)
{
?>
<tr>
<td><?php echo $key+1;?></td>
<td><?php echo '<a href="editcandidatecard.php?no=" ' . $row['payroll_number'] . '</a>'?><img src="images/document.gif" height="30" ></td>
<td><?php echo ' ' . $value['payroll_number'] . ''?><img src="images/document.gif" height="30" ></td>
<td><?php echo $value['payroll_number'];?></td>
<td><?php echo $value['title'], ' ', $value ['first_name'], ' ', $value ['last_name'];?></td>
<td><?php echo $value['mobile_number'];?></td>
<td><?php echo $value['home_number'];?></td>
<td><?php echo $value['email_address'];?></td>
</tr>
<?php
}
}
?>
'''
Gives:
The Url shown by:
''''?>'''
Is - editcandidatecard.php?no=
The Url shown by:
''' ' . $value['payroll_number'] . ''?>'''
IS - editcandidatecard.php?no=
I want to achieve a url of editcandidatecard.php?no=6050
Where the 6050 is pulled from the value shown in the 'payroll number'
Many thanks in advance for your help

You have to place images between a tags like below.
<td><?php echo ''; ?><img src="images/document.gif" height="30" /></td>
<td><?php echo ''; ?><img src="images/document.gif" height="30" /></td>
As a more readable and simple approach, the following snippet can be used.
<td><img src="images/document.gif" height="30" /></td>
<td><img src="images/document.gif" height="30" /></td>

Thank you #Ozan Budak
Complete working code:
'''
<?php
if(!$employee_details)
{
echo '<tr>No data found</tr>';
}
else{
foreach($employee_details as $key=>$value)
{
?>
<tr>
<td><?php echo $key+1;?></td>
<td><img src="images/document.gif" height="30" ></td>
<td><img src="images/document.gif" height="30" ></td>
<td><?php echo $value['payroll_number'];?></td>
<td><?php echo $value['title'], ' ', $value ['first_name'], ' ', $value ['last_name'];?></td>
<td><?php echo $value['mobile_number'];?></td>
<td><?php echo $value['home_number'];?></td>
<td><?php echo $value['email_address'];?></td>
</tr>
<?php
}
}
?>
'''

Related

How do you fetch data from the database? [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 1 year ago.
Improve this question
<div id="report-tbl-holder">
<table id="report-tbl" class="table table-stripped table-bordered">
<thead>
<tr>
<th>#</th>
<th>Date/Time</th>
<th>Person's Code/Name</th>
<th>Establishment's/Barangay Code/Name</th>
<th>Temperature</th>
</tr>
</thead>
<tbody>
<?php
$i = 1;
$where = ($eid > 0 && is_numeric($eid)) ? " and e.id = {$eid} " : "";
$tracks = $conn->query("SELECT t.*,Concat(p.firstname,' ',p.middlename,' ',p.lastname)as pname,p.code as pcode, e.name as ename,e.code as ecode from tracks t inner join people p on p.id=t.person_id inner join establishment e on. e.id = t.establishment_id where date_format(t.date_added,'%Y-%m-%d') BETWEEN '{$date_start}' and '{$date_end}' $where order by date(t.date_added) asc");
while($row=$tracks->fetch_assoc()):
?>
<tr>
<td class="text-center"><?php echo $i++; ?></td>
<td><?php echo date("M d, Y h:i A",strtotime($row['date_added'])) ?></td>
<td><?php echo $row['pcode'] . ' - ' . (ucwords($row['pname'])) ?></td>
<td><?php echo $row['ecode'] . ' - ' . (ucwords($row['ename'])) ?></td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
I created a row in my database named "temperature" and wanted to include it in a table on the webpage I have created but I don't know how to call the contents of the newly added row (temperature) to display. It did add a new row because I added "Temperature" in the table header but I don't know how to properly call the values for temperature from the database.
I think that there's a confusion... Here "Temperature" is not a row, but a column.
You can try to add the following code line inside your loop :
<td><?php echo $row['body_temp'] ?></td>
You can simply get the data from database in same manner as you are getting in last table columns . you have to give just newly added column name into $rows array.
<tr>
<td class="text-center"><?php echo $i++; ?></td>
<td><?php echo date("M d, Y h:i A",strtotime($row['date_added'])) ?></td>
<td><?php echo $row['pcode'] . ' - ' . (ucwords($row['pname'])) ?></td>
<td><?php echo $row['ecode'] . ' - ' . (ucwords($row['ename'])) ?></td>
<td><?=$row['body_temp'] ?></td>
</tr>

table redirect to a link error displaying in query

What's wrong with this code?
<td><?php echo '<a href="index.php?page=article&id="$id ' .$row['title'] . '</a>';?> </td>
how to include the "$id" like a parameter?
<?php echo '<a href="index.php?page=article&id='.$id.'>'.$row['title'].'</a>';?>
This will be do the trick if php short tag is on
<td><a href="index.php?page=article&id=<?=$id?>"> <?=$row['title']?> </td>
You can use php in side the html tag. Simply like this.
<td><?php echo $row['title']; ?></td>
You can also try this
<td><?php echo $row['title'];?></td>
or this one also
<td><?php echo ''.$row['title'].''; ?></td>

Nothing on my page with an exception of the header after SQL query and table

I've been troubleshooting for a while now, and I really can't find any answer. Basically this is what it looks like:
When I type the name of a real user: Nothing posted on the page with an exception of the header
When I type a fake user: User has not been found (direct translation from Norwegian in the code)
<?php
include_once("moduler/head.php");
$user = $_GET['user'];
$query1 = $con->query("SELECT * FROM players WHERE name='$user'");
echo $con->error;
if ($query1->num_rows == 0) {
echo "<h1>Ingen spiller funnet med: $user.</h1>";
return;
}
while ($row == mysqli_fetch_array($query1)) {
$styrkeLvl = $row['styrke'];
$beskyttelseLvl = $row['beskyttelse'];
$bueskytingLvl = $row['bueskyting'];
$trehuggingLvl = $row['trehugging'];
$gruvedriftLvl = $row['gruvedrift'];
$fiskingLvl = $row['fisking'];
$kills = $row['kills'];
$deaths = $row['deaths'];
$rank = $row['rank'];
$money = $row['money'];
$donstatus = $row['donationstatus'];
$lastlogin = $row['lastlogin'];
$regtime = $row['registrationtime'];
$rankName = getRankString($rank);
?>
<h1><?php echo $user; ?></h1>
<table class=\"userView\">
<tbody>
<tr><td>Brukerstatus</td>
<td><?php echo $rankName; ?></td>
</tr>
<tr><td>Donasjon status</td>
<td>D<?php echo $donstatus; ?></td>
</tr>
<tr><td>Styrke level</td>
<td><?php echo $styrkeLvl; ?></td>
</tr>
<tr><td>Beskyttelse level</td>
<td><?php echo $beskyttelseLvl; ?></td>
</tr>
<tr><td>Bueskyting level</td>
<td><?php echo $bueskytingLvl; ?></td>
</tr>
<tr><td>Trehugging level</td>
<td><?php echo $trehuggingLvl; ?></td>
</tr>
<tr><td>Fisking level</td>
<td><?php echo $fiskingLvl; ?></td>
</tr>
<tr><td>Drap</td>
<td><?php echo $kills; ?></td>
</tr>
<tr><td>Dødsfall</td>
<td><?php echo $deaths; ?></td>
</tr>
<tr><td>Sist pålogget</td>
<td><?php echo $lastlogin; ?></td>
</tr>
<tr><td>Registreringsdato</td>
<td><?php echo $regtime; ?></td>
</tr>
</tbody>
</table>
<?php
}
?>
Any ideas? I've also tried running the entire thing in an echo with no result
Thanks
All your variables inside the while loop are only available inside the while loop. so you cannot echo them in the tables. so <td><?php echo $rankName; ?></td> will give you an undefined variable error. The same applies for the other variables you are trying to display.
To avoid this you should try to declare your variables globally, or put your table inside the loop.
Also the other issue is that as it is the code inside the loop will never execute because of the double equal (==). You should use double equal (==) for comparison and single equal (=) for assignment.
So you have to change while ($row == mysqli_fetch_array($query1)) to while ($row = mysqli_fetch_array($query1))

how to parse the contents of a particular row of a html table into array

I need to pass a one of these row contents of features-table to an array. But the problem is I used an iframe to display the table. And I need it to happen when after clicking the image of particular row.
In main.php
<iframe id="ifrm" src="reserved_tables/reserved_rooms_table.php"></iframe>
In reserved_rooms_table.php
<?php
include '../core/init.php';
$username = $user_data['username'];
$que = "SELECT * FROM ordered_rooms WHERE `username` LIKE '$username'";
$reslt = mysql_query($que);
echo '<table class="features-table" >';
echo '<thead>
<tr>
<td></td>
<td>Date</td>
<td>Start At</td>
<td>End At</td>
<td>Action</td>
</tr>
</thead>
<tbody>';
while($row = mysql_fetch_array($reslt)){
echo '<tr><td>' . $row['room_name'] .' </td><td> '. $row['date'] . '</td><td>'. $row['s_at'].'hrs</td>
<td>'. $row['e_at'].'hrs</td><td><input type="image" src="../images/cross.png" onclick="delete();" value=""></td></tr>';
}
echo "</tbody></table>";
mysql_close(); //connection closed
?>
It isn't entirely clear what you're trying to do. If you want to take data from an HTML table row and send it to a PHP array after a click then you'll need to use javascript.
Keep it simple. Create a link that sends the data to whatever URL/file does the processing:
while ($row = mysql_fetch_array($reslt)) {
?>
<tr>
<td><?php echo $row['room_name'] ?></td>
<td><?php echo $row['date'] ?></td>
<td><?php echo $row['s_at'] ?>hrs</td>
<td><?php echo $row['e_at'] ?>hrs</td>
<td><a id="my_link" href="some_file.php?room_name=<?php echo $row['room_name'] ?>&date=<?php echo $row['date'] ?>&s_at=<?php echo $row['s_at'] ?>&e_at=<?php echo $row['e_at'] ?>"><input type="image" src="../images/cross.png" value=""><a/></td>
</tr>
<?php
}
The data will then be available to some_file.php in $_GET.
Note that you can still use javascript to process this dynamically. You could add a click function to the link, so that when it is clicked, it does an AJAX call using the href value. For example:
$('#my_link').click(function() {
$.ajax({
url: this.href
});
});

Echoing specific element IDs' values in multi-dimensional array

I am programming a script to output sorted information grabbed from the PubMed Central API. My issue is that I would like to pull the first and second authors as well as the first an second keywords (for the purposes of this question, we can focus on just one). A good example of this is at $xml->GetRecord->record->metadata->article->front->{'article-meta'}->{'contrib-group'}->contrib->name->surname. I can, obviously, get the first name to print.
It is my understanding from reading other posts that I need a foreach loop to achieve what I desire. I do not, however, understand how to implement this in this context. My code is as follows:
<?php
$PMCID = 3545513;
$url = 'http://www.pubmedcentral.nih.gov/oai/oai.cgi?verb=GetRecord&identifier=oai:pubmedcentral.nih.gov:'.$PMCID.'&metadataPrefix=pmc_fm';
$xml = new SimpleXMLElement(file_get_contents($url));
?>
<table>
<tr>
<td>Journal Title</td><td>Year</td><td>Issue</td><td>NOC_Country</td><td>State</td><td>City</td><td>Primary Institution</td><td>Secondary Institution</td><td>First Author</td><td>Second Author</td><td>Topic</td><td>Target Behavior 1</td><td>Target Behavior 2</td><td>Population</td><td>Paper</td><td>Status</td>
</tr>
<tr>
<td><?php echo $xml->GetRecord->record->metadata->article->front->{'journal-meta'}->{'journal-title-group'}->{'journal-title'};?></td>
<td><?php echo $xml->GetRecord->record->metadata->article->front->{'article-meta'}->{'pub-date'}->year;?></td>
<td><?php echo $xml->GetRecord->record->metadata->article->front->{'article-meta'}->issue;?></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td><?php echo $xml->GetRecord->record->metadata->article->front->{'article-meta'}->{'contrib-group'}->contrib->name->surname;?>, <?php echo $xml->GetRecord->record->metadata->article->front->{'article-meta'}->{'contrib-group'}->contrib->name->{'given-names'};?></td>
<td><?php echo $xml->GetRecord->record->metadata->article->front->{'article-meta'}->{'contrib-group'}->contrib->name->surname;?>, <?php echo $xml->GetRecord->record->metadata->article->front->{'article-meta'}->{'contrib-group'}->contrib->name->{'given-names'};?></td>
<td><?php echo $xml->GetRecord->record->metadata->article->front->{'article-meta'}->{'title-group'}->{'article-title'};?></td>
<td><?php echo $xml->GetRecord->record->metadata->article->front->{'article-meta'}->{'kwd-group'}->kwd;?></td>
<td><?php echo $xml->GetRecord->record->metadata->article->front->{'article-meta'}->{'kwd-group'}->kwd;?></td>
<td></td>
<td><?php echo $xml->GetRecord->record->metadata->article->front->{'article-meta'}->{'article-categories'}->{'subj-group'}->subject;?></td>
<td></td>
</tr>
</table>
Any help would be greatly appreciated!
Ended up with:
<table>
<tr>
<td><strong>Journal Title</strong></td><td><strong>Year</strong></td><td><strong>Issue</strong></td><td><strong>First Author</strong></td><td><strong>Second Author</strong></td><td><strong>Topic</strong></td><td><strong>Target Behavior 1</strong></td><td><strong>Target Behavior 2</strong></td><td><strong>Paper</strong></td>
</tr>
<?php
$PMCID = $_REQUEST['PMCID'];
$url = 'http://www.pubmedcentral.nih.gov/oai/oai.cgi?verb=GetRecord&identifier=oai:pubmedcentral.nih.gov:'.$PMCID.'&metadataPrefix=pmc_fm';
$xml = new SimpleXMLElement(file_get_contents($url));
?>
<tr>
<td><?php echo $xml->GetRecord->record->metadata->article->front->{'journal-meta'}->{'journal-title-group'}->{'journal-title'};?></td>
<td><?php echo $xml->GetRecord->record->metadata->article->front->{'article-meta'}->{'pub-date'}->year;?></td>
<td><?php echo $xml->GetRecord->record->metadata->article->front->{'article-meta'}->issue;?></td>
<?php
$n=0;
foreach($xml->GetRecord->record->metadata->article->front->{'article-meta'}->{'contrib-group'} as $author){
echo "<td>" . $author->contrib->name->surname . ", ";
echo $author->contrib->name->{'given-names'} . "</td>";
$n++;
if($n==2) break;
}
unset($n);
unset($author);
?>
<td><?php echo $xml->GetRecord->record->metadata->article->front->{'article-meta'}->{'title-group'}->{'article-title'};?></td>
<?php
$i=0;
foreach($xml->GetRecord->record->metadata->article->front->{'article-meta'}->{'kwd-group'}->kwd as $keyword){
echo "<td>" . $keyword . "</td>";
$i++;
if($i==2) break;
}
unset($i);
unset($keyword);
?>
<td><?php echo $xml->GetRecord->record->metadata->article->front->{'article-meta'}->{'article-categories'}->{'subj-group'}->subject;?></td>
</tr>
</table>

Categories