HTML in PHP which contains PHP - php

Is it possible to put PHP-code surrounded by HTML which is surrounded by PHP?
Here is a little code-snippet. All of that is in PHP-brackets. The browser displays the table but not the PHP values.
echo "<tr>";
echo '<td class="tg-031e"><?php echo $Auftragsnummer;?></td>';
echo '<td class="tg-031e"><?php echo $Modellbezeichnung;?></td>';
echo '<td class="tg-031e"><?php echo $Untersuchungsart;?></td>';
echo '<td class="tg-031e"><?php echo $TUEV_Stelle;?></td>';
echo '<td class="tg-031e"><?php echo $TUEV_Termin;?></td>';
echo "</tr>";
Regards
Bluefox

Concatenation
echo '<td class="tg-031e">' . $Auftragsnummer . '</td>';
But if you have a lot of HTML it's better to close your php tag
<?php your code ?>
<tr>
<td class="yourClass"> <?php echo $yourVar; ?> </td>
<tr>

Look at Concatenation.
You can put a string in an echo command like so:
$string = 'hello world';
echo 'I wanted to say '.$string.'!'; //outputs "I wanted to say hello world!"
so your code should look like:
echo '<tr>';
echo '<td class="tg-031e">'.$Auftragsnummer.'</td>';
echo '<td class="tg-031e">'.$Modellbezeichnung.'</td>';
echo '<td class="tg-031e">'.$Untersuchungsart.'</td>';
echo '<td class="tg-031e">'.$TUEV_Stelle.'</td>';
echo '<td class="tg-031e">'.$TUEV_Termin'.</td>';
echo '</tr>';

you do not need to close the php bracket
do more like this
echo '<td class="tg-031e">' .$Auftragsnummer. '</td>';

You can go for HEREDOC :
$html = <<<HTML
<tr>
<td class="tg-031e">{$Auftragsnummer}</td>
<td class="tg-031e">{$Modellbezeichnung}</td>
<td class="tg-031e">{$Untersuchungsart}</td>
<td class="tg-031e">{$TUEV_Stelle}</td>
<td class="tg-031e">{$TUEV_Termin}</td>
</tr>
HTML
;
echo $html;

echo is PHP. So you should just do something like this :
echo '<td class="tg-031e">'.$Auftragsnummer.'</td>';

Using sprintf().
<?php
echo sprintf('<td class="tg-031e">%s</td>', $Auftragsnummer);
Or, as a loop/array construct:
foreach(array(
$Auftragsnummer,
$Modellbezeichnung,
$Untersuchungsart,
$TUEV_Stelle,
$TUEV_Termin) as $item) {
echo sprintf('<td class="tg-031e">%s</td>', $item);
}

Related

get related data from db via anchor tag

My code:
<?php
if (isset($_GET["q"]))
{
$q= $_GET["q"]; # this is team name
$link=mysqli_connect("localhost","root","");
mysqli_select_db($link,"onesports");
$result=mysqli_query($link," select * from team where team_name='" .$q. " ' ");
$result2=mysqli_query($link,"select players.full_name, team.* from players,team where team.team_name='" .$q. " ' and players.team_name=team.team_name ");
while($row = mysqli_fetch_array($result)) {
?>
<table>
<tr>
<td style="font-size: 30px; font-variant-caps:petite-caps;" > <?php echo $row['team_name']; ?> </td>
<td style="text-transform: capitalize; "> <?php echo "("; echo $row['city'] ; echo ","; echo $row['prov']; echo ")"; ?> </td>
</tr>
<tr>
<td style="text-transform: capitalize;">
<?php echo $row['captain']; echo "(c)"; ?>
</td>
<td style="text-transform: capitalize;"> <?php echo $row['coach']; ?> </td>
</tr>
</table>
<hr>
<?php
}
echo '<table cellpadding="0" cellspacing="0" class="db-table">';
echo "<tr>";
echo "<th>";
echo "Players";
echo "</th>";
echo "</tr>";
while($row = mysqli_fetch_array($result2)) {
echo "<tr>";
echo "<td>";
echo '<a href= " " >' . $row['full_name'] . '</a>';
echo "</td>";
echo "</tr>";
}
echo "</table>";
The problem is that I'm getting full_name dynamically, every name has some details in db I want to get.
When I click on full_name, I want it to give me all the related data from the DB.
This is the part with the links:
echo '<table cellpadding="0" cellspacing="0" class="db-table">';
echo "<tr>";
echo "<th>";
echo "Players";
echo "</th>";
echo "</tr>";
while($row = mysqli_fetch_array($result2)) {
echo "<tr>";
echo "<td>";
echo '<a href= " " >' . $row['full_name'] . '</a>';
echo "</td>";
echo "</tr>";
}
echo "</table>";
So kindly help me. Do you suggest that I use any other tag rather than an anchor tag, or you can tell me how to get data this way?
As I got the point, you need to retrieve the information by clicking the relevant link.
You can use the following structure:
echo ''.$row["full_name"].'';
Then at your server-side code, get the data by using
$_GET['FN']
I hope this answer help you as well as.
browse image
db image
here is both pic browser and db onesports is my db name and players is table name,
in browser image you can see players name i want when i click on players name it show related data on same page
Here is the php code, please review
As I mentioned, because of setting "player_id" as your primary key, you have to fetch the information by using it.
echo ''.$row["full_name"].'';
Your Query should be in the following format:
Select * from `players` Where `player_id` = $_GET['player_id']

how do I update the value of each row without primary key?

I want to update the value in a certain row. But it seems impossible since this table (from database) doesn't have the primary key. It only have two foreign key in its column. What should I do ? please, any help ?
here is my code :
<table align= "center" border="1" cellspacing="0" cellpadding="2">
<?php
$strgettable="select tblUsrGrp.UsrGrpNama, tblmenu.MenuNama, tblmenuakses.MenuAkses
FROM tblUsrGrp
inner join tblMenuAkses
on tblUsrGrp.UsrGrpID = tblMenuAkses.usrgrpid
inner join tblMenu
on tblMenu.menuid = tblMenuAkses.menuid";
$varRecCount=0;
$rs=odbc_exec($dbconnVOT, $strgettable);
if($rs)
{
echo '<tr><td style=width:10%;>';
echo '<center><b> No. </b></center>';
echo '</td>';
echo '<td style=width:30%;>';
echo '<center><b> User Group </b></center>';
echo '</td>';
echo '<td style=width:20%;>';
echo '<center><b> Menu Name </b></center>';
echo '</td>';
echo '<td style=width:20%;>';
echo '<center><b> Menu Akses </b></center>';
echo '</td>';
echo '<td style=width:20%;>';
echo '<center><b> Update </b></center>';
echo '</td></tr>';
while (odbc_fetch_row($rs))
{
$varRecCount++;
echo '<tr><td>';
echo '<center> '.$varRecCount.'</center>';
echo '</td>';
echo '<td>';
echo '<center> '.odbc_result($rs,"UsrGrpNama").'</center>';
echo '</td>';
echo '<td>';
echo '<center> '.odbc_result($rs,"MenuNama").'</center>';
echo '</td>';
echo '<td>';
echo '<center> '.odbc_result($rs,"MenuAkses").'</center>';
echo '</td>';
echo '<td>';
echo '</td>';
echo '</td></tr>';
}
}
?>
</table>
<div style="text-align:center;">
<input type="button" name="btnUpdate" id="btnUpdate" onClick="javascript:sendData('updatedata');" value = "Update">
</div>
any help would be much appreciated . TQ

How do I show database info on my website?

I have a account page on my website where it shows all information about a user but it does not show the username.
Database Name: df
Table to get info from: members
Column that stores all the usernames: user
Screenshot:
So I tried this code but it did not work. You may wonder how I came up with that code: I copied the other code that shows when user is registered.
echo '<tr>';
echo '<td align="left" class="padding_td" width="'.$td_width.'">';
echo 'Registrerad:';
echo '</td>';
echo '<td align="left" class="padding_td">';
echo members($user['user']);
echo '</td>';
echo '</tr>';
When I try this code on my site I get this error:
Fatal error: Call to undefined function members() in
C:\xampp\htdocs\account.php on line 328
Here's the code to show when user is registered (may or may not be helpful):
echo '<tr>';
echo '<td align="left" class="padding_td" width="'.$td_width.'">';
echo 'Registrerad:';
echo '</td>';
echo '<td align="left" class="padding_td">';
echo date_detailed($user['date_registred']);
echo '</td>';
echo '</tr>';
Try this:
echo '<tr>';
echo '<td align="left" class="padding_td" width="'.$td_width.'">';
echo 'Registrerad:';
echo '</td>';
echo '<td align="left" class="padding_td">';
echo $user['user'];
echo '</td>';
echo '</tr>';

Enumerate table rows in html

I have this code which prints a table taken from a search query and I want to enumerate them using PHP. I'm trying a for loop but unsuccessfully. Can anyone please help me?
<table id="students">
<?php
$iterator = new CDataProviderIterator($dataProvider);
//echo count($iterator);
echo '<thead>';
echo '<tr>';
echo '<th>'.Yii::t('default', 'Last Name').'</th>';
echo '<th>'.Yii::t('default', 'First Name').'</th>';
echo '<th>'.Yii::t('default', 'Description').'</th>';
echo '<th>'.Yii::t('default', 'Debit').'</th>';
echo '<th>'.Yii::t('default', 'Credit').'</th>';
echo '<th>'.Yii::t('default', 'Date').'</th>';
echo '<th>'.Yii::t('default', 'Trans number').'</th>';
echo '</tr>' ;
echo '</thead>';
echo '<tfoot>';
echo '<tr>';
echo '<td>'.Yii::t('default', 'Page Total').'</td>';
echo '<td>'."".'</td>';
echo '<td>'."".'</td>';
echo '<td>'."".'</td>';
echo '<td>'."".'</td>';
echo '<td>'."".'</td>';
echo '<td>'."".'</td>';
echo '</tr>';
echo '</tfoot>';
$sumdebit=0;
$sumcredit=0;
foreach($iterator as $rec) {
$sumdebit+=$rec['debit'];
$sumcredit+=$rec['credit'];
echo '<tbody>';
echo '<tr>';
$count=0;
for ($i=0;$i<=40;$i++){
$count+=$i;
echo '<td>'.$count; '</td>';
echo '<td>'.$rec['student']['lastname']; '</td>';
echo '<td>'.$rec['student']['firstname'];'</td>';
echo '<td>'.$rec['transtype']['description']; '</td>';
echo '<td align="right">'.$rec['debit']; '</td>';
echo '<td align="right">'.$rec['credit']; '</td>';
echo '<td>'.$rec['transdate']; '</td>';
echo '<td>'.$rec['transnumber']; '</td>';
}
echo '</tr>';
echo '</tbody>';
}
echo '<tr>';
echo '<td>'.Yii::t('default', 'Total').'</td>';
echo '<td>'."".'</td>';
echo '<td>'."".'</td>';
echo '<td align="right">'.$sumdebit;'</td>';
echo '<td align="right">'.$sumcredit;'</td>';
echo '<td>'."".'</td>';
echo '<td>'."".'</td>';
echo '</tr>';
?>
</table>
My problem is that I want to enumerate the table rows, also I'm not very familiar with the syntax and all of this. I'm trying to make it work in Yii. which I'm not very familiar also. So the problem is I want to put numbers in front of every row. For example I have 20 table rows and I want to start counting and enumerate them. e.g. 1. George Cat 2. Tom Dog 3. John Bird etc..
Your question is unclear, you do not state what your actual problem is.
Therefore we can only guess...
[...]
echo '<tbody>';
echo '<tr>';
for ($i=0;$i<=40;$i++) {
echo '<td>'.$i.'</td>';
[...]
You probably received a syntax error which you apparently either didn't see (look into the error log files!) or simply ignored. At least you did not post it here though it probably exactly points out what the issue is...

soundcloud http request search engine

I want to retrieve XML data from soundcloud using a simple search engine, that retrieves results in a simple results table array
$tracks = "https://api.soundcloud.com/tracks?q=".$var."&client_id=bbba84be29098bdaad6a5de1c048e3e9&limit=10";
$mysongs = simplexml_load_file($tracks);
echo "<table>";
echo '<table cellpadding="0" cellspacing="0">';
echo '<tbody>';
echo '<tr>';
echo '<th>State</th> <th>Name</th><th>Song</th><th>artist</th><th>user</th> <th>user</th>';
echo '</tr>';
echo '</tbody>';
foreach ($mysongs->track->user as $track) {
echo '<tbody>';
echo '<tr>';
echo '<td>';
echo $user->kind;
echo '</td>';
echo " ";
echo '<td>';
echo $user->kind;
echo " ";
echo '</td>';
echo '<td>';
echo $user->kind;
echo " ";
echo '</td>';
echo '<td>';
echo $user->kind;
echo " ";
echo '</td>';
echo '<td>';
echo $user->kind;
echo '</td>';
echo '<td>';
echo $user->kind;
echo '</td>';
echo '</tr>';
echo '</tbody>';
}
this is my code but nothing seems to display as a result, i have tested the same format of code on another api (yelp) and it does work in xml, so what am i missing here? i dont want to use json, i need it to be xml ( the user -> kind ) is just for testing the code right now.
the variable $user doesn't exist. the variable you want is $track. so where you have
echo $user->kind
replace that with
echo $track->kind
you can see the format of the returned object (and it's hierarchy by running the code in the cli and
print_r($mysongs)

Categories