handling with single quotes in php codeigniter - php

I want to use html syntax in php and i want to use . instead of <?php ?> my code ig given below ,
$delete='<a class="confirm" onclick="return delete_event(<?php echo $value->id; ?>, '<?php echo base_url() . 'webtv/delete_channels' ?>', '<?php echo current_full_url(); ?>');" href="" ><i class="glyphicon glyphicon-trash text-red del" title="Delete"></i></a>';
Please help me.

<?php
$value = "value_1"; //$value->id;
$baseurl = "base_url"."/webtv/delete_channels"; //base_url()."/webtv/delete_channels";
$fullurl = "current_url"; //current_full_url();
$delete="<a href='#' class='confirm' onclick=\"return delete_event('".$value."','".$baseurl."','".$fullurl."')\" >Click me</a>";
echo $delete;
?>
<script>
function delete_event(var1,var2,var3){
alert(var1+" -- "+var2+" -- "+var3);
}
</script>

You can use sprintf function to solve this issue.
Solution is:
$delete = sprintf('<a class="confirm" onclick="return delete_event(%d, \'%s\',\'%s\');" href="" ><i class="glyphicon glyphicon-trash text-red del" title="Delete"></i>jkhklh</a>', $value->id, base_url() . 'webtv/delete_channels', current_full_url());

I cleaned up your php syntax. I don't quite understand what you're trying to do, but the declaration below should give you an a tag containing what you want (a confirm delete button):
$delete='<a class="confirm" onclick="return delete_event($value->id, '.base_url().'webtv/delete_channels, '.current_full_url().');" href="" ><i class="glyphicon glyphicon-trash text-red del" title="Delete"></i></a>';
If you echo this on your webpage, assuming all of your other links are correct, it should work.

Related

Need help passing two php variables through a url to the next page

I'm new to Php but what I need this php code to do is to pass two variables through the URL like this
<td align="center"><a class="btn btn-danger" href="reserve.php?distroid=<?php echo $row["distroid"] echo $row['orderid']; ?>">Place Order</a></td>
When we try and do it with just distroid, it works completely fine. But I'm unsure how to pass both values.
Any help would be appreciated.
EDIT: SOLVED IT THANK YOU FOR THE HELP ALL
Try to add more key for the query string like this :
<td align="center">
<a class="btn btn-danger"
href="reserve.php?distroid=<?php echo $row["distroid"]; ?>&orderid=<?php echo $row['orderid']; ?>">
Place Order
</a>
</td>
Then you can get both distroid and orderid
Try this query string like this :
<td align="center">
<a class="btn btn-danger"
href="reserve.php?distroid=<?php echo $row["distroid"]."&orderid=".$row['orderid']; ?>">
Place Order
</a>
</td>
Then you can get both variable distroid and orderid
Hi you can try this anchor tag, it will work for you:
<a class="btn btn-danger" href="reserve.php?distroid=<?php echo $row['distroid'];
?>&orderid=<?php echo $row['orderid']; ?>">
Place Order
</a>

How to display html link element inside php script

I am trying to include a php variable inside this php script that displays an html link. What i need is to include my php $row['vin'] variable in the href html link after the ? to pass a value to the page i am linking to. Top code block works but i still need that php variable, bottom is an example of what ive tried which will not work.
Works but missing my php variable:
<?php if($row['instock'] == "Yes")
{
echo '<a href="orderForm.php?">
<span class="glyphicon glyphicon-plus" aria-hidden="true">
</span>
</a>';
}
?>
Does not work:
<td>
<?php if($row['instock'] == "Yes")
{
echo '<a href="orderForm.php?'. $row['vin']">
<span class="glyphicon glyphicon-plus" aria-hidden="true">
</span>
</a>';
}
?>
</td>
You've forgotten the rest of the concatenation logic. It's just a syntax error:
<td>
<?php if($row['instock'] == "Yes")
{
echo '<a href="orderForm.php?'. $row['vin'] . '">
<span class="glyphicon glyphicon-plus" aria-hidden="true">
</span>
</a>';
}
?>
</td>
An alternative to using PHP to echo out great chunks of mostly static content is to instead, drop in and out of the PHP context (ie <?php ... ?>) when necessary and use it like a templating language.
For example
<td>
<?php if ($row['instock'] == "Yes"): ?>
<a href="orderForm.php?<?= htmlspecialchars($row['vin']) ?>">
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
</a>
<?php endif ?>
</td>
See http://php.net/manual/control-structures.alternative-syntax.php

How to pass two PHP variables in HTML button onClick function?

I need to pass these two variables in my HTML button.
$value['_id']
$sellerInfo[0]['City']
The HTML is:
<button id='myBtn' onclick='showproduct()'>Pending</button>
I have tried with this code:
<button id='myBtn' onclick='showproduct("<?php echo $value['_id'];?> , <?php echo $sellerInfo[0]['City']; ?> ")'>Pending</button>
I'm getting an error the second parameter is undefined.
How can I pass the two variables in showproduct()?
The quotes are messed.
Change your code to this:
<button id='myBtn' onclick='showproduct("<?php echo $value['_id'];?>" , "<?php echo $sellerInfo[0]['City']; ?>")'>Pending</button>
Try this
<button id='myBtn' onclick='showproduct("<?php echo $value['_id'];?>" , "<?php echo $sellerInfo[0]['City']; ?>")'>Pending</button>
You can try these tricks in your onClick function from this example
<i class="fa fa-times pl-5 in_time_late_approve" onclick='in_time_late_approve("<?php echo $key ?>", "<?php echo $employee_attendance_item->attendance_in_time ?>")' style="color:green; cursor:pointer" aria-hidden="true"></i>

error in embeding html tags in php

<?php
$id=16;
echo '<td><a class="btn btn-primary" href="edit_news.php?id=$id"><i class="fa fa-pencil fa-fw"></i> Edit</a></td>';
?>
I have a search program that performs search via ajaX,whwre i need to embed html tag with php. Search works fine but when i click on edit button the id cant pass on another page. It shows thathttp://localhost/web/edit_news.php?id=$id. But i cant get the id=16. And error shows Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\web\edit_news.php on line 9. what is the error in my code?
Can any one help me to solve this?
you have change "edit_news.php?id=$id" to "edit_news.php?id='.$id.'". Because data in double quotes treated it like string. or you can use single quotes '. like href='edit_news.php?id=$id'.
<?php
$id=16;
echo '<td><a class="btn btn-primary" href="edit_news.php?id='.$id.'"><i class="fa fa-pencil fa-fw"></i> Edit</a></td>';
?>
just change it quote like ' to " and " to '
<?php
$id=16;
echo "<td><a class='btn btn-primary' href='edit_news.php?id=$id'><i class='fa fa-pencil fa-fw'></i> Edit</a></td>";
?>
OR
<?php
$id=16;
echo '<td><a class="btn btn-primary" href="edit_news.php?id='.$id.'"><i class="fa fa-pencil fa-fw"></i> Edit</a></td>';
?>
Change the single quote with double and double with single Like this :
<?php
$id=16;
echo "<td><a class='btn btn-primary' href='edit_news.php?id=$id'><i class='fa fa-pencil fa-fw'></i> Edit</a></td>";
?>

how to use a variable value in anchor's href

<a href="uploads/templates'.$row[0].'/index.php?id=<?php echo $row[0];?>"
class="btn btn-warning">
View
</a>
above is the button and in this button i want to give a path in which folder named templates should be like templates1 ,templates2, templates3. So the numeric value is a variable and 0to be attached with templates so that the folder can open and the index file can be run..so can any one help me with this
<a href="uploads/templates/<?php echo $row[0]; ?>/index.php?id=<?php echo
$row[0];?>" class="btn btn-warning">
View</a>
OR
<?php
echo '<a href="uploads/templates/'.$row[0].'/index.php?id='.$row[0].'"
class="btn btn-warning">
View</a>';
?>
<a href="uploads/templates<?php echo $row[0];?>/index.php?id=<?php echo $row[0];?>" class="btn btn-warning">
View
</a>
If you are writing PHP code inside HTML, you need to wrap your code in <?php ?>.
Your code should be:
<a href="uploads/templates<?php echo $row[0]; ?>/index.php?id=<?php echo $row[0];?>" class="btn btn-warning">
View
</a>

Categories