Page 1 of 1

<script src=myscript.php> not displaying

Posted: Sat Aug 30, 2008 6:10 am
by pentace
Sorry i dont know quiet how to explain this so i will do my best. Basically i have this code that i can embed via src=myfile.php and it will display all the image files in a var on an html page.

Code: Select all

<?
Header("content-type: application/x-javascript");
 
function returnimages($dirname="/my directory/") {
   $pattern="\.(jpg|jpeg|png|gif|bmp)$";
   $files = array();
   $curimage=0;
   if($handle = opendir($dirname)) {
       while(false !== ($file = readdir($handle))){
               if(eregi($pattern, $file)){
         $filedate=date ("M d, Y H:i:s");
                 echo 'galleryarray[' . $curimage .']=["' . $file . '"];' . "\n";
                 $curimage++;
               }
       }
 
       closedir($handle);
   }
   return($files);
}
 
echo "var galleryarray=new Array();" . "\n";
returnimages();
?>
this works fine but i want to use this code to display the information in a DB it works fine from the direct php file
http://protocol-x.com/dproof/dbs.php

but when i try to use it via src=myfile.php nothing happens

Code: Select all

<?php 
$database="DProofImages"; 
mysql_connect("myserver","mydatabase","mypass");
@mysql_select_db($database) or die( "Unable to select database"); 
$result = mysql_query( "SELECT * FROM user" )
or die("SELECT Error: ".mysql_error()); 
$num_rows = mysql_num_rows($result); 
print "There are $num_rows records.<P>"; 
print "<table width=400 border=1>\n"; 
while ($get_info = mysql_fetch_row($result)){ 
print "<tr>\n"; 
foreach ($get_info as $field) 
print "\t<td><font face=arial size=1/>$field</font></td>\n"; 
print "</tr>\n"; 
} 
print "</table>\n"; 
?>
It has to be used as a src=myfile.php due to certain restrictions. I have tried altering it to load it in as an array as well and still will not work seems to be getting held up due to this part.

Code: Select all

while ($get_info = mysql_fetch_row($result)){ 
print "<tr>\n"; 
foreach ($get_info as $field) 
print "\t<td><font face=arial size=1/>$field</font></td>\n";


any help would be greatly appreciated

Re: <script src=myscript.php> not displaying

Posted: Sat Aug 30, 2008 11:03 am
by greyhoundcode
When you say you are embedding it using src='script.php' do you mean that that is what you are putting in your HTML? If so, I suggest that you save your HTML page with a .php extension and substitute src='script.php' for:

Code: Select all

<?php
include "filepath/script.php";
?>
Also - though I might be wrong about this since I'm not sure what your intention is - you might want to reconsider your header() function, maybe even remove it altogether.