I have two pages index.php and currentmovies.php. I am trying to display movie name for a given movie in currentmovies.php, but I am unable to display the entire name, only the first word is being displayed. I have written my query in index.php and I am passing the values to currentmovies.php.
Eg: if the movie name is "Lord Of the Rings" only "Lord" is being displayed
//Code in index.php
echo "";
//code in currentmovies.php
<?php
echo "<b><font size='3'>Current Movie:",$_GET['movie_name']," </font></b>";
echo "<p> The movie ",$_GET['movie_name']," was released on ",$_GET['rdate']," and falls under the ",$_GET['genre']," category. </p>";
Thanks for the help
//code in currentmovies.php
<?php
echo "<b><font size='3'>Current Movie: ".$_GET['movie_name']."</font></b>";
echo "<p>The movie ".$_GET['movie_name']." was released on ".$_GET['rdate']." and falls under the ".$_GET['genre']." category.</p>";
Try this:
Pleae do it this way:
<?php
echo '<b><font size="3">Current Movie: '.$_GET['movie_name'].' </font></b>';
echo '<p> The movie '.$_GET['movie_name'].' was released on '.$_GET['rdate'].' and falls under the '.$_GET['genre'].' category. </p>';
Please remember, in this case dot instead of comma.
And one more thing:
If you don't use any variables inside quota, please use single quota, plus for html is much better and easier use single quota, in example:
<font size="3">
Related
As the title reads I am using the echo function to create an h3 string which will insert a php value $lowprice and $highprice. The goal is to have the text read
Here are all the houses whos prices are between $lowprice and $highprice. The code breaks into individual lines like this
Here are all the houses whose prices are between $
100000
and $
500000
:
This is the code I have written, how do I get it all onto one line.
<?php
echo '<caption>';
echo '<h3> Here are all the houses whose prices are between $ </h3>'.$lowprice.'<h3> and $</h3>'.$highprice.'<h3> : </h3>';
echo '</caption>';
?>
<h3> is a block element, meaning it will take up a whole line. I think you want to replace your inner <h3>'s with <span> tags which are inline elements:
Like this:
<?php
echo '<caption>';
echo '<h3> Here are all the houses whose prices are between $ <span>'.$lowprice.'</span>
and $<span>'.$highprice.'</span></h3>';
echo '</caption>';
?>
Or you can simply remove all the inner tags all together, like this:
<?php
echo '<caption>';
echo '<h3> Here are all the houses whose prices are between $'.$lowprice.' and $'.$highprice.'</h3>';
echo '</caption>';
?>
The line breaks appear because you've made several h3 elements. You're closing and reopening h3 tags at every insertion, which is not necessary. The html output of your code is the following:
<h3>Here are all the houses whose prices are between $</h3>
<h3>100000 and $</h3>
<h3>500000 : </h3>
Which automatically adds breaks, since that is the behaviour of h3 elements.
What you need is this:
echo '<h3> Here are all the houses whose prices are between $'.$lowprice.' and $'.$highprice.':</h3>';
Better yet, don't use echo to define your html; html and php are interchangeable within the same file. A cleaner, more readable and more easily maintainable solution would be to form your script like this:
<caption>
<h3>Here are all the houses whose prices are between $<?= $lowprice ?> and $<?= $highprice ?>:</h3>
</caption>
Generally, you switch between php and html like this:
<?php
...do some php
?>
<somehtml></somehtml>
<?php do some more php ?>
<morehtml>...
Note that <?= is a shorthand for <?php echo.
I have a database table that contains these rows, "id" ,"link" and "name"
with link being :
<a href=\"https://www.sample.com/file1.php\">[1-200]< /a> <a href=\"https://www.sample.com/file2.php\">[201-224]< /a>
and name :
item1
I have the following PHP code to get the info from the database and return it to visitors. My problem is that the link for file2.php, is not only applied as hyper link for [201-224], the hyperlink is applied for the rest of the page content also. How do I prevent this? And thanks in advance.
echo "</br> ".$name= $row['name'];
echo "</br> ".$Torrentlink= preg_replace('/\\\\/', '',$row['Torrentlink']);
echo "</br> ";
echo "</br> ";echo "</br> ";
echo "the rest of my text goes here ";
This is a terrible way to handle this type of data. If you know they are all links then you should only be storing the link and the name (of course id and other meta data could be useful). Your current situation allows for too many errors and a maintenance problem for those working behind you. If you do not want to create a record for each link, consider storing them as JSON or some other format.
Example: (Store JSON in DB as VARCHAR)
<?php
//Populate variable from DB
//$TorrentLinks = $row{'Torrentlink'};
$TorrentLinks = '[
{"url":"https://www.sample.com/file1.php","text":"[1-200]"},
{"url":"https://www.sample.com/file2.php","text":"[201-224]"}
]';
//Convert to array
$jsonLinks = json_decode($TorrentLinks,true);
//Iterate and print links
foreach ($jsonLinks as $key => $value) {
echo "{$value["text"]}<br />";
}
Results:
[1-200]
[201-224]
Depending on how you capture the data, you could also use something like htmlspecialchars() to keep the special characters from executing.
I think there's a problem with your preg_replace('/\\\\/', '',$row['Torrentlink']);
/\\\\/ finds text with double backslash \\. It seems that your intention is to find only single backslashes to get rid of them in your links.
So try replacing it with
preg_replace('/\\/', '',$row['Torrentlink']);
For example https://regexr.com/ is a good place to check your regular expressions.
the error was simply the input html text.
the problem was the " < /a> " in the line:
<a href=\"https://www.sample.com/file1.php\">[1-200]< /a> <a href=\"https://www.sample.com/file2.php\">[201-224]< /a>
I had a space before the the backslash.
I'm stuck trying to echo my product descriptions correctly for my eCommerce store.
Is it possible to write formatted HTML (i.e. with elements and tags... to youtube links, etc) as text in a MySQL description field and then echo it with PHP correctly formatted?
At the moment I am using...
<?php
echo "<p>".Helper::encodeHTML($product['description'])."</p>";
?>
...but as I say it doesn't output as formatted.
Thanks for the help! :)
Edit; Fixed for the moment ('less anything changes) with...
echo html_entity_decode($var['string']);
i.e.
echo html_entity_decode($product['description2']);
http://uk1.php.net/manual/en/function.html-entity-decode.php
How about removing the p tag and echo it as is?
<?php
echo Helper::encodeHTML($product['description']);
?>
or echo it with htmlentities() like this:
<?php
echo htmlentities($product['description']);
?>
or echo it directly like this:
<?php
echo $product['description'];
?>
I would like to request information of how to extract a particular value in getpath() function.
currently I placed the following information:
<?php $currentCat = Mage::registry('current_category'); ?>
<?php echo $currentCat->getPath()?>
and the system echo 1/2/5 , where 1 is root of root, 2 is catalog root and 5 is the first simple category.
I would like to extract the third value only (number 5 in this example) in that serie of categories to echo that info only in the page but i tried different appraches with no success.
thank you.
explode(), end()
<?php echo end(explode("/", $currentCat->getPath())); ?>
do you know if I can place a value to retrieve always that 3 level no matter if im placed in another subcategory
Should looks like this:
<?php
$exp = explode("/", $currentCat->getPath());
echo $exp[2];
?>
I would recommend you to take a look at explode() again :)
I've been dealing with some calendar code for a while and i can't seem to find the way..
So, i have this calendar showing tours(Y), months(X) and the respective prices for each combination. Now what i need is to add additional column showing the durations in days of each tour. I did that, and it works fine but i also have to sort them and group by the number of days.
e.g First column (containing the name of the tours) starts by title : "1 day tours" and is followed by the tours whom's duration is 1 day. Than an other title: "2 days tours"..and so on.
To do that i had to create two embed 'foreach' circles. The main 'foreach' displays the titles " X days tours",, than the embed 'foreach' displays the proper tours.
Now my problem is how do i print out the html code????
here is the code:=>
foreach($tour_durations as $d){
**print "<tr><td colspan="4"><b>Tous of <?php echo $d;?> Days</b></td></tr>"**
foreach($result->tour as $tour) {
if($tour->duration == $d){ ?>
<tr>
<td>
<a href="<?php print $tour->tour_url_tracked; ?>"><?php print $tour->tour_name;?>
</a></td>
<?php
print "<td><span class='month of'>".$tour->duration."</span></td>";?>
<= the enclosed by stars, is the problematic code..
What is the rights way to display it?? What's wrong??
I hope i was enought clear! :/
Thanks in advance!!!
echo "<tr><td colspan='4'><b>Tous of ".$d." Days</b></td></tr>";
instead of
print "<tr><td colspan="4"><b>Tous of <?php echo $d;?> Days</b></td></tr>"
should do it