Okay guys this is going to be one long question so please bear with me.
I want to create an accordion with contents in it:
How I want the image to look like
I have a web application, where I upload various types(blog, homepage) of images every week. The first week is round 1 and the image can be labelled something like 1.x.x where 1 is the number corresponding to the week. Likewise for 2.x.x, 3.x.x etc.
I insert these images to a server using php and log the entry into a database, with information like project_name, file_name, url, version etc.
What I want to do is, automatically generate multiple accordion tabs one below the other. First tab should be the round corresponding to the latest week of uploading. Below that the week before and like wise till it reaches round 1(See images attached).
Now I am able to pull data and display files from ALL the rounds in a single round. What I want to do is separate rounds, automatically based on version number.=>> 1.x.x files in Round 1, 2.x.x in round 2 etc
Following is the code that I have written. The commented part is what I have been follow and and do. I am a total new comer to PHP and would appreciate it if anyone could help me with this. Thanks!
$project_name_download_form = $_GET['project_name'];
$file_name_download_form = $_GET['file_name'];
$version_download_form = $_GET['version'];
$download_data = "SELECT *
FROM projects, files
WHERE project_id = projects.id
AND project_name = '$project_name_download_form'
AND file_name = '$file_name_download_form'
AND version = '$version_download_form'";
mysqli_select_db($conn, $GLOBALS['database']);
$return_data = mysqli_query($conn, $download_data);
if (!$return_data) {
die('Could not get what you wanted: ' . mysqli_error($conn));
}
while ($row = mysqli_fetch_array($return_data)) {
$url = $row['url'];
$project_folder = $row['project_folder'];
//$id = 18;
$file_name = $row['file_name'];
$version = $row['version'];
$details = $row['details'];
$file = $row['file'];
$new = basename($row['file']); // GET FILE NAME ONLY, GET RID OF PATH.
// $design->url = $row[file_name]
// $design->version = $row[version]
// $designs.push ($design)
}
mysqli_free_result($return_data);
// $lastRound = 0;
// for each $design in $designs
// {
// $round = $design.version.split('.')[0];
// if $round <> $lastRound {
?>
<div class="col-sm-2" id = "accordianSet">
<div class="panel-group" id="accordion">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion" href="#collapseOne"><span>
</span>Explore</a>
</h4>
</div>
<div id="collapseOne" class="panel-collapse collapse">
<div class="panel-body">
<?php
}
?>
<?php
// <HTML FOR LINK >
}
echo "<table class = 'table'>";
echo "<tr>";
echo " <th>File Name</th>
<th>File Link</th>";
echo "</tr>";
What you want to do is pull the results for each week and loop through but each time you loop you want to print variables in html like follows:
<?php
$i=0
while ($row = mysqli_fetch_array($return_data)) {
$url = $row['url'];
$project_folder = $row['project_folder'];
//$id = 18;
$file_name = $row['file_name'];
$version = $row['version'];
$details = $row['details'];
$file = $row['file'];
$new = basename($row['file']);
$i++
//1st Round
echo' <table>
<caption> Round $i</caption>
<tr>
<th>File Name</th>
<td>$file_name</td>
</tr>
<tr>....
</tr>
</table>';
}//while loop close tag
Note that you can format the data anyway you want but you have to spit out the html as you loop through the mysql results. Hope this helps.