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.
Related
I want to give some values with GET to another site. The value is a ID which is from a database.
The values are stored in $row.
<table>
<?php
foreach ($pdo->query($sql) as $row) {
?>
<tr>
<td><?php echo $row['ID'];?></td>
<td><?php echo $row['Titel'];?></td>
<td><a href='./edit.php?id=$row['ID']>Edit</a></td>
</tr>
<?php
}
?>
How do i have to concenate the string in the third td tag? I want to give the value of the ID to the next page (so the value of the first column of the matching row). I know now it is wrong concenated.
Thanks!
You have not put your php code inside <?php ?> and a closing quote for the href property value is also missing. Compare the corrected code below.
<td>
<a href='./edit.php?id=<?php echo $row['ID']; ?>'>Edit</a>
</td>
<td><a href='./edit.php?id=<?php echo $row['ID'] ?>'>Edit</a></td>
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 already grab a page from webpage and save it in my variable $result. Now I want to explode it because I just want to get 1 row from all page which contain the information that I need. Here is an example of the HTML code that I grab.
<pre>
.....
<tr class="altRowItem">
<td class="center"></td>
<td class="center"></td>
<td class="center"></td>
<td class="fareCol1"></td>
<td class="fareCol2">
<p>
<input id="ControlGroupScheduleSelectView_AvailabilityInputScheduleSelectView_RadioButtonMkt1Fare4" type="radio" value="0~A~~A~RGFR~~1~X|QG~9743~ ~~CGK~04/18/2014 13:10~DPS~04/18/2014 15:55~" name="ControlGroupScheduleSelectView$AvailabilityInputScheduleSelectView$market1"></input>
Rp.1,137,000
</p>
</td>
</tr>
.....
</pre>
I just need string from <p> until </p>. Here is the code that I used.
$arrayResult[] = explode("<td class='fareCol2'>", $result);
echo $arrayResult[1];
There's nothing in $arrayResult[1]. Can anyone help me?
No need for [ ], also match the quotation formatting
$arrayResult = explode( '<td class="fareCol2">', $result);
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.
I have a large form, in the end of the form a user is presented with a summary:
You have entered:
<table>
<tr>
<td>First name</td>
<td><?php echo $firstname ?></td>
</tr>
<tr>
<td>Last name</td>
<td><?php echo $lastname ?></td>
</tr>
</table>
I first designed the summary page and now the thought came to me that it would be nice to send the user this page as a confirmation e-mail. What I have done now is this:
<?php $summarypage = "<table>
<tr>
<td>First name</td>
<td>".$firstname."</td>
</tr>
<tr>
<td>Last name</td>
<td>".$lastname."</td>
</tr>
</table>";
echo $summarypage; ?>
For loops I use $summarypage .= "blabla"; within the loops.
When sending the e-mail I can just take $summarypage and attach it to my e-mail body. Beautiful.
Is what I am doing OK? It seems very "not elegant" to me.
Isn't $summarypage being rendered totally anew when I call it again in my e-mail - meaning all variables concatenated with it (e.g. $firstname) will be called again - performance hog?
Is there some kind of "buffer" I could just write the $summarypage variable to, so I have a plain-text variable afterwards? Would $newsummarypage = string($summarypage) do the trick?
Ignore performance on that level, it won't matter. If the method you show works for you, use it.
An alternative that makes things a bit more readable (because you won't need PHP openers / closers) is HEREDOC:
<?php $summarypage = <<<EOT
<table>
<tr>
<td>First name</td>
<td>$firstname</td>
</tr>
<tr>
<td>Last name</td>
<td>$lastname</td>
</tr>
</table>
EOT;
?>
I think you are a bit confused about how strings/variables work in php. A little example might help
$s = "hello"; //stores the sequence 'h' 'e' 'l' 'l' 'o' in $s
$s = $s." world";//take the sequence stored in $s add the sequence ' world',
//and store in $s again
echo $s; // prints 'hello world'. That is what $s contains, what $s is
$summary = "<div>".$firstname."</div>"; // take '<div>', lookup what $firstname
//contains and add that, then add '</div>' and then store this
//new string thing('<div>Ishtar</div>') in $summary.
echo $summary; //$summary here knows nothing about $firstname,
//does not depend on it
All variables are evaluated when you use them. (Well, most of the time you use variables by evaluating them.)
$summarypage is a string, so it's just a bit of data assigned to a variable - a plain-text variable, as you said. Once the data is assigned to $summarypage, the work is done. You can happily write it out into pages, emails, databases and text files with no additional performance hits related to $summarypage.