For example:
<?php foreach($something as $anotherthing){ ?>
<span id="<?php echo $product_id; ?>"><?php echo $price; ?></span>
<?php if($option == 'select') { ?>
<select name="joe" id="<?php echo $select_id; ?>" > ......
I have no idea how to get the id's into javascript.
HTML is text. JavaScript is text. So - the same way.
getElementById('<?php echo $product_id; ?>');
The same way as in HTML :
document.getElementByID('<?php echo $id?>');
Suggestion, either use $_SESSION or put the variable into a hidden input field that always has the same name, then you can get the value from there and use it as the ID :)
Given you use a syntax similar to product-N or product[N] if you only have a want all products on the page:
document.querySelectorAll('[id^=product]');
if you want just one of those you can use only the first match add [0] just before the ;
Related
Im trying to send the patient ID through a hyperlink, tho while it redirects to the correct page it is not sending the information.
<a href="./patientrecord.php?patient_id="<?php $row["patient_id"]?>><?php echo $row["surname"];?></a>
Please make sure you are going to echo the variable
Echoing a variable:
<?= $echoable_variable_here ?> // Use <?= ?> tags
or
<?php echo $echoable_variable_here ?> // Use echo inside <?php ?> tags
Edit: You have placed echo outside the href attribute tag
Therefore,
Change this:
<a href="./patientrecord.php?patient_id="<?php $row["patient_id"]?>><?php echo $row["surname"];?></a>
to:
<?php echo $row["surname"];?>
or to:
<?php echo $row["surname"];?>
I have a code like this.
If the $j or $get_book_rating value is '1' then I need to change the select box colour to red or highlight and show the value(if the value is 1). Else let it show the
normal select box with no styles applied. How can I achieve that?
<?php $get_book_rating = $row['book_rating']; ?>
<select name="<?php echo $bookName ?>" id="<?php echo $bookId ?>">
<?php for($j=0;$j<2;$j++){ ?>
<option <?php if($j == $get_book_rating) echo 'selected="selected"'; ?>><?php echo $j; ?></option>
<?php } ?>
</select>
In other words, I need to check the value of $j and also $get_book_rating and if the value is '1' i need to highlight or show some styles to the select box.
Is that possible.
Thanks,
Kimz
Hope below code may be help you- Not tested but you can use logic as i have write:
You can change condition as per your requirement
<?php $get_book_rating = $row['book_rating']; ?>
<?php
$className='';
$str='';
for($j=0;$j<2;$j++){
if($j=='1' || $get_book_rating=='1') // you need to change condition here as per your requirement
{
$className='highlight';
$str.="<option selected='selected'>". $j ."</option>";
}
else
$str.="<option>". $j ."</option>";
}
$select="<select name='".$bookName."' id='".$bookId."' class='".$className."'>";
echo $select . $str ."</select>";
?>
//Define css for class highlight in css like color,width etc
I am using the jQuery Hovercard plugin (here) and trying to impliment it with user images pulled from Facebook with their php sdk, here is the code I am using to display the Hovercard:
<?php
$friends = $this->facebook->api('/me/friends');
foreach ($friends["data"] as $value) { ?>
<label id="demo-facebook" data-hovercard="<?php echo $value['id'] ?>">
<img src="https://graph.facebook.com/<?php echo $value["id"] ?>/picture" alt="<?php echo $value["name"] ?>" />
</label>
<?php }
?>
The problem I am having is that the Hovercard will only show for the first users image displayed, after that no Hovercard will show when the image is moused over ?
You should change the CSS selector "demo-facebook" from an id to a class. I haven't used HoverCard before, but that seems like it would be the problem.
An ID specifies one specific element of a page, whereas a class can be re-used on multiple elements.
Also, I think it would be easier to just echo the HTML instead of having a <?php echo $value; ?> everytime you have to insert a PHP value. You could just do echo "<img src='$value'>"; instead of <img src="<?php echo $value; ?>" />. Just seems like it would be easier that way.
<?php do { ?>
<?php echo ""; ?><?php echo $row_pageDetails['name']; ?>(<?php echo $row_pageDetails['profile']; ?>) </br>
<?php } while ($row_pageDetails = mysql_fetch_assoc($rspageDetails)); ?>
This gives a clickable link name(profile) but if the profile is empty It shows () how can I improve it so that when the profile record is empty it shows nothing.
You have many unnecessary opening and closing php tags. You should only use one for this whole thing given your code.
And you have a mis-closed </br> tag, should be <br/> and it would be better if you put it after the closing anchor tag.
You can not show the link at all by putting the whole thing in an if statement
<?php
do {
if(!empty($row_pageDetails['profile'])){
echo "<a href=\"$row_pageDetails[website]\">";
echo $row_pageDetails['name'] . "($row_pageDetails[profile])</a><br/>";
}
} while ($row_pageDetails = mysql_fetch_assoc($rspageDetails));
?>
instead of
(<?php echo $row_pageDetails['profile']; ?>)
use ternary operator
<?php echo ($row_pageDetails['profile']) ? '('.$row_pageDetails['profile'].')' : ''; ?>
Your code must be something like this
<?php do {
echo (isset($row_pageDetails['profile']) && !empty($row_pageDetails['profile']))?
''.$row_pageDetails['name'].'('.$row_pageDetails['profile'].')':''; } while ($row_pageDetails = mysql_fetch_assoc($rspageDetails)); ?>
I'm echoing quotes through htmlentities($str) and it works the first time, but it's for caption's on images that are being swapped via jQuery when clicked- then the caption shows the html entity ".
How can I echo the text with quotes so that it still appears as a " instead of the $quot; after clicked?
Here's my html
<div class="smallImageWrapper">
<?php if(empty($row_rsPTN['img1'])): echo "" ?>
<?php else: ?>
<span class="smallImage"><img src="../images/products/pbetn/50x50/<?php echo $row_rsPTN['img1']; ?>" alt="<?php echo htmlentities($row_rsPTN['img1caption']); ?>" name="smallImage" id="smallImage1" height="50px" width="50px" /></span>
<?php endif; ?>
and here's my jQuery to swap the images:
$("#smallImage1").bind("click", function() {
$("#largeimage").attr("src","../images/products/pbetn/180x280/<?php echo $row_rsPTN['img1']; ?>");
$("#largeimage").attr("alt","<?php echo htmlentities($row_rsPTN['img1caption']); ?>");
$(".caption").text("<?php echo htmlentities($row_rsPTN['img1caption']); ?>");
});
here's a link to my test site where you can see it occurring:
http://www.imsmfg.com/new/test/products/ptn.php?menuproduct=Lacing%20Strips
Let me know if you need more info.
Thanks!
Change this line:
$("#largeimage").attr("alt","<?php echo htmlentities($row_rsPTN['img1caption']); ?>");
To this:
$("#largeimage").attr("alt","<?php echo addslashes($row_rsPTN['img1caption']); ?>");
jQuery entitizes things automatically, so you don't need to put entities in that quote. You just need to escape any quotes. Hence addslashes.