Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
If <?php echo $jsonObj->data->image; ?> has a value, like 1234.jpg I want to show this:
<img src="https://www.example.com/img/<?php echo $jsonObj->data->image; ?>" />
If <?php echo $jsonObj->data->image; ?> has no value, then <img src="https://www.example.com/img/<?php echo $jsonObj->data->image; ?>" /> should remain hidden.
Any help please?
Use php if-else statement for that.
<?php
if(!empty($jsonObj->data->image)) {
?>
<img src="https://www.example.com/img/<?php echo $jsonObj->data->image; ?>" />
<?php
}
?>
You can add else part and do whatever you want.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I tried this code for displaying an item name, price and a photo from database for searching an item name in a search bar
<?php
try
{
require('connection.php');
$sql2="SELECT * FROM items
where item.item_name like '".$txt1."%'
$result2=$db->query($sql2);
if ($result2->rowCount()!=0) {
foreach ($result2 as $r2) { ?>
<a href="images/<?php echo $r2['item_photo'] ?>" class="fh5co-card-item image-popup">
<figure>
<div class="overlay"><i class="ti-plus"></i></div>
<img src="images/<?php echo $r2['item_photo']?>" alt="Image" class="img-responsive">
</figure>
<div>
<?php echo "<p><span class='price kk'>" ; ?>
<p style="font-family:'georgia';text-align:center;font-size:20px;color:black;"><?php echo ($r2['item_name']); ?></span></p>
<h2 style="font-family:'georgia';text-align:center;font-size:18px;color:grey;"><?php echo ("BD ".$r2['item_price']); ?></h2>
</div>
<?php }
} ?>
The problem is the sql, There is an extra name after where
$sql2="SELECT * FROM items
where item.item_name like '".$txt1."%' ;
There should be only item_name not item.item_name. Change this as:
$sql2="SELECT * FROM items
where item_name like '".$txt1."%';
And your code may be exploited with sql injection. Be carefull for production use this code.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
in my opencart I have image in products category page.
If I have set image in category show in category if I haven't set image show onather one.
<?php if ($thumb) { ?>
<div class="category-img" style="background: url('<?php echo $thumb; ?>') no-repeat;"></div>
<?php }else{ ?>
<div class="category-img" style="background: url(image/catalog/category/default-thum.jpg) 50% 50% no-repeat;"></div>
<?php } ?>
I want to modify code.
If I have set image then show image,
else if
No showing.
Can someone tell me how to modify code?
Use ternary operator .Check this code:
<div class="category-img" style="background: url('<?php echo ($thumb ?: 'image/catalog/category/default-thum.jpg'); ?>') 50% 50% no-repeat;"></div>
http://php.net/manual/en/language.operators.comparison.php
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
i want to change this into html format
echo " http://somedomain/somepath/usn_handler.php?usn='" . $row['usn'] .
"' >" . $row['usn'] . " ";
This will work
?>
link
<?php
If you are just making a link to the same domain omit the full URL
?>
link
<?php
Assuming you want to make a hyper link. But really you should just google first.
I think you mean something like this :
<div>
http://somedomain/somepath/usn_handler.php?usn=<?php echo $row['usn']; ?>' >" <?php echo $row['usn']; ?>
</div>
or :
<div>
<a src="http://somedomain/somepath/usn_handler.php?usn=<?php echo $row['usn']; ?>" > <?php echo $row['usn']; ?></a>
</div>
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I need the data to have a different style if the sold = 0 in the mysql table
and when i use the code below the website shows a blank white page
(?=$vehicle-> this is the vehicle reference
and sold is the column withing the sql table
<?php
if (?=$vehicle->sold?!= 1)
{
<div class="foo">
<div class="fboverlay"></div>
<a>
<img src="/media.php?productId=<?=$vehicle->vehicle_id?>&file=<?=$vehicle->main_image?>" />
</a>
</div>
}
else {
<img src="/media.php?productId=<?=$vehicle->vehicle_id?>&file=<?=$vehicle->main_image?>" />
}
?>
You need to learn the PHP from the basics. Learn about operators, PHP and HTML secion, etc..
Anyway, i fixed your code. The condition is if $vehicle->sold is not equal to 1. But i think, (in your OP you mentioned it should be 0) you want this: $vehicle->sold == 0
//Use sytnax like this. See php opeartors.
if ($vehicle->sold != 1) {
?> <!-- Close the php -->
<div class = "foo">
<div class = "fboverlay"></div>
<img src = "/media.php?productId=<?= $vehicle->vehicle_id ?>&file=<?= $vehicle->main_image ?>" />
</div>
<?php
//Open the php again
} else {
?> <!-- close the php -->
<img src = "/media.php?productId=<?= $vehicle->vehicle_id ?>&file=<?= $vehicle->main_image ?>" />
<?php //Open again
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
This is a code snippet I have and I would like to be able to select the out of PHP. When I try to grab the PHP output and store it into a variable, I receive "undefined".
<h1 id=<?php echo '$test; ?> class="list-name--original">
My last attempt I tried this code:$("h1.list-name--original")[0].outerHTML);
Why not just put all your PHP output in a variable
<script>
var data = '<?=$test?>';
</script>
You can then set the contents of an H1 tag like this
<h1 id="myid"></h1>
<script>
$('h1#myid').text(data);
</script>
Try
<h1 id="<?php echo $test; ?>" class="list-name--original">
in jQuery
$(".list-name--original").html();
or
$("#<?= $test ?>").html();
Try this:
<?php $test = "Hello world!"; ?>
<h1 id="example" class="list-name--original"><?php echo $test; ?></h1>
<script language="javascript">
$("#example").html();
</script>