This question already has answers here:
How can I combine two strings together in PHP?
(19 answers)
Closed 4 years ago.
I'm trying to use a php variable to add a href value for a link in an echo statement.
Here's a simplified version of the code I want to use. I know that I can't just add the variable into the echo statement, but I can't seem to find an example anywhere that works.
<i class="fa fa-step-backward"></i> Back
this code will work. kindly use this code in your .php file.
<i class="fa fa-step-backward"></i> Back
and if you want to echo in then use this
<?php
echo "<a href=" . base_index() . "list-job-order?" . $param . " class='btn btn-success btn-flat'><i class='fa fa-step-backward'></i> Back</a>";
?>
Related
This question already has answers here:
Add PHP variable inside echo statement as href link address?
(8 answers)
Closed 3 years ago.
I want to make underline at specific part using href in php.
Please help..
Here is my code..
echo "Welcome " . $row1['name'] . "Sir ";
//I want to make underline only this part: $row1['name'];
You can actually put anchor tag directly inside your php echo
echo "Welcome <a href='#yourlink'>" . $row1['name'] . "</a> Sir ";
<?php
echo " Welcome <a href='hyperlink'>" . $row1['name'] . "</a> Sir ";
?>
This will work, without any flow
This question already has answers here:
How can I combine two strings together in PHP?
(19 answers)
Closed 7 years ago.
Hi I am trying to produce a <td> which also contains an <a> link which will redirect to a function in my controller which also echos the id of my data. Here is my code so far:
<?php
if ($this->session->userdata("username")==$info->U_username) {
echo '<td>EDIT</td>';
}
?>
This code produces an error Disallowed Key characters. Any help or comment is highly appreciated.
For concatenating strings PHP has . operator.
echo '<td>EDIT</td>';
You need to add the result of base_url() to the string you want to output, e.g.:
echo '<td>EDIT</td>';
Either you need to concatinate instead to use php multiple time .use like this
<?php
if ($this->session->userdata("username")==$info->U_username){
echo "<td><a href='".base_url()."'/gamestalker/edit_content/'".$info->C_id."'>EDIT</a></td>";
}
?>
or don't include html into php tags like this
<?php
if ($this->session->userdata("username")==$info->U_username){ ?
<td>EDIT</td>
<? }
?>
You need string concatenation. In PHP you use . for that.
Also codeigniter's base_url can take an argument:
<?php
if ($this->session->userdata("username")==$info->U_username){
echo '<td>EDIT</td>';
}
?>
This question already has answers here:
How to echo php code inside html which is inside php code in this situation? [duplicate]
(2 answers)
Closed 7 years ago.
How can i display form data in echo php ?
My code is:
<?php
echo "<td align='center' style='vertical-align:middle;'> Bust:
<?php
echo $_POST["bust"];
?>
<br> Waist:
<?php
echo $_POST["waist"];
?>
<br> </td>";
?>
But this doesn't work, please guide me with correct steps.
There are a lot of problems with your code.
You're using " in $_POST["bust"] but you opened echo with " as well, causing a conflict.
You're using <?php instead an echo... which is already PHP. There's no need to do this.
It is best to isolate variable printing from your code. Use string concatenation with . as such:
echo "<td align='center' style='vertical-align:middle;'> Bust: ".$_POST["bust"]."<br> Waist: ".$_POST["waist"]."<br> </td>";
This question already has answers here:
What is the difference between single-quoted and double-quoted strings in PHP?
(7 answers)
Closed 8 years ago.
I want my link class to be a variable (I am using the filtering system Isotope).
$categories = get_categories($args);
foreach($categories as $category) {
$name = '.'.$category->name;
echo '<a href="#" data-filter=$name>'; //$name does not work here
echo $category->name;
echo '</a>';
echo ' / ';
}
My $name is only displayed as $name in the browser and not the category name I want. Outside the data-filter echoing $name gives all the categories as expected. Is there a way to solve this problem with putting the $name in the data-filter? If the answer is too difficult, please point me to the right direction of what I should do to fix this problem myself please.
Thanks!
Strings in single quotes do not do variable expansion. You have to change it to something like this:
echo '<a href="#" data-filter='.$name.'>';
An alternative without the need for concatenation would be:
echo "<a href=\"#\" data-filter=$name>";
Or, more elegant in my eyes:
echo sprintf('<a href="#" data-filter=%s>', $name);
Also I guess you have to add double quotes around that data-filter attributes content...
This question already has answers here:
What is the "?" symbol in URL used for in php?
(7 answers)
Closed 9 years ago.
Sorry if this is a stupid question but I want to include two variables in an href
the href is not in a form
<div class="button">
View
</div>
int he page I am sending it to i have a Get method
if (isset($_GET['Name']) && isset($_GET['pid'])) {
$id2 = $_GET['Name'];
$id = $_GET['pid'];
Summary
I want to include $id in the a href so i will be able to get both name and id in the page product.php
You can append as many URL parameters as you like using &:
<a href="<?php fetchdir($ipages); ?>product.php?Name=<?php echo $name; ?>&id=<?php echo $id; ?>" ...
product.php?Name=$name&pid=$pid
You can use & to add two or more GET parameters to a URL.
One good way to build a property encoded is to use the http_build_query function, this will ensure that the data sent in the request is properly encoded.
<?php
$qstr = http_build_query(array("Name"=>$row["Name"], "id"=>$row["pid"]));
?>
<a href="<?php fetchdir($ipages) ?>product.php?<?= $qstr ?>">
This of course can also be done inline
<a href="<?php fetchdir($ipages) ?>product.php?<?= http_build_query(array("Name"=>$row["Namw"], "id"=>$row["pid"])) ?>">