[PHP] Full source

2002-02-08 Thread phantom

?
header(Cache-Control: public);
header(Cache-Control: max-age= . $this-allowcache_expire * 60);

$Link = mysql_connect(mysite.com, db_user, db_password)
 or die (SL1-.mysql_errno().: .mysql_error());
mysql_select_db (db_name, $Link)
   or die (SL2-.mysql_errno().: .mysql_error());

/* update Counter Table */
$UpdateCounter = UPDATE Counter SET Ct=Ct+1 WHERE WHERE Img = '${Img}';
mysql_query($UpdateCounter, $Link);

/* get Img data */
$Query = SELECT ImgType, ImgData FROM Photos WHERE Img = '${Img}';
$Results = mysql_query($Query, $Link)
 or die (SL3-.mysql_errno().: .mysql_error());
$Num_rows = mysql_num_rows($Results);

if ($Num_rows==1) {
$ImgType = mysql_result($Results,0,ImgType);
$ImgData = mysql_result($Results,0,ThmData);
header(Content-Type:  . $ImgType);
echo $ImgData;
}
?







Jason Wong wrote:

 On Friday 08 February 2002 16:26, phantom wrote:
  I have this really cool script that grabs image data stored in a mysql
  bin field and echo's the data into an image file.
 
  01: /* QUERY DB AND LOAD IMAGE DATA */
  02: /* must get values for ImgType and ThmData */
  03: $Results = mysql_query($Query, $Link)
  04: or die (SL3-.mysql_errno().: .mysql_error());
  05: $Num_rows = mysql_num_rows($Results);
  06: if ($Num_rows==1) { // show image;
  07: $ImgType = mysql_result($Results,0,ImgType);
  08: $ThmData = mysql_result($Results,0,ThmData);
  09: header(Content-Type:  . $ImgType); //$ImgType shoud be
  image/jpeg;
  10: echo $ThmData;
  11:}
 
  However, I have a simple mysql database counter that counts how many
  times this image is loaded.  $UpdateQuery = UPDATE Counter SET Ct=Ct=1
  WHERE Img = '${Img}';

 Where is this query being used? You're not inadvertently using it twice?
 Could you post the complete code?

  However everytime I run this script the counter increments by 2 (not
  1).  G.
 
  After dicing this script up, the line that is suspect is Line 09:
 
  If I comment out this line (Line 09), the counter increments properly
  (by 1).
 
  If I comment out Line 10 and leave Line 09 in, the counter increases by
  2 and the image fails to display.  Also Line 09 echos the URL of the
  image.  Could this URL be resubmitting the script again, thus
  incrementing the counter an extra count???

 I don't see how it can resubmit your script again, it's not using Location:.

 --
 Jason Wong - Gremlins Associates - www.gremlins.com.hk

 /*
 The future isn't what it used to be.  (It never was.)
 */


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Full source

2002-02-08 Thread Jason Wong

On Friday 08 February 2002 17:03, phantom wrote:

 ?
 header(Cache-Control: public);
 header(Cache-Control: max-age= . $this-allowcache_expire * 60);

 $Link = mysql_connect(mysite.com, db_user, db_password)
  or die (SL1-.mysql_errno().: .mysql_error());
 mysql_select_db (db_name, $Link)
or die (SL2-.mysql_errno().: .mysql_error());

 /* update Counter Table */
 $UpdateCounter = UPDATE Counter SET Ct=Ct+1 WHERE WHERE Img = '${Img}';

Why have you got WHERE WHERE? Is it a typo?


 mysql_query($UpdateCounter, $Link);

 /* get Img data */
 $Query = SELECT ImgType, ImgData FROM Photos WHERE Img = '${Img}';
 $Results = mysql_query($Query, $Link)
  or die (SL3-.mysql_errno().: .mysql_error());
 $Num_rows = mysql_num_rows($Results);

 if ($Num_rows==1) {
 $ImgType = mysql_result($Results,0,ImgType);
 $ImgData = mysql_result($Results,0,ThmData);
 header(Content-Type:  . $ImgType);
 echo $ImgData;
 }
 ?


Is this copy  paste direct from your source-code? If so, you have a problem 
with your query:

   $Query = SELECT ImgType, ImgData FROM Photos WHERE Img = '${Img}';

You're selecting ImgType  ImgData. But here

$ImgData = mysql_result($Results,0,ThmData);

you're trying to get ThmData from the results.


But that still doesn't explain why your counter is increasing by 2 :(



-- 
Jason Wong - Gremlins Associates - www.gremlins.com.hk

/*
If the King's English was good enough for Jesus, it's good enough for me!
-- Ma Ferguson, Governor of Texas (circa 1920)
*/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php