I have something like this.
<div id="tabs">
<ul>
<li>Tab 1</li>
<li>Tab 2</li>
<li>Tab 3</li>
</ul>
<div id="tabs-1">
<p>Tab 1 content</p>
</div>
<div id="tabs-2">
<p>Tab 2 content</p>
</div>
<div id="tabs-3">
<p>Tab 3 content</p>
</div>
</div>
Instead of the content (Tab 1 content...) in each of the tabs, I need Tables. The structure of the tables in all the 3 tabs is the same, just the content changes with the MySQL query. The query results may have thousands of rows.
How can I go about it? I am very new to Javascript and PHP
Thanks
What you are trying to achieve is basically:
<div id="tabs">
<ul>
<li>Tab 1</li>
<li>Tab 2</li>
<li>Tab 3</li>
</ul>
<div id="tabs-1">
<table> <!-- Rest of the table1 --> </table>
</div>
<div id="tabs-2">
<table> <!-- Rest of the table2 --> </table>
</div>
<div id="tabs-3">
<table> <!-- Rest of the table3 --> </table>
</div>
</div>
you can use the PHP code to create these tables (I assume you have queried the DB and have the data in variable $rows ):
<div id="tabs-1">
<table>
<?php foreach ($rows as $data)
{
echo "<tr>";
echo "<td>". $data['attribute1'] . "</td><td>". $data['attribute2'] . "</td>"";
echo "</tr>";
}
?>
</table>
</div>
Well, the above code is not complete though, you can add table header, decorate it with CSS etc as per your requirement. But using this method, you will have to repeat the code for each table. Since you said you have the same table structure in all the three tabs, you can create the div tags in a loop it self. In that case you will have:
for(loop as many tabs you want) {
echo "<div id='tabs-'".index.">";
/* Query DB and get the data into $rows variable */
foreach ($rows as $data) {
echo "<tr>";
echo "<td>". $data['attribute1'] . "</td><td>". $data['attribute2'] . "</td>"";
echo "</tr>";
}
echo "</div>";
}
Again, you need to decorate as per your requirements. These code snippets should help you get started!
jQuery UI makes it easy to create and access tabs. It has a nice API for doing the things you describe.
Related
i am literally stuck with getting these ul/li elements in one row.
Only first li has class, others are in another ul but without class or id. i tried multiple searches and loops, but can't get it right.
Below results returns too many rows where elements don't fit together.
Can someone help me?
idealy the result from below example would be:
'part', 'desc', 'qty'
'106128-001','LBL, BLNK,THERMAL PRINT','1'
'106128-004','LBL, BLNK THERMAL,RECT 2.40x4','1'
HTML example
<div id='tab1' class="section tab" data-position="auto" style="max-height:none;">
<ul class="links">
<li id="innertab1">106128-001</li>
</ul>
<ul id="combom0" class="tab1 cols2 compare">
<li style="border: none;">
<div>
<ul>
<li><strong>Description: </strong>LBL, BLNK,THERMAL PRINT</li>
<li><strong>Qty: </strong>1</li>
</ul>
</div>
</li>
</ul>
<ul class="links">
<li id="innertab1">106128-004</li>
</ul>
<ul id="combom1" class="tab1 cols2 compare">
<li style="border: none;">
<div>
<ul>
<li><strong>Description: </strong>LBL, BLNK THERMAL,RECT 2.40x4</li>
<li><strong>Qty: </strong>1</li>
</ul>
</div>
</li>
</ul>
My poor attempt with trying to count rows:
$search = $html->find('div[id=tab1]',0);
$i=0;
$alles=array();
foreach ($search->find('* li') as $test){
if(!empty($test->innertext)){
if($i>3){$i=0;}
$i++;
if($i==1){
echo $alles_li['part'] = strip_tags($test->innertext);
}
if($i==2){
// don't need this, bad stripping
strip_tags($test->innertext);
}
if($i==3){
$alles_li['desc'] = strip_tags($test->innertext);
}
if($i==4){
$alles_li['qty'] = strip_tags($test->innertext);
}
}
// if less than 3 elements don't add
if(count($alles_li)==3){
$alles[]=$alles_li;
}
}
I returning my data to build a list group. All is fine but when the data contains <pre> tag it messes my display.
My list group as follows.
if (isset($BS_array)){
//Create a list group to show results
echo '<div class="list-group">';
foreach($BS_array as $result){
?>
<!-- Build list group -->
<div class="list-group-item list-group-item-action" aria-current="true">
<div class="d-flex w-100 justify-content-between">
<!-- Incident number goes here -->
<h5 style="cursor: pointer;" id="<?php echo $result['number']; ?>" onclick="getINCDetails(this.id)" class="mb-1"><?php echo $result['number']; ?></h5>
</div>
<!-- Description goes here -->
<p class="mb-1"><?php echo $result['description']; ?></p>
<small>
<?php
//List BS in INC card
echo $result['state'];
?>
</small>
</div>
<?php
}
echo '</div>';
}
?>
The way when all goes ok should be like this.
But at times, $result['description'], contains the word <pre>, which messes things up.
It will look like this.
How do I fix/circumvent this problem?
If you dont require html tags to actually work on the description just use htmlentities():
<?php echo htmlentities($result['description']); ?>
That will actually show instead of the browser considering it html tag.
I am trying to print random slections from an array. However array contains full html and it causes problems, it does not echo the whole html. It just displays the texts within the HTML. I have tried singles quotes but also did not work.
Here is the the thing what i have done;
$items = Array('<div class="custom-top-tags">
<div class="sm-top-tags-title">Öne Çıkanlar:</div>
<div class="sm-top-tags-keywords">
<ul class="sm-top-tags-keywords-list">
<li>Matkaplar</li>
<li>İş Eldivenleri</li>
<li>Mikser & Karıştırıcı</li>
<li>Silikon</li>
<li>Tangitt</li>
<li>Lokma Takımı</li>
<li>Plastik Boru Makası</li>
<li>El Arabası</li>
<li>Vanalar</li>
<li>Boya</li>
<li>Kompresör</li>
</ul>
</div>
</div>',
'<div class="custom-top-tags">
<div class="sm-top-tags-title">Öne Çıkanlar:</div>
<div class="sm-top-tags-keywords">
<ul class="sm-top-tags-keywords-list">
<li>Matkaplar</li>
<li>İş Eldivenleri</li>
<li>Mikser & Karıştırıcı</li>
<li>Silikon</li>
<li>Tangitt</li>
<li>Lokma Takımı</li>
<li>Plastik Boru Makası</li>
<li>El Arabası</li>
<li>Vanalar</li>
<li>Boya</li>
<li>Kompresör</li>
</ul>
</div>
</div>');
echo $items[array_rand($items)];
And my expectaion is displaying randomly selected HTML code.
Meaning, i need to choose different links randomly from a list and i need to display them in html with codes as seen below.
<div class="custom-top-tags">
<div class="sm-top-tags-title">Öne Çıkanlar:</div>
<div class="sm-top-tags-keywords">
<ul class="sm-top-tags-keywords-list">
<li>Matkaplar</li>
<li>İş Eldivenleri</li>
<li>Mikser & Karıştırıcı</li>
<li>Silikon</li>
<li>Tangitt</li>
<li>Lokma Takımı</li>
<li>Plastik Boru Makası</li>
<li>El Arabası</li>
<li>Vanalar</li>
<li>Boya</li>
<li>Kompresör</li>
</ul>
</div>
</div>
Waiting for the suggestions and helps.
The line breaks in you code won't work...
I would suggest to split the code into a temp variable and then array allocation
And use the proper multi lkne syntax
1st of all for styling purposes, and also to prevent this error
You should use $tempvar and the code I wrote for each array insertion
$items = array();
$tempvar = <<<TEMP
<div class="custom-top-tags">
<div class="sm-top-tags-title">Öne Çıkanlar:</div>
<div class="sm-top-tags-keywords">
<ul class="sm-top-tags-keywords-list"> <li>Matkaplar</li> <li>İş Eldivenleri</li>
<li>Mikser & Karıştırıcı</li>
<li>Silikon</li>
<li>Tangitt</li> <li>Lokma Takımı</li>
<li>Plastik Boru Makası</li>
<li>El Arabası</li> <li>Vanalar</li>
<li>Boya</li> <li>Kompresör</li> </ul> </div> </div>
TEMP;
$items[] = $tempvar;
...
that is one possible solution
echo htmlspecialchars($items[array_rand($items)]);
my code only shows one image from the database. I dont know whats the problem. I tried looping it with allthe divs and ul but nothing it only shows one image. my code is
<div class="fullwidthbanner-container">
<div class="fullwidthbanner">
<?php
$about = slider();
while($about_fetch=mysql_fetch_array($about)){
?>
<ul>
<li data-transition="fade" data-slotamount="7">
<img src="images/<?php echo $about_fetch["slide"];?>" alt="">
<?php
}?>
</li>
</ul>
<!--<div class="tp-bannertimer"></div>-->
</div><!-- end .banner -->
</div><!-- end .bannercontainer -->
for the code-part, try this please:
(i assume, you dont want to have several <ul> elements and only the <li>'s)
<div class="fullwidthbanner-container">
<div class="fullwidthbanner">
<ul>
<?php
$about = slider();
while($about_fetch=mysql_fetch_array($about)){ ?>
<li data-transition="fade" data-slotamount="7">
<img src="images/<?php echo $about_fetch["slide"];?>" alt="">
</li>
<?php } ?>
</ul>
</div><!-- end .fullwidthbanner -->
</div><!-- end .fullwidthbanner-container -->
Well, your HTML isn't valid. You're looping over the start of a <ul> and <li> and not closing either until after the loop.
If that isn't the problem, then we can't help you since there is no debugging information available. Break your problem up into pieces. Is the issue server-side or client-side? Look at your output HTML to be sure. What are the return values of mysql_fetch_array() for each iteration? var_dump() is your friend.
I've spent all afternoon trying to figure this out with no success, I wondered if anyone could help?
I have a dropdown menu on my site which is working perfectly. I've duplicated one of the menu options and after I did this it still worked fine, it had a php / SQL query inside but once duplicate it still did what it should.
What I did then was change the SQL and although the query is correct (checked in myphpadmin) all of my results appear out side of the div tag for some reason, its as if the div tag is closing itself.
Here's my code:
'
<li>Brand<!-- Begin 4 columns Item -->
<div class="dropdown_5columns"> <!-- Begin 4 columns container -->
<div id="top"></div>
<div class="col_4">
<h2 style="width:98%;">Choose from the following Brands:</h2>
</div>
<div class="col_1" style="width:190px;">
<?php
$databrand = mysql_query("SELECT DISTINCT(brand), COUNT(*) as Total from `pt_products` where `brand` <>'' group by `brand` limit 5")
or die(mysql_error());
while($infobrand = mysqlfetch_array( $databrand ))
{
print "<li style='width:190px;'>";
print "<a href='/brand'>".$infobrand['brand']." (".$infobrand['Total'].")</a></li>";
}
print "</div>";
?>
<div id="bottom"></div>
</div><!-- End 4 columns container -->
</li>`
I can't seem to figure this one out. All I did was change the SQL Query.
I've tried deleting the duplicate content and starting again, but get the same outcome.
Any help would really be appreciated.
here's the view source data on of my site:
<li>Brand<!-- Begin 4 columns Item -->
<div class="dropdown_5columns" style="position:absolute;"> <!-- Begin 4 columns container -->
<div id="top"></div>
<div class="col_4">
<h2 style="width:98%;">Choose from the following Brands:</h2>
</div>
<div class="col_1" style="width:190px;">
<li style='width:190px;'><a href='/brand'>Balterio (50)</a></li>
<li style='width:190px;'><a href='/brand'>Dale Hardware (24)</a></li>
<li style='width:190px;'><a href='/brand'>EuroSpec Hardware (2)</a></li>
<li style='width:190px;'><a href='/brand'>Everbuild (35)</a></li>
<li style='width:190px;'><a href='/brand'>Jeld Wen (4)</a></li>
</div>
<div id="bottom"></div>
</div><!-- End 4 columns container -->
</li>
You can't tell from below but the first <li style='width:190px;'> and the </div> after the li list are higlighted in red (error) and also the last </li>
Thanks in advance for your help.
You're using <li>, which should be inside a <ul> or <ol>, which you can then put inside a <div> if you need. Alternatively, you can change the <li> to something else, such as another <div>.
Your problem is like when you put a <p> directly inside a table without nesting in <tr><td>.