i have a big table where should print 5 php variables.
I am printing this way
echo '
<td valign="center" align="center" colspan="2">Number : <br/>$num</td>
';
but it prints $num not the value of $num
EDIT :
I realized that.
echo '
' <td valign="center" align="center" colspan="2">Number : <br/>'.$num.'</td> ';
Thank you for help :)
Single quoted PHP strings do not interpolate variables. Double quoted strings do. Use a double quoted string.
Better yet, don't build up HTML in strings in the first place. Drop into PHP mode only when you need access to PHP.
<td valign="center" align="center" colspan="2">Number : <br/><?php echo $num;?></td>
Related
OK I know the code for editable field working in HTML, inline edit. But I am unable to use the same i PHP code
I am attaching below HTML working one and PHP in echo where I am lacking
Please Guide
Thanks
HTML (WORKING)
<td style="text-align:center;" contenteditable="true" data-old_value="<?php echo $row1["view"];?>" onBlur="saveInlineEdit(this,'view','<?php echo $row1["id"]; ?>')" onClick="highlightEdit(this);"><?php echo $row1["view"]; ?></td>
PHP (Surely there is a mistake by me - Not Working)
echo "<td style='text-align:center;' contenteditable='true' data-old_value='<?php echo $row1["view"];?>' onBlur='saveInlineEdit(this,"view","<?php echo $row1["id"]; ?>")' onClick='highlightEdit(this);'><?php echo $row1["view"]; ?></td>
<?php echo is only used when you're in HTML output mode and need to get back into PHP execution. But you're already executing PHP. It doesn't do anything special inside a string, it's just echoed literally.
Just use normal variable substitution or concatenation.
echo "<td style='text-align:center;' contenteditable='true' data-old_value='{$row1["view"]}' onBlur='saveInlineEdit(this,\"view\",\"{$row1["id"];\")' onClick='highlightEdit(this);'>{$row1["view"]}</td>
Also, you need to escape the literal " inside the string.
I doubt that the excepted answer will work, atleast one " is missing. I also prefer concatenation, since it is better readable.
Concatenation:
echo '<td style="text-align:center;" contenteditable="true" data-old_value="' . $row["notess"] . '" onBlur="saveInlineEdit(this,\"notess\",' . $row["id"] . ')" onClick="highlightEdit(this);">' . $row["notess"] . '</td>';
you could also go the dirty way with output buffering:
<?php ob_start(); ?>
<td style="text-align:center;" contenteditable="true" data-old_value="<?php echo $row1["view"];?>" onBlur="saveInlineEdit(this,'view','<?php echo $row1["id"]; ?>')" onClick="highlightEdit(this);"><?php echo $row1["view"]; ?></td>
<?php ob_end_clean(); ?>
I have a little bit more complicated row than I can handle.
I am echoing and I got lost in the " ', could someone help me out and tell me how to have this line correctly?
echo '<td style="text-align: center"><a onclick=" window.open('/edit.php?id=' . $row['id'] . ','_self')"><img height="30" width="30" src="/wp-content/themes/sparkling/edit.png"/></a></td>';
Escape single quotation?
echo '...<a onclick=" window.open(\'/edit.php?id=...';
Edit
To show single quotation in string wrapped with single quotation, you need to escape it, like this
echo 'Hello \' world';
So your code should be
echo '<td style="text-align: center"><a onclick=" window.open(\'/edit.php?id=' . $row['id'] . '\',\'_self\')"><img height="30" width="30" src="/wp-content/themes/sparkling/edit.png"/></a></td>';
Use the heredoc syntax to create the string and your " and ' can be used freely inside the string.
See manual about heredoc http://php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc
Example of heredoc:
https://3v4l.org/SJTBO
I don't know about a third quotation mark in code.
But, using "heredoc" syntax is really usefull when you want/need to keep both the single and double quotes unescaped.
Using it, your code should look like this:
echo <<<EOD
<td style="text-align: center">
<a onclick="window.open('/edit.php?id='{$row['id']}', '_self')">
<img height="30" width="30" src="/wp-content/themes/sparkling/edit.png"/>
</a>
</td>
EOD;
Think about using { } around your variables to make them more visible.
See documentation about it here: http://php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc
At the beginning I would like to say that this is my first post and I apologize in advance for any possible mistakes. And these are my beginnings in programming.
I have a problem with appropriate action download.php in the following code snippet:
<?php
$cv= $row[25];
$output .= '
<tr>
<td> <a href='download.php?dow=$cv'>Download</a> </td>
</tr>
';
?>
I wish it worked like the following code (in which it operates correctly):
<tr>
<td><?php echo "<a href='download.php?dow=$cv'>Download</a><br>"; ?></td>
</tr>
You need to concatenate the string. To concatenate you use a dot . This will put the variable value inside your string.
<?php
$output .= "
<tr>
<td><a href='download.php?dow=".$cv."'>Download</a> </td>
</tr>
";
you closed string before it's even finished!
the $output is a variable and you tried to store the HTML as an string inside it, but you've closed the ' sign before the download.php?dow=$cv and then opened it again. the correct way to write it is:
<?php
$cv= $row[25];
$output .= "
<tr>
<td> Download </td>
</tr>
";
?>
the \ before " called escaping and is needed because we dont want to end our string! just want to add that quote sign as a character like the others.
I am using the following code for display the table row
$tableRow="<tr>
<td style='text-align:center'>".$services[$i]['serviceName']."</td>
<td style='text-align:center'>".$services[$i]['serviceDesc']."</td>
<td style='text-align:right'>".$services[$i]['taxAmt']."</td>
</tr>";
But only value is display.I got the following out
test tset 43500
I want like these
<tr>
<td style='text-align:center'>test</td>
<td style='text-align:center'>tset</td>
<td style='text-align:right'>43500</td>
</tr>
You can use php function for display your value
$tableRow="<tr>
<td style='text-align:center'>".$services[$i]['serviceName']."</td>
<td style='text-align:center'>".$services[$i]['serviceDesc']."</td>
<td style='text-align:right'>".$services[$i]['taxAmt']."</td>
</tr>";
echo htmlentities($tableRow);
replace < by < and > by >
You can use the tag inside any variable like :
$a = '<b>hell</b>';
then pass the variable to view;
$this->load->view('view_name',$a);
You want to display the literal source of HTML so you can use htmlspecialchars htmlspecialchars will do a character translation, pasted here for reference
Character Replacement
& &
" "
' '
< <
> >
You should call it like this:
echo htmlspecialchars($tableRow, ENT_QUOTES, 'UTF-8');
I am likely to get b'*ch slapped because I haven't searched the forum enough before posting, but I really think I searched all relevant posts already, many seem not specifically covering the question I have, the others fly right over my beginner's head ( as I am new to PHP & js ). That being said...
I have built a PHP code to fetch data from an XML file using the $xml=simplexml_load_file();
No worries there, however one of the needed data 'entries' or 'fields' needs to exist within an onclick and/or an onmouseup javascript function.
The code is as follows:
<?php
$xml=simplexml_load_file('prod_test_feed_sameday.xml');
$max = 8;
$i = 1;
foreach($xml->product as $feed){
if ($i <= $max){
echo "<table id='{$feed->position}' class='prod_container'>
<td class='hidden_mask' id='{$feed->position}'>
</td>
<td class='hidden_image' id='{$feed->position}'><span style='background:url({$feed->prod_image_large}) no-repeat center;'/></span><div><a onmouseup='$('.hidden_image#{$feed->position}').slideToggle('slow');' onclick='$('.hidden_mask#{$feed->position}').hide();'><b>CLOSE</b></a></div>
</td>
<tr>
<td class='prod_image' id='{$feed->position}'>
<span style='background:url({$feed->prod_image_small}) no-repeat center; background-size:contain;'/></span>
</td>
<td rowspan='1' class='info_toggle' id='{$feed->position}'><a onmouseup='$('.hidden_image#{$feed->position}').slideToggle('slow');' onclick='$('.hidden_mask#{$feed->position}').show();><img src='images/zoom_02.png' title='See a larger image of these flowers' /></a>
</td>
</tr>
<tr>
<td colspan='2' class='prod_name' id='{$feed->position}'>{$feed->prod_name}
</td>
</tr>
<tr>
<td colspan='2' class='prod_price' id='{$feed->position}'><span id='{$feed->position}'>from: £{$feed->price}</span><a href='{$feed->prod_link}' target='_blank'><span class='buy_button'> Buy it now! </span></a></td>
</tr>
</table>";
$i++;
}
}
?>
The data and the CSS all work perfectly. There is a href link towards the end of the code, which also works perfectly.
I am racking my brain trying to find the error in my syntax within the onlick function.
I have tried all manners of backslashing, using trial and error, for exampel:
onclick='$(\'.hidden_mask#{$feed->position}\').hide();' or
onclick='\'$('.hidden_mask#{$feed->position}').hide();\'' or
onclick=\''$(\'.hidden_mask#{$feed->position}\').hide();\'' or even
onclick=\''$(\\'.hidden_mask#{$feed->position}\\').hide();\'' <--Freddy Krugar 'slashing' example
At any rate I am at a loss.
Try with double quotes and escape them:
echo " ...
onclick=\"$('.hidden_mask#{$feed->position}').hide();\"
...";
Or
echo " ...
onclick='$(\".hidden_mask#{$feed->position}\").hide();'
...";
DEMO
This way you do the escaping in the PHP only, without needing the Freddy Krugar escaping for the DOM parser.