how to list all with this code.thanks

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
fnleong
Forum Newbie
Posts: 18
Joined: Wed May 12, 2004 5:49 am

how to list all with this code.thanks

Post 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)';
?>
?>
Last edited by fnleong on Thu May 13, 2004 3:47 am, edited 1 time in total.
fnleong
Forum Newbie
Posts: 18
Joined: Wed May 12, 2004 5:49 am

but i have encode the pic before insert to database

Post 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");
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

click the first link below - and don't double-post again. :evil:
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Post 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.
User avatar
launchcode
Forum Contributor
Posts: 401
Joined: Tue May 11, 2004 7:32 pm
Location: UK
Contact:

Post 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.
Post Reply