PHP echo results into a table [closed] - php

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 8 years ago.
Improve this question
I am struggling to put the data that is pulled from my database into a table layout.
This is the echo result:
echo "<p><h3>".$results['ID Number']."</h3>".$results['id_number']."</p>";
echo "<p><h3>".$results['Card Status']."</h3>".$results['card_status']."</p>";
echo "<p><h3>".$results['Full Name']."</h3>".$results['full_name']."</p>";
echo "<p><h3>".$results['DBS/CRB Number']."</h3>".$results['dbs_number']."</p>";
echo "<p><h3>".$results['Job Title']."</h3>".$results['job_title']."</p>";
echo "<p><h3>".$results['Card Start Date']."</h3>".$results['card_start_date']."</p>";
echo "<p><h3>".$results['Card Expiry']."</h3>".$results['card_expiry_date']."</p>";
echo "<img src='photos/".$results['photo_name']."'>";
Please can someone help me, its driving me crazy, also the Name of the result isn't showing, e.g. 'ID Number' as a title then 'id_number' result.
or is there an easier way to show all the data from the record rather than having multiple echo's
I have a search box to find a record matching the id_number and then the data connected to a id_number is then shown

Well I dont think there was any help needed , still for the sake of your blockade use this as
echo "<table><tr><td><h3>ID Number</h3></td><td>".$results['id_number']."</td></tr>";
echo "<tr><td><h3>Card Status</h3></td><td>".$results['card_status']."</td></tr>";
echo "<tr><td><h3>Full Name</h3></td><td>".$results['full_name']."</td></tr>";
echo "<tr><td><h3>DBS/CRB Number</h3></td><td>".$results['dbs_number']."</td></tr>";
echo "<tr><td><h3>Job Title</h3></td><td>".$results['job_title']."</td></tr>";
echo "<tr><td><h3>Card Start Date</h3></td><td>".$results['card_start_date']."</td></tr>";
echo "<tr><td><h3>Card Expiry</h3></td><td>".$results['card_expiry_date']."</td></tr>";
echo "<tr><td></td><td><img src='photos/".$results['photo_name']."'></td></tr></table>";

I'd personally store those into an array and loop over it.
Something like this:
<?php
$array = array();
$array[] = $results['ID Number'] . ' ' . $results['id_number'];
//And so on until all the values you want are in the array.
//You could potentially use a loop for this too, depending on your code
echo '<table>';
foreach($array as $value){
echo '<tr>';
echo '<td> $value </td>';
echo '</tr>;
}
echo '</table>';
As for the name of the result not showing up. It's hard to pin point that out without looking at the rest of the code.

Related

Looking for proper way to inject HTML table into PHP code [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 5 years ago.
Improve this question
Let me start by saying that i'm sorry if this is a complete noob question.
while using phpStorm, I have an array of $teams and by invoking foreach loop I tried to put each of the array section into an HTML table
here is what I did so far
I am getting cannot use [] for reading, I can't find an answer how to do that properly, thx in advance.
<table>
<tr>
<th>Team</th>
<th>ID</th>
</tr>
<?php
include dirname(__FILE__) . "/stats.php";
global $teams;
foreach ($teams['data'] as $team) {
echo "<tr>" ;
echo "<td> $team['name']</td>" ;
echo "<td> $team ['id']</td> " ;
echo "</tr>";
}
?>
</table>
To get the string substitution working correct, you have to suround it with {} if it's something more complex than a simple var - especially array access.
echo "<td> {$team['name']}</td>";

Trying to make this entire line of code into a hyperlink [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 5 years ago.
Improve this question
echo <a href = 'test.php'> "CategoryID: " . $row["CategoryID"]. " - Category Name: ".$row["CategoryName"]. </a> "<br>";
This is what i have an is not working properly.
This:
echo "<a href = 'test.php'>CategoryID: {$row['CategoryID']} - Category Name: {$row['CategoryName']}</a><br />";
I am using the { and } as they allow you to include an array in a string and ignore the concatenation which I find harder to read.
I find it funny that you can loop through a MySQL array but can't echo a simple string :P
Some links (teach a man to fish...):
W3Schools
PHP documentation
Codecademy
Tutorials Point
Try this:
<?php
$link = "";
$link = sprintf("<a href = 'test.php'>CategoryID: %d - Category Name: %s </a><br />", $row['CategoryID'], $row['CategoryName']);
echo $link;
?>
Assuming that $row['CategoryID'] is an integer and $row['CategoryName'] is a string.

php - How do I add div in a php function? [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 7 years ago.
Improve this question
I am trying to add a <div> to my php, but everything I've found on google hasn't worked for me. I don't know what I'm doing wrong. Any ideas on how to add a <div> in a php function for styling purposes only?
<?php
//get_additional is a custom function
ob_start();
echo get_additional('Cosmos','Trades');
echo nl2br("\n");
//I want the div to start here
$buffered = ob_get_clean();
echo $buffered;
$times = $buffered;
$imgurl = 'Images/cat.png';
for($i=0;$i<$times;$i++){
echo '<img src="'.$imgurl.'" />';
}
?>
You need to echo it.
Like you've already used once in your code, echo '<img src="'.$imgurl.'" />';
Now coming back to your code:
<?php
//get_additional is a custom function
ob_start();
echo get_additional('Cosmos','Trades');
echo nl2br("\n");
//I want the div to start here
echo '<div class = "blah">
// whatever you want to do here
</div>';
$buffered = ob_get_clean();
echo $buffered;
$imgurl = 'Images/cat.png';
for($i=0;$i<$times;$i++){
echo '<img src="'.$imgurl.'" />';
}
?>

How can i get the values from the php arrray [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 7 years ago.
Improve this question
I wanted to take the fields such as ResumeParsingStartDate, ResumeParsingExpiryDate, MaxLimitOfParsedResume, NumberOfParsedResume
How can i take those valuse in php
Here is the Eval Link
Here is the array that i have
Here is the updated code :
Note : As stackoverflow's editor allows only 30,000 char the character has 35,000 char, and i can't able to decrease it anyway
You can get the single records like this :
$url = 'http://recruitplushrxmlapidemo.onlineresumeparser.com/hrxml/149Anne%20Marie%20Powell.xml';
$sxml = simplexml_load_file($url);
echo 'ResumeParsingStartDate --> '.$sxml->ResumeAdditionalItems->ResumeAdditionalItem[1]->ResumeParsingStartDate;
echo "<br />";
echo 'ResumeParsingExpiryDate --> '.$sxml->ResumeAdditionalItems->ResumeAdditionalItem[1]->ResumeParsingExpiryDate;
echo "<br />";
echo 'NumberOfParsedResume --> '.$sxml->ResumeAdditionalItems->ResumeAdditionalItem[1]->NumberOfParsedResume;
echo "<br />";
echo 'MaxLimitOfParsedResume --> '.$sxml->ResumeAdditionalItems->ResumeAdditionalItem[1]->MaxLimitOfParsedResume;
echo "<br />";
Use loop for repetitive elements

PHP json_parse trakt API [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 9 years ago.
Improve this question
<?php
$response = file_get_contents("http://api.trakt.tv/shows/trending.json/5d7588c188eeea0074b8d2664d12fffc");
$result = json_decode($response, true);
echo $result['title'][0];
echo "<br>";
echo $result['network'][0];
echo "<br>";
echo $result['air_day'][0];
echo "<br><img style='width:200px;' src='";
echo $result['images'][0]['poster'];
echo "'>";
?>
Ain't working. I don't know why.
I use the the trakt.tv shows API.
Write
echo $result[0]['title'];
instead of
echo $result['title'][0];
Besides, PHP's echo function will print integers and strings, but will fail with array-alike structures. You could use var_dump or var_export instead. Thanks to them, you could scan the structure and you wouldn't ask this question ;)

Categories