Jump to content

Recommended Posts

I am trying to output this data resutls onto my web page using <div> tags or something instead of just outputting on a blank php page. any ideas ?

Heres the info i want to output

if(!empty($arr_hdd_files)) {
        
        foreach($arr_hdd_files as $k => $v) { 
                <li>$v</li>
        }
        echo '</ul>';
} else {
        echo '<li>None</li></ul>';
}

echo '<p>Files in Database</p><ul>';
if(!empty($arr_db_files)) {
        
        foreach($arr_db_files as $k => $v) { 
                <li>$v</li>
        }
        echo '</ul>';
} else {
        echo '<li>None</li></ul>';
}

echo '<p>Files inserted to DB</p><ul>';
if(!empty($arr_insert_files)) {
        
        foreach($arr_insert_files as $k => $v) { 
                <li>$v</li>
        }
        echo '</ul>';
} else {
        echo '<li>None</li></ul>';
}

Link to comment
https://forums.phpfreaks.com/topic/171587-how-to-display-this-output-in-tags/
Share on other sites

ok so im not having any luck with that.

Heres my page code to see if theres something im just not putting in the right spot.

I also noticed that I had added the incorrect code in the first place :( too much confusion today hehe. So heres what I got and want to display in the <div> the results of each.

 

    <!-- INCLUDE overall_header.html -->
<p class="{S_CONTENT_FLOW_END}<!-- IF S_USER_LOGGED_IN --> rightside<!-- ENDIF -->"><!-- IF S_USER_LOGGED_IN -->{LAST_VISIT_DATE}<!-- ELSE -->{CURRENT_TIME}<!-- ENDIF --></p>
<!-- IF U_MCP --><p>{CURRENT_TIME} <br />[ <a href="{U_MCP}">{L_MCP}</a> ]</p><!-- ELSEIF S_USER_LOGGED_IN --><p>{CURRENT_TIME}</p><!-- ENDIF -->

<html>
<head>
<?php 
$Dir = './images/'; 

mysql_connect('localhost', 'xxx', 'xxx');
mysql_select_db('pets');

$arr_hdd_files = array();
$arr_db_files = array();
$arr_insert_files = array();

//get files in db
$query = "SELECT * FROM image";
$result = mysql_query($query) or die("Could not execute query ".mysql_error());
$row_result = mysql_fetch_assoc($result);
if($row_result) {
        do {
                $arr_db_files[] = $row_result['name'];
        } while($row_result = mysql_fetch_assoc($result));
}           

//check files on disk 
foreach (glob("$Dir/*.{jpg,gif,png}", GLOB_BRACE) as $filename) {
    $pathinfo = pathinfo($filename);
    $name = basename($filename);
    $ext = $pathinfo['extension'];
        $arr_hdd_files[] = $name;
    $size = filesize($filename);
    $thePath=dirname($_SERVER['PHP_SELF']) . substr($filename, 1);

    //check hdd filename against array of db filenames
    if ( !in_array($name,$arr_db_files) ) {
         $query1 = "INSERT INTO image SET name='$name', size='$size', type='$ext', path='$thePath'";
         // or uncomment to use blob
         // $blob = addslashes(file_get_contents($filename));
         // $query = "INSERT INTO images SET name='$name', size='$size', type='$ext', content='$blob'";
         $result1 = mysql_query($query1);
         if($result) {
           $arr_insert_files[] = $name;
         }
                 
    }
        
}
//show results
echo "<h2>Results</h2>\n";
echo '<p>Files on Disk</p><ul>';
if(!empty($arr_hdd_files)) {
        
        foreach($arr_hdd_files as $k => $v) { 
                echo "<li>$v</li>";
        }
        echo '</ul>';
} else {
        echo '<li>None</li></ul>';
}

echo '<p>Files in Database</p><ul>';
if(!empty($arr_db_files)) {
        
        foreach($arr_db_files as $k => $v) { 
                echo "<li>$v</li>";
        }
        echo '</ul>';
} else {
        echo '<li>None</li></ul>';
}

echo '<p>Files inserted to DB</p><ul>';
if(!empty($arr_insert_files)) {
        
        foreach($arr_insert_files as $k => $v) { 
                echo "<li>$v</li>";
        }
        echo '</ul>';
} else {
        echo '<li>None</li></ul>';
}
?>
<div class="panel">
       <div class="inner"><span class="corners-top"><span></span></span>
       
	<h1>Files on Disk</h1>
	echo "<li>".$v."</li>";

       <span class="corners-bottom"><span></span></span></div>
    </div>

<!-- INCLUDE overall_footer.html -->

just wrap what you want to echo in the foreach with the div tags? assuming you want to wrap whats inside the following code block in a div tag

//show results
echo "<h2>Results</h2>\n";
echo '<p>Files on Disk</p><ul>';
if(!empty($arr_hdd_files)) {
        
        foreach($arr_hdd_files as $k => $v) { 
                echo "<li>$v</li>";
        }
        echo '</ul>';
} else {
        echo '<li>None</li></ul>';
}

echo '<p>Files in Database</p><ul>';
if(!empty($arr_db_files)) {
        
        foreach($arr_db_files as $k => $v) { 
                echo "<li>$v</li>";
        }
        echo '</ul>';
} else {
        echo '<li>None</li></ul>';
}

echo '<p>Files inserted to DB</p><ul>';
if(!empty($arr_insert_files)) {
        
        foreach($arr_insert_files as $k => $v) { 
                echo "<li>$v</li>";
        }
        echo '</ul>';
} else {
        echo '<li>None</li></ul>';
}
?>

 

just echo div tags around them...

echo "<div id='something'>";
//show results
echo "<h2>Results</h2>\n";
echo '<p>Files on Disk</p><ul>';
if(!empty($arr_hdd_files)) {
        
        foreach($arr_hdd_files as $k => $v) { 
                echo "<li>$v</li>";
        }
        echo '</ul>';
} else {
        echo '<li>None</li></ul>';
}

echo '<p>Files in Database</p><ul>';
if(!empty($arr_db_files)) {
        
        foreach($arr_db_files as $k => $v) { 
                echo "<li>$v</li>";
        }
        echo '</ul>';
} else {
        echo '<li>None</li></ul>';
}

echo '<p>Files inserted to DB</p><ul>';
if(!empty($arr_insert_files)) {
        
        foreach($arr_insert_files as $k => $v) { 
                echo "<li>$v</li>";
        }
        echo '</ul>';
} else {
        echo '<li>None</li></ul>';
}
echo "</div>";
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.