Page 1 of 1

how to list all with this code.thanks

Posted: Wed May 12, 2004 5:49 am
by fnleong

Code: Select all

<?php
<php?
  @ $db = mysql_pconnect('localhost','root');

  if (!$db)
  {
     echo 'Error: no record to database.  Please try again later.';
     exit;
  }

  mysql_select_db('mobile');
  $query = "SELECT * FROM images";
  $result = mysql_query($query);
  $num_results = mysql_num_rows($result);
  

  if(!$num_results)
	{
	echo 'No pics can be found!';
	exit();
	}

        printf("<TABLE BORDER WIDTH="100%%">\n");
	printf("<TR>
   
         <TD><B>User Name</B></TD>
         <TD><B>Password</B></TD>
	
	     
        </TR>\n");

while (($row = mysql_fetch_array($result))) 
{ 
$imgid = $row["imgid"];
$encodeddata = $row["sixfourdata"]; 
printf("<TR>
         <TD>%s</TD>
         <TD>%s</TD>
</TR>\n",
	$row->imgid, $row->$encodeddata);}
	printf("</TABLE>\n");
	mysql_free_result($result);

} 

echo 'base64_decode($encodeddata)';
?>
?>

but i have encode the pic before insert to database

Posted: Wed May 12, 2004 5:51 am
by fnleong
<?php
$dbcnx = @mysql_connect("localhost", "root", "");

if (!$dbcnx)
{
echo( "connection to database server failed!" );
exit();
}

if (! @mysql_select_db("mobile") )
{
echo( "Image Database Not Available!" );
exit();
}

$path = "./";

$dir_handle = @opendir($path) or die("Unable to open directory $path");

while ($file = readdir($dir_handle))
{
$filetyp = substr($file, -3);
if ($filetyp == 'gif' OR $filetyp == 'jpg')
{
$handle = fopen($file,'r');
$file_content = fread($handle,filesize($file));
fclose($handle);
$encoded = chunk_split(base64_encode($file_content));
$sql = "INSERT INTO images SET sixfourdata='$encoded'";
@mysql_query($sql);
}
}

closedir($dir_handle);
echo("complete");

Posted: Wed May 12, 2004 6:30 am
by patrikG
click the first link below - and don't double-post again. :evil:

Posted: Wed May 12, 2004 8:22 am
by Bill H
And, given that you made even one post, why?

To show us that you can write code?
So can we. Big deal.

Posted: Wed May 12, 2004 8:29 am
by launchcode
I think he's asking for help - the subject of his messages seems to imply that anyway. Trying to chunk encode an image into a SQL table for some reason.