I'm working on a new website with an API of Bol.com and I'm stuck at the moment.
My question is really simple, but i cant solve this issue. I just want to have a number for every div which needs to increase by 1.
This code will result an book within a div:
private static function printIndex($product) {
echo '<div id="indexboxes">';
echo '<div id="itemleft"><img src=" ' . $product->getImagemedium() . ' " width="135" height="210"></div>';
echo '<div id="itemmiddle">';
echo '<div id="itemmiddlename"><h2>' . $product->getTitle() . "</h2></div>";
echo '<div id="itemmiddlepub"><h3> ' . $product->getPublisher() . "</h3></div>";
echo '</div></div>';
}
It needs to be like this:
Number 1
Image
Title
Publisher
Number 2
Image
Title
Publisher
Number 3
Image
Title
Publisher
etc..
The image, title and the publisher is working already.. But the numbers doesnt work.
How can get the numbers in this div?
Thanks!
You can use something better than <h2>. Why not use an ordered list <ol> element and list items <li> instead. You can use CSS counters and li:before to get the "Number ?" before each item.
Why not use HTML and CSS capabilities when they are the most natural way of doing the job? In any case, using this print method and putting ids on your divs will cause ids to be used more than once on the same page. You do not want to do that; ids must be unique.
I suggest you do a static mockup of what you want your page to look like; don't use PHP, use lists for styling, and use CSS to format the text sizes and the 'Number' prefix you want. Then, add the PHP to get the dynamism you want.
I would pass the index into your function by reference: eg:
private static function printIndex($product, &$idx) {
// your code
$idx++;
}
Related
I have got a Wiki, with multiple languages, and a custom Skin. My Sidebar is 100% custom-made. I want to get the Language box in there. If someone uses this markup:
[[iwcode:Pagename]]
I want the link and corresponding Language name to pop up in there. How do i get it into my HTML code?
Please help me!
Best regards,
Max
Inside your skin class, yuou should have access to the iw links through $this->data['language_urls']. If you want the links in your sidebar, you can just copy the code from the other skins:
echo "<ul>";
foreach ( $this->data['language_urls'] as $key => $langLink ) {
echo $this->makeListItem( $key, $langLink );
}
echo "</ul>";
I'm working on laravel php framework , I've a simple question ,
While using blade template engine , I normally use html helper functions
to render forms , links or whatever so .
Now when i try to put a link to specific route , i usually to like that :
{{ HTML::link_to_route('author','TheAuthor')) }}
First parameter takes the route , and the second one takes the string that will appear ,
To make it simpler that code will produce :
TheAuthor
Now I want to replace TheAuthor with an image ,
What can i do ?
Or you can use {{route}}
Ex:
<img src="'.$image.'" />
I know this is not the answer you want to hear - but you cannot pass any image via link_to_route.
The problem is the output from the HTML class is escaped automatically. So if you try to pass this:
{{ HTML::link_to_route('author','<img src="'.URL::base().'assets/images/image.jpg" alt="icon" />')) }}
it comes out like this:
<img src="http://laravel3.dev/assets/images/image.jpg" alt="icon" />
which will just be text on the screen - no image. Instead you need to use URI::to_route('author') and generate the link yourself. So make a helper a like this (not tested):
function link_to_route_image($route, $image)
{
$m = '<a href="'.URL::to_route($route).'">'
. '<img>'.$image.'</img>'
. '</a>';
return $m;
}
It may become tedious if you are doing this all over the place, but in isolated spots the best way to handle this would actually be to wrap your entire link_to_* method call in HTML::decode.
{{ HTML::decode(HTML::link_to_route('author','<img src="{URL::base()}assets/images/image.jpg" alt="icon" />')) }}
There's nothing you can do from the inside of the function (such as wrapping the "title" portion in decode) because the cleaning is happening within the function call, but if you decode the entire link it will render the html properly.
I have a page which includes details of the registered users.
Every html table includes 80-90 users.
For every user there is a $username variable.
I normally show their pictures in a table like the code below.
print "<a href=\"small-avatar-$username.jpg\" target=\"_blank\">
<img src=\"big-avatar-$username.jpg\">
</a>";
But the user can open images in a new tab. I want to show big avatars easily.
My first choice was lightbox-jquery. But because i use twitter-bootstrap in my site, i decided to use default bootstrap and jquery features.
I saw that there is "bootstrap-modals". When user clicks link, i don't plan to show anything more than i big picture.
I tried this:
print "<a href=\"#$username" data-toggle=\"modal\" class=\"img-modal\" >
<img src=\"small-avatar-$username.jpg\" ></a>";
print '</td>';
.
print "<div id=\"$username\" class=\"modal\">";
<img src=\"big-avatar-$username.jpg\">
print "</div>";
.
<script type="text/javascript" id="js">
$('#username').modal();
</script>
I suppose putting $('#username').modal();
for every user to my page will make HTML file huge.
But then I tried class name of anchor like this: $('.img-modal').modal();
But this didn't work.
What would you recommend in this situation?
I would recommend you to use a HTML5 Custom Data Attributes in your <a> tag to identify the username and keep your img-modal class.
"<a href="#myModal" data-username='".$username."' class="img-modal">...
Trigger the call to modal on click on .img-modal (you don't need the data-toggle="modal")
$('.img-modal').click(function(event) {
You can get the value of the username by using
var username = $(this).attr('data-username')
Since you have the username you can replace the src property of your <img> tag in your unique modal with something like.
$("#img-in-modal").attr("src","big-avatar-" + username + ".jpg")
And open your modal
$('#myModal').modal('show')
And finally, make sure bootstrap-modal.js or boostrap.js is included.
I have a form that inserts data into mySQL. It works fine.
After the submission, I have a success page that displays 'part_no'. I need to also show 'add_qty', as well.
How do i alter my post script to show two field data's on the success page?
Here is part of my code (that already works):
$part_no = $_REQUEST['part_no'] ;
header("location: inv_fc_add_success.php?part_no=" . urlencode($part_no));
}
else {
header("location: inv_fc_add_fail.php");
}
?>
Just append it as another $_GET variable i.e part_no="part"&quantity=1
header("location: inv_fc_add_success.php?part_no=" . urlencode($part_no)."&qty=".$quantity );
You need 3 things.
First, you'll need:
$add_qty = $_REQUEST['add_qty'];
Alternatively you can simply use $_REQUEST['add_qty'] directly instead of assigning it to a new variable ($add_qty).
Then instead of:
header("location: inv_fc_add_success.php?part_no=" . urlencode($part_no));
you need:
header("location: inv_fc_add_success.php?part_no=" . urlencode($part_no) . "&add_qty=" . urlencode($add_qty));
Then, on the page inv_fc_add_success.php (which you will need to edit), you display the variable the same way that you display $part_no. As always, you can either assign it to a variable, like you already do at the top, or you can just use $_REQUEST['add_qty'] directory.
There is some HTML code which appears on the page as the result of AJAX request/response. This HTML contains GET requests to another php script. Links containing this requests are not working while "real" HTML (added on the page manually) works normally.
When I open the page source with Ctrl+U I see empty div's (but they actually have HTML retrieved via AJAX) and the full-fledged HTML code added manually. Can't figure out how can I make the AJAX-retrieved links working.
This is how I try to form the HTML code which must be added to the page as the result of AJAX response.
<?php
//some selections from the database...
//all subsequent varibles are the members of $row = mysql_fetch_array($query) array;
$html_to_be_inactive =
'<li id="productID_' . $productID . '">
<a href=work.php?action=deleteFromBasket&productID=' . $productID . ' onClick="return false;">
<img src="images/delete.png" id="deleteProductID_' . $productID . '">
</a> ' . $productName . '(' . $totalItems . ' items) - $' . ($totalItems * $productPrice) . '</li>';
echo $html_to_be_inactive;
?>
And that is it, result of 'echo' appears on the page after successful AJAX request as the simple HTML, and it does nothing when I click the link.
I do not perform DOM 'append' methods as I'm not familiar with DOM yet. I can see all the elements mentioned in $thml_to_be_inactive but the link seems to be really inactive. Also this HTML is absent in the "Ctrl+U" output, I can see it only when I select "Inspect element" in the browser.
The HTML which was added manually operates the same items as usual, but I need AJAX-retrieved HTML to be working as well.
I suspect I need to perform some 'append' method via JavaScript or jQuery, but I don't know how to do it in a proper way.
Thanks.
You need to put your href in quotes.
onClick="return false;" will override the default action (go to href) of your link. You need to bind an other event to the link, or just remove `return false'.
Your links use relative paths.
You're probably inserting the HTML into a page in a different directory, breaking the relative paths.
If so, you need to switch to absolute paths.