Hi,
when I click the folder that is in the first folder it just can't recognize what's in it.
What is it I'm doing wrong ?
<?php
$fil = new SplFileObject(__FILE__);
$dato = new DateTime();
$dato->setTimezone(new DateTimeZone('Europe/Copenhagen'));
$dato->setTimestamp($fil->getMTime()); // getMTime sidst modificeret
if($_GET) {
$path = $fil->getPath();
$path = $path . "/" . $_GET['mappe'];
} else {
$path = $fil->getPath();
}
$mappeinterator = new FilesystemIterator($path);
foreach ($mappeinterator as $fileinfo) {
$type = $fileinfo->isDir();
if(!$type){
echo '<div style="width: 648px; margin:0 auto;">';
echo '<div id="name">';
echo $fileinfo->getFilename();
echo '</div>';
echo '<div id="kb">';
echo $fileinfo->getSize() . ' kb' . '<br>';
echo '</div>';
echo '<div id="mo">';
echo 'Modified on';
echo '</div>';
echo '<div id="m">';
$modificeret = $dato->format('d-m-Y H:i:s');
echo $modificeret . '<br>';
echo '</div>';
echo '</div><br><br>';
} else {
echo '<div style="width: 648px; margin:0 auto;">';
echo '<div id="name">';
// ------------------------------------------------------
$m = $fileinfo->getFilename();
echo '<a href=op02.php?mappe=' . $m . '>';
echo $m;
echo '</a>';
echo '</div>';
// ------------------------------------------------------
echo '<div id="kb">';
echo $fileinfo->getSize() . ' kb' . '<br>';
echo '</div>';
echo '<div id="mo">';
echo 'Modified on';
echo '</div>';
echo '<div id="m">';
$modificeret = $dato->format('d-m-Y H:i:s');
echo $modificeret . '<br>';
echo '</div>';
echo '</div><br><br>';
}
}
?>
I have more folder in each folder just for the test.
But as you can see it does go further
You are using the directory of __FILE__ as base. You have to provide the whole path to your sub-subdir that means including MAPPE. Your directory is not C:\xampp\htdocs\AW\Filsystem\mappe3 but C:\xampp\htdocs\AW\Filsystem\MAPPE\mappe3. Therefore you should include the whole relative path in your link:
$m = substr($path."\\".$fileinfo->getFilename(), strlen(dirname(__FILE__))+1);
echo '<a href=op02.php?mappe=' . $m . '>';
But beware: using request vars for building a path could be a security problem.
Related
I had retrieve some result from database and want to display the result separately.
If the pb_title is same as temp_title then put it togather in a red color div
else is pb_title is not same as temp_title then put it in grey color div
Here my tried code :
$select_brand = "SELECT * FROM tblProduct_Brand WHERE pb_display='display'";
$result = mysqli_query ($mydatabase, $select_brand);
if($result)
{
while($row = mysqli_fetch_array($result))
{
$pb_feature_image = substr(($row['pb_feature_image']),3);
$pb_logo = substr(($row['pb_logo']),3);
$temp_result;
if($temp_result == $row["pb_title"])
{
//if product brand title is same, put it in same area
echo '<div style="padding:20px; background-color:red;">';
echo '<div style="display:inline-block;width:340px;height:250px;vertical-align:top;">';
echo '<img src="'.$pb_feature_image.'" width="100%" height="100%"/>';
echo '</div>';
echo '<div style="display:inline-block;width:330px;height:250px;padding-left:10px;">';
echo '<div style="height:40px;width:80px;float:right">';
echo '<img src="'.$pb_logo.'" width="100%"/>';
echo '</div>';
echo '<div style="clear:both"></div>';
echo '<a class="product-content">'.$row["pb_content"].'</a>';
echo '</div>';
echo '</div>';
$temp_result = $row["pb_title"];
}
else
{
//if not same, put in another area
echo '<div style="padding:20px; background-color:grey;">';
echo '<div style="display:inline-block;width:340px;height:250px;vertical-align:top;">';
echo '<img src="'.$pb_feature_image.'" width="100%" height="100%"/>';
echo '</div>';
echo '<div style="display:inline-block;width:330px;height:250px;padding-left:10px;">';
echo '<div style="height:40px;width:80px;float:right">';
echo '<img src="'.$pb_logo.'" width="100%"/>';
echo '</div>';
echo '<div style="clear:both"></div>';
echo '<a class="product-content">'.$row["pb_content"].'</a>';
echo '</div>';
echo '</div>';
}
}
Any mistake about the code please correct me.
Thanks.
The following code assumes that you did something like this with the data you fetched from the sql query:
$data = array();
while($row = mysqli_fetch_assoc($result)) {
$data[] = $row;
}
Which returns an array like this:
Array (
[0] => Array(
'pb_title' => '',
'pb_content' => '',
//...etc
),
//.....etc
)
Now assuming that I understand your question correctly, you'd want to do something like this:
$i = array();
$key = 'A';
foreach ($data as $item) {
if ($item['pb_title'] == $key) {
$i['red'][] = $item;
} else {
$i['grey'][] = $item;
}
}
Which gives you an array of red (Matching) and grey (Not Matching).
Which you can loop through and generate your div's appropriately.
Something like this (pseudo code)
echo '<div style="padding:20px; background-color:red;">';
foreach($i['red'] as $row) {
echo '<div style="display:inline-block;width:340px;height:250px;vertical-align:top;">';
echo '<img src="'.$pb_feature_image.'" width="100%" height="100%"/>';
echo '</div>';
echo '<div style="display:inline-block;width:330px;height:250px;padding-left:10px;">';
echo '<div style="height:40px;width:80px;float:right">';
echo '<img src="'.$logo.'" width="100%"/>';
echo '</div>';
echo '<div style="clear:both"></div>';
echo '<a class="product-content">'.$row["pb_content"].'</a>';
echo '</div>';
}
echo '</div>';
Example
$temp_result;
if($temp_result == $row["pb_title"])
Before checking the condition you should have assigned some value to $temp_result , but you haven't and you are comparing it anyway.
EDIT :
What I understand is that initially you have not set any value of $temp_result and it is always coming in your Else Block where you do'not assign $temp_result = $row["pb_title"]; , So that it shoudl store the previous value , you only did it in the If Block , you need to place the same code in your else block too..
Simple Edit this section in your code
else
{
//if not same, put in another area
echo '<div style="padding:20px; background-color:grey;">';
echo '<div style="display:inline-block;width:340px;height:250px;vertical-align:top;">';
echo '<img src="'.$pb_feature_image.'" width="100%" height="100%"/>';
echo '</div>';
echo '<div style="display:inline-block;width:330px;height:250px;padding-left:10px;">';
echo '<div style="height:40px;width:80px;float:right">';
echo '<img src="'.$pb_logo.'" width="100%"/>';
echo '</div>';
echo '<div style="clear:both"></div>';
echo '<a class="product-content">'.$row["pb_content"].'</a>';
echo '</div>';
echo '</div>';
$temp_result = $row["pb_title"]; // added this to save previous result
}
Make sure that programing should be effective for that you need to have following ideas:
1) Here you no need to use if($result) because when the sql results are true then only it will allow inside the condition
2) While programing try to avoid more if else condition for making efficient.
<?php
$select_brand = "SELECT * FROM tblProduct_Brand WHERE pb_display='display'";
$result = mysqli_query ($mydatabase, $select_brand);
while($row = mysqli_fetch_array($result))
{
$pb_feature_image = substr(($row['pb_feature_image']),3);
$pb_logo = substr(($row['pb_logo']),3);
$temp_result;
if($temp_result == $row["pb_title"]) { $style = 'style="padding:20px; background-color:red;"'; }
else { $style = ' style="padding:20px; background-color:grey;"'; }
echo '<div '.$style.' >';
echo '<div style="display:inline-block;width:340px;height:250px;vertical-align:top;">';
echo '<img src="'.$pb_feature_image.'" width="100%" height="100%"/>';
echo '</div>';
echo '<div style="display:inline-block;width:330px;height:250px;padding-left:10px;">';
echo '<div style="height:40px;width:80px;float:right">';
echo '<img src="'.$pb_logo.'" width="100%"/>';
echo '</div>';
echo '<div style="clear:both"></div>';
echo '<a class="product-content">'.$row["pb_content"].'</a>';
echo '</div>';
echo '</div>';
$temp_result = $row["pb_title"];
}
?>
I have this page that looks a little like this.
<div class="ecigcontainer">
<div class="backbutt"><?php include("php/back.php"); ?></div>
<div class="ecig"><?php include("php/ecig.php"); ?></div>
<div class="forwardbutt"><?php include("php/forward.php"); ?></div>
</div>
A back button that works like this.
<?php
if (isset($_GET["ecig"])) {
$back = $_GET["ecig"] - 1;
echo "<a href=\"?ecig=" . $back . "\">";
echo "<img src=\"images/ecigs/" . $back . ".png\" height=\"300px\" /></a>";
} else {
$back = $_GET["ecig"] - 1;
echo "<a href=\"?ecig=" . $back . "\">";
echo "<img src=\"images/ecigs/" . $back . ".png\" height=\"300px\" /></a>";
}?>
The forward button pretty much has the same code, and the display looks like this.
<div class="ecigpic">
<img src="images/ecigs/<?php include("php/ecigcounter.php"); ?>.png" height="400px" />
</div>
<div class="ecigdesc">
<?php
if (isset($_GET["ecig"])) {
include("ecigs/" . $_GET["ecig"] . ".php");
echo "<h3>" . $ecigname . "</h3>";
echo "<p>" . $ecigdesc . "</p>";
} else {
$_GET["ecig"] = 1;
include("ecigs/" . $_GET["ecig"] . ".php");
echo "<h3>" . $ecigname . "</h3>";
echo "<p>" . $ecigdesc . "</p>";
}?>
</div>
With the "ecigcounter" that does this.
<?php
if (isset($_GET["ecig"])) {
echo $_GET["ecig"];
} else {
$_GET["ecig"] = 1;
echo $_GET["ecig"];
}?>
But the whole reason for this question is, how to I make it so it only displays numbers 1-40? Kind of lost and can't really seem to figure it out, and put it where it needs to go.
All the it needed was
<?php
if (isset($_GET["ecig"])) {
if ($_GET["ecig"] == 1){
$back = 40;
echo "<a href=\"?ecig=" . $back . "\">";
echo "<img src=\"images/ecigs/" . $back . ".png\" height=\"300px\" /></a>";
} else {
$back = $_GET["ecig"] - 1;
echo "<a href=\"?ecig=" . $back . "\">";
echo "<img src=\"images/ecigs/" . $back . ".png\" height=\"300px\" /></a>";
}
} else {
$back = $_GET["ecig"] - 1;
echo "<a href=\"?ecig=" . $back . "\">";
echo "<img src=\"images/ecigs/" . $back . ".png\" height=\"300px\" /></a>";
}?>
This little script made the world.
if ($_GET["ecig"] == 1){
$back = 40;
echo "<a href=\"?ecig=" . $back . "\">";
echo "<img src=\"images/ecigs/" . $back . ".png\" height=\"300px\" /></a>";
below I have values and below that I have a while loop with multiple values that are sorted by $top_list_friends['workouts'], with the highest number at top.
How can a merge the below values into one list?
echo "<div class='user'>";
echo "<span class='number'>" . $my_rank . "</span>";
echo "<span class='name'>" . $personal['name'] . "</span>";
echo "<span class='workouts'>" . $personal['workouts'] . "</span>";
echo "</div>";
$i = 0;
while ($top_list_friends = mysql_fetch_array($query_top_list_friends)) {
$i++;
echo "<div class='user'>";
echo "<span class='number'>" . $i . "</span>";
echo "<span class='name'>" . $top_list_friends['name'] . "</span>";
echo "<span class='workouts'>" . $top_list_friends['workouts'] . "</span>";
echo "</div>";
}
Didn't understand question very well, but I would do it in this way:
$name = $personal['name'];
$workouts = $personal['workouts'];
$html = <<<html
<div class='user'>
<span class='number'>$my_rank</span>
<span class='name'>$name</span>
<span class='workouts'>$workouts</span>
</div>
html;
$i=0;
while ($top_list_friends = mysql_fetch_array($query_top_list_friends)) {
$i++;
$topName = top_list_friends['name'];
$topW = $top_list_friends['workouts']
$html += <<<html
<div class='user'>
<span class='number'>$i</span>
<span class='name'>$topName</span>
<span class='workouts'>$topW</span>
</div>
html;
}
echo $html;
At the beginning:
$inserted=0;
into the loop:
if(!$inserted && $personal['workouts']> $top_list_friends['workouts'])}
$inserted=0;
//first div echoes
}
at the end
if(!$inserted){
//the same echos
}
I am having problem in resizing pictures. to show the uploaded images i have saved their path in database table and code to show images is:
$result = mysql_query("SELECT * FROM photos");
while($row = mysql_fetch_array($result))
{
$name = 'name';
echo '<div id="imagelist">';
echo '<p ><img src="timthumb.php?src="' .$row['location']. '"&w=100&h=80"/></p>';
echo '</div>';
echo '<div id="imagelist">';
echo '<p>' .$row['id']. '</p>';
echo " ";
echo '<p><b>Location:</b>' .$row['location']. '</p>';
echo '<p><b>File Name:</b>' .$row['name']. '</p>';
echo '<p><b>ID:</b>' .$row['au_id']. '</p>';
echo '<p><b>Position:</b>' .$row['position']. '</p>';
echo '<p><b>Contace info:</b>' .$row['contact']. '</p>';
echo '</div>';
}
I am using timthumb and .$row['location']. has values like "photos/image.png". Page is unable to show the pictures, am I usning timthumb correctly?
echo '<p ><img src="timthumb.php?src="' .$row['location']. '"&w=100&h=80"/></p>';
Remove " " from URL:
echo '<p ><img src="timthumb.php?src=' .$row['location']. '&w=100&h=80"/></p>';
I have this code to pull data from the database and insert the data into one of 4 columns,
I have spent a whole day searching and just cant seem to find out how to do it..
Ideally, I want to select all from database and then where the fetch array has a column id of 1 - echo that then the sama for the next column etc..
<?php
echo '<div class="column grid_3 clearfix" id="column0" >';
echo ' ';
$user_sites_0=mysqli_query($connection, "SELECT * FROM user_sites WHERE column_id='0' ORDER BY sort_no");
if(!$user_sites_0) {
echo 'No sites added, please <a class="addsite" href="#">add one now</a>';
}
else {
while($user_site_0=mysqli_fetch_array($user_sites_0))
{
$id = stripslashes($user_site_0['id']);
$site_name = stripslashes($user_site_0['site_name']);
$site_address = stripslashes($user_site_0['site_address']);
$site_desc = stripslashes($user_site_0['site_desc']);
$site_category = stripslashes($user_site_0['site_category']);
$getImage = 'http://immediatenet.com/t/s?Size=1024x768&URL='.$site_address;
echo '<div class="dragbox" id="item'.$id.'">';
echo '<h2 class="h2handle">'.$site_name.' <span class="close"><img src="assets/img/closepanel.png"></span></h2>';
echo '<div class="dragbox-content" ';
if($user_site_0['collapsed']==1)
echo 'style="display:none;" ';
echo '>';
echo '<p><a class="sitelink" href="' . $site_address . '" title="'.$site_name.'"><img src="'.$getImage.'" alt="'.$site_name.'" title="'.$site_name.'"/></a>';
echo '<p>' . $site_category . '</p>';
echo '<p>' . $site_address . '</p>';
echo '<p>' . $site_desc . '</p>';
echo' </div>
</div>';
}
}
echo '</div>';
?>
<?php
echo '<div class="column grid_3 clearfix" id="column1" >';
echo ' ';
$user_sites_1=mysqli_query($connection, "SELECT * FROM user_sites WHERE column_id='1' ORDER BY sort_no");
if(!$user_sites_1) {
echo '';
}
else {
while($user_site_1=mysqli_fetch_array($user_sites_1))
{
$id = stripslashes($user_site_1['id']);
$site_name = stripslashes($user_site_1['site_name']);
$site_address = stripslashes($user_site_1['site_address']);
$site_desc = stripslashes($user_site_1['site_desc']);
$site_category = stripslashes($user_site_1['site_category']);
$getImage = 'http://immediatenet.com/t/s?Size=1024x768&URL='.$site_address;
echo '<div class="dragbox" id="item'.$id.'">';
echo '<h2 class="h2handle">'.$site_name.' <span class="close"><img src="assets/img/closepanel.png"></span></h2>';
echo '<div class="dragbox-content" ';
if($user_site_1['collapsed']==1)
echo 'style="display:none;" ';
echo '>';
echo '<p><a class="sitelink" href="' . $site_address . '" title="'.$site_name.'"><img src="'.$getImage.'" alt="'.$site_name.'" title="'.$site_name.'"/></a>';
echo '<p>' . $site_category . '</p>';
echo '<p>' . $site_address . '</p>';
echo '<p>' . $site_desc . '</p>';
echo' </div>
</div>';
}
}
echo '</div>';
?>
<?php
echo '<div class="column grid_3 clearfix" id="column2">';
echo ' ';
$user_sites_2=mysqli_query($connection, "SELECT * FROM user_sites WHERE column_id='2' ORDER BY sort_no");
if(!$user_sites_2) {
echo '';
}
else {
while($user_site_2=mysqli_fetch_array($user_sites_2))
{
$id = stripslashes($user_site_2['id']);
$site_name = stripslashes($user_site_2['site_name']);
$site_address = stripslashes($user_site_2['site_address']);
$site_desc = stripslashes($user_site_2['site_desc']);
$site_category = stripslashes($user_site_2['site_category']);
$getImage = 'http://immediatenet.com/t/s?Size=1024x768&URL='.$site_address;
echo '<div class="dragbox" id="item'.$id.'">';
echo '<h2 class="h2handle">'.$site_name.' <span class="close"><img src="assets/img/closepanel.png"></span></h2>';
echo '<div class="dragbox-content" ';
if($user_site_2['collapsed']==1)
echo 'style="display:none;" ';
echo '>';
echo '<p><a class="sitelink" href="' . $site_address . '" title="'.$site_name.'"><img src="'.$getImage.'" alt="'.$site_name.'" title="'.$site_name.'"/></a>';
echo '<p>' . $site_category . '</p>';
echo '<p>' . $site_address . '</p>';
echo '<p>' . $site_desc . '</p>';
echo' </div>
</div>';
}
}
echo '</div>';
?>
<?php
echo '<div class="column grid_3 clearfix" id="column3">';
echo ' ';
$user_sites_3=mysqli_query($connection, "SELECT * FROM user_sites WHERE column_id='3' ORDER BY sort_no");
while($user_site_3=mysqli_fetch_array($user_sites_3))
{
$id = stripslashes($user_site_3['id']);
$site_name = stripslashes($user_site_3['site_name']);
$site_address = stripslashes($user_site_3['site_address']);
$site_desc = stripslashes($user_site_3['site_desc']);
$site_category = stripslashes($user_site_3['site_category']);
$getImage = 'http://immediatenet.com/t/s?Size=1024x768&URL='.$site_address;
echo '<div class="dragbox" id="item'.$id.'">';
echo '<h2 class="h2handle">'.$site_name.' <span class="close"><img src="assets/img/closepanel.png"></span></h2>';
echo '<div class="dragbox-content" ';
if($user_site_3['collapsed']==1)
echo 'style="display:none;" ';
echo '>';
echo '<p><a class="sitelink" href="' . $site_address . '" title="'.$site_name.'"><img src="'.$getImage.'" alt="'.$site_name.'" title="'.$site_name.'"/></a>';
echo '<p>' . $site_category . '</p>';
echo '<p>' . $site_address . '</p>';
echo '<p>' . $site_desc . '</p>';
echo' </div>
</div>';
}
echo '</div>';
?>
The code looks a right state.. Could I do it better?
Use for and change the code, some code :
<?php
for ($i=0; $i<4; $i++)
{
echo '<div class="column grid_3 clearfix" id="column'.$i.'" >';
echo ' ';
$user_sites=mysqli_query($connection, "SELECT * FROM user_sites WHERE column_id='".$i."' ORDER BY sort_no");
if(!$user_sites) {
echo 'No sites added, please <a class="addsite" href="#">add one now</a>';
}
else
{
while($user_site=mysqli_fetch_array($user_sites))
{
... // Do it yourself
maybe
function get_site($column_id){
$str = "";
$user_sites = mysqli_query($connection, "SELECT * FROM user_sites WHERE column_id='".$column_id."' ORDER BY sort_no");
if(!$user_sites_0) {
echo 'No sites added, please <a class="addsite" href="#">add one now</a>';
}
else {
while($user_site_0=mysqli_fetch_array($user_sites_0))
{
$id = stripslashes($user_site_0['id']);
$site_name = stripslashes($user_site_0['site_name']);
$site_address = stripslashes($user_site_0['site_address']);
$site_desc = stripslashes($user_site_0['site_desc']);
$site_category = stripslashes($user_site_0['site_category']);
$getImage = 'http://immediatenet.com/t/s?Size=1024x768&URL='.$site_address;
$str.= '<div class="dragbox" id="item'.$id.'">';
$str.= '<h2 class="h2handle">'.$site_name.' <span class="close"><img src="assets/img/closepanel.png"></span></h2>';
$str.= '<div class="dragbox-content" ';
if($user_site_0['collapsed']==1)
echo 'style="display:none;" ';
$str.= '>';
$str.= '<p><a class="sitelink" href="' . $site_address . '" title="'.$site_name.'"><img src="'.$getImage.'" alt="'.$site_name.'" title="'.$site_name.'"/></a>';
$str.= '<p>' . $site_category . '</p>';
$str.= '<p>' . $site_address . '</p>';
$str.= '<p>' . $site_desc . '</p>';
$str.=' </div>
</div>';
}
}
$str.='</div>';
return $str;}
echo '<div class="column grid_3 clearfix" id="column0">';
echo ' ';
echo oget_site(0);
echo '<div class="column grid_3 clearfix" id="column1">';
echo ' ';
echo oget_site(1);
//....