I want to set the css TOP property different after every 3 div's
for eg:
<div style="top:100px;">
</div>
<div style="top:100px;">
</div>
<div style="top:100px;">
</div>
**Now after this the next 3 div's shall have**
<div style="top:150px;">
</div>
<div style="top:150px;">
</div>
<div style="top:150px;">
</div>
**Now after this the next 3 div's shall have**
<div style="top:200px;">
</div>
<div style="top:200px;">
</div>
<div style="top:200px;">
</div>
**and so on**
I want to do this dynamically using php.
Using the for loop i can check if
$ij=0; if($ij%3==0) {
echo "";
}
else {
}
But not sure how to get desired result.
Any help is really appreciated.
Try this:
$top = 50;
$n = 30; // no. of divs
for($i = 0; $i < $n; $i++) {
if($i % 3==0) $top+=50;
echo "<div style=\"top:".$top."px;\">\n</div>";
}
Related
Need help with php code, that can count divs inside parent div and add some code if inner divs have specific count number.
Html is:
<div class="row-fluid str_category">
<div class="span2 jshop_categ"><div>
<div class="span2 jshop_categ"><div>
<div class="span2 jshop_categ"><div>
<div class="span2 jshop_categ"><div>
<div class="span2 jshop_categ"><div>
</div>
So need php with logic something like:
find div with class.str_category
find div with class.jshop_categ
count number of divs.jshop_categ
if number of divs.jshop_categ = 4
- add code "<div class="additionaldiv"><div>"
if number of divs.jshop_categ = 3
- add code "<div class="additionaldiv"><div> <div class="additionaldiv"><div>"
if number of divs.jshop_categ = 3
- add code "<div class="additionaldiv"><div> <div class="additionaldiv"><div> <div class="additionaldiv"><div>"
--
Final result is to make always 5 divs in a row, even if only one div inside parent div.
Thanks.
Why not just make a loop that will always display 5 inner <div> ?
So the code will be:
<div class="row-fluid str_category">
<?php
for($i=0; $i<5; $i++){
echo '<div class="span2 jshop_categ">yeah<div>';
}
?>
</div>
***If this is not what you really want, please elaborate the situation further :)
This code, returned hrefs to content, now I want to extract content form this hrefs and sent it to my view. Name divs which I need to extract:
<div class="c_pad">
<div class="c_label">
<span class="std_header2">Contact:</span>
</div>
<div class="c_name">
<span class="std_text_b">Monkey</span>
</div>
<div class="clear"></div>
</div>
<div class="c_pad">
<div class="c_label">
<span class="std_header2">Phone number:</span>
</div>
<div class="c_phone">
<span class="std_text_b">001111111</span>
</div>
<div class="clear"></div>
</div>
for($i=0; $i <= 1; $i++)
{
$p = new Client();
$d = $p->request('GET', ''.$link.'&std=1&results='. $i);
$n = $d->filter('a[class="o_title"]')->each(function ($node)
{
$pp = new Client();
$dd = $pp->request('GET', $node->attr('href'));
$kk = $dd->filter('div[id="adv_desc"]')->each(function ($tekst) { echo $node->attr('href').'<br>'.$tekst->text();
});
});
}
You want to filter specific tags with attributes.
But you are using $d->filter('a[class="o_title"]').
This filters the tag a with the attribute class="o_title". And that's not part of your content.
You simply need to adjust your node filter to select the correct elements.
Use the jQuery Selectors Syntax: https://api.jquery.com/category/selectors/
Referencing the documentation of Symfony's DomCrawler, which is used by Goutte:
http://symfony.com/doc/current/components/dom_crawler.html#node-filtering
in ZOO Application/templates/uikit/_categories.php have this code:
<?php
// init vars
$i = 0;
$columns = $this->params->get('template.categories_cols', 2);
reset($this->selected_categories);
// render rows
while ((list($key, $category) = each($this->selected_categories))) {
if ($category && !($category->totalItemCount() || $this->params->get('config.show_empty_categories', false))) continue;
if ($i % $columns == 0) echo ($i > 0 ? '</div><hr class="uk-grid-divider"><div class="uk-grid">' : '<div class="uk-grid">');
echo '<div class="uk-width-1-'.$columns.'">'.$this->partial('category', compact('category')).'</div>';
$i++;
}
if (!empty($this->selected_categories)) {
echo '</div>';
}
?>
Render look like this:
<div class="uk-grid">
<div class="uk-width-1-3"></div>
<div class="uk-width-1-3"></div>
<div class="uk-width-1-3"></div>
</div>
<hr class="uk-grid-divider">
<div class="uk-grid">
<div class="uk-width-1-3"></div>
<div class="uk-width-1-3"></div>
<div class="uk-width-1-3"></div>
</div>
And I want this (only one div.uk-grid for all div.uk-width* and without hr.uk-grid.divider):
<div class="uk-grid">
<div class="uk-width-1-3"></div>
<div class="uk-width-1-3"></div>
<div class="uk-width-1-3"></div>
<div class="uk-width-1-3"></div>
<div class="uk-width-1-3"></div>
<div class="uk-width-1-3"></div>
</div>
Can someone help me with this, i am not good in php?
Thanks.
My modified code which not work :(
<?php
$columns = $this->params->get('template.categories_cols', 2); // I dont know why is at end ", 2"
reset($this->selected_categories); // I dont know why is needed reset array
// render rows
while ((list($key, $category) = each($this->selected_categories))) {
if ($category && !($category->totalItemCount() || $this->params->get('config.show_empty_categories', false))) {
echo '<div class="uk-grid">'; // I dont know why is not rendered
}
echo '<div class="uk-width-1-'.$columns.'">'.$this->partial('category', compact('category')).'</div>';
}
if (!empty($this->selected_categories)) {
echo '</div>';
}
?>
You must have set a parameter to add two columns, that's what kicks in the code that adds the separator.
The name of the parameter is template.categories_cols it will be translated though to something in english.
This is a commercially supported extension, you might be able to get some support on their forums
Your best bet would be to set your columns at 1, then use UIKit's CSS to size your divs. This means you'd want your container class to be uk-grid uk-grid-width-1-3, then to remove the uk-width-1-3 from the inner divs. The added benefit here is that you can vary layout depending on your screen size > Grid Component - UIKit.
In your PHP you could remove the columns param all together. Remove the line starting with $columns..., the single spot it's echo'd '.$columns.', and you should be all set.
The PHP was using your "columns" variable to split divs (2 was the default), but if you tailor the container you can avoid the column assignment altogether.
I had 14 li elements with various information in and thought it's be better to wrap it all up into a php loop and use variables and arrays to fill in the gaps.
I've encountered two problems. The first of which is that I'm not returning any elements from the array description or title.
The next problem is in the filename $iFINAL.pdf - it should just be the variable $i with FINAL appended to it.
I wouldn't normally use EOT but in this case it seemed far quicker than escaping all the various quotes.
any help is appreciated, thanks!
<?php
$description = array("Decription 1 here","description 2 here");
$title = array("title 1","titlesfdfs ","sdfsdsd","wqeqe","","");
for($i=1; $i <= 14; $i++){
if($i < 10){
$i = "0".$i;
}
$body = <<<EOT
<h3>Chapter $i - $title[$i]</h3>
<div class=trainingItemListContainer>
<div class="mainDetails">
<p><strong>Introduction:</strong> $description[$i]</p>
</div>
<div class="subDetails">
<div class="viewAndDownload">
<p>Click to view the chapter</p>
</div>
<div class="viewAndDownload">
Click to download the PDF file <img src="../images/disk.png" alt="downloadIcon" border="0"/>
</div>
</div>
</div>
EOT;
echo $body;
}
There are two major issues with your code:
You're setting the value of $i to 01, 02 etc. This will cause the script to produce Undefined Index errors because there's no such index in your array.
You're not enclosing the variables in { }. If you enclose it, the actual variable values will be used. For example: {$i}
Example:
$body = <<<EOT
<h3>Chapter {$i} - {$title[$i]}</h3>
<div class=trainingItemListContainer>
<div class="mainDetails">
<p><strong>Introduction:</strong> {$description[$i]}</p>
</div>
<div class="subDetails">
<div class="viewAndDownload">
<p>Click to view the chapter</p>
</div>
<div class="viewAndDownload">
Click to download the PDF file <img src="../images/disk.png" alt="downloadIcon" border="0"/>
</div>
</div>
</div>
EOT;
Several issues here:
(1) This code is causing problems:
if($i < 10){
$i = "0".$i;
}
WHY? if you did a var_dump($i) (= simple debugging), you'd realize that
$title[1] is different from $title['01']
solution: delete the above code.
(2) an array in PHP will start with index 0, not 1.
echo $description[1];
will output "description 2 here".
solution:
for ($i = 0; $i < 14; $i++) {
$number = str_pad(($i + 1), 2, "00", STR_PAD_LEFT);
...
<h3>Chapter $number - $title[$i]</h3>
see it working here: http://codepad.viper-7.com/489laJ
There is a problem within your code, you are changing the value of $i (reassigning another value with it here):
if($i < 10){
$i = "0".$i;
}
You can alternatively use another variable such as $j
if($i < 10){
$j = "0".$i;
}else{
$j = $i;
}
This might not be your exact problem, but it might help you to improve your code.
Why not try this?
<?php
$description = array("Decription 1 here","description 2 here");
$title = array("title 1","titlesfdfs ","sdfsdsd","wqeqe","","");
for($i=1; $i <= 14; $i++){
if($i < 10){
$i = "0".$i;
}
?>
<h3>Chapter <?php print($i." - ".$title[$i]); ?></h3>
<div class=trainingItemListContainer>
<div class="mainDetails">
<p><strong>Introduction:</strong> <?php print($description[$i]); ?></p>
</div>
<div class="subDetails">
<div class="viewAndDownload">
<p>Click to view the chapter</p>
</div>
<div class="viewAndDownload">
Click to download the PDF file <img src="../images/disk.png" alt="downloadIcon" border="0"/>
</div>
</div>
</div>
If you have PHP code later on, just open the <? tag again!
I have a table in my database with 100 names, dates, id's, and other stuff. I want to be able to get a specific amount of rows echoed in a div, and then another specific amount in the next and so on.
I have been looking at foreach and break here, cause my googling kind of sent me there.. but maybe im looking at the wrong thing:
http://php.net/manual/en/control-structures.break.php
I just don't seem to get things right.
This is a school project and I know this is maybe a little bit vague, sorry about that.
Something like this:
<div id="div1"> echo row 1-7 </div>
<div id="div2"> echo row 7-19 </div>
<div id="div3"> echo row 20-44 </div>
and so on...
Could someone point me in the right direction?
You can do it directly in your query
Use at the end of your query this:
<div id="div1"> echo row 1-7 </div> use "LIMIT 0,6"
<div id="div2"> echo row 7-19 </div> use "LIMIT 7, 19"
<div id="div3"> echo row 20-44 </div> use "LIMIT 20,44"
if you have a numerically indexed array holding your rows you could do something like:
<div id="div1">
<?php for ($i = 1; $i <= 7; $i++) {
print $yourArray[Si]['some_field'];
} ?>
</div>
<div id="div2">
<?php for ($i = 8; $i <= 19; $i++) {
print $yourArray[Si]['some_field'];
} ?>
</div>
...
Something like this (not tested) might work:
$id=1;
$count=0;
$limit=20;
foreach($row as $r){
if ($count==0) echo "<div id='div$id'>";
echo $r;
if ($count++==$limit){
$count=0;
$id++;
echo "</div>\n";
};
}
if ($count!=0) echo "</div>";