Re: [Phplib-users] Classes, MySQL, Images & phplib
Brought to you by:
nhruby,
richardarcher
From: Mike G. <mi...@op...> - 2001-12-31 20:47:27
|
Hey Nathan, nathan r. hruby wrote: >>OK.. My present code looks like this: >>require('config.php3'); >>class Image { >> var $db; >> function Image($ID='$GLOBALS[ID]') { > No quotes in the above, it's not working cause $ID is being set to the > string "$GLOBALS[ID]" and not the actual value of the global $ID (as a > side note, this happen becasue you're using single quotes which casue > literal strings, double quotes would have meant that the string would have > been scanned for variable substituion and it would have been ok, but you > would have paid a small performance penalty for that substitution. This > is where knowing everything about your varibles comes in handy.) I tried a stack of different options on this, but these gave me parse errors: $ID=$GLOBALS[ID] $ID="$GLOBALS[ID]" and these didn't (they gave me identical - but bad results): $ID='$GLOBALS[ID]' $ID=48 As did this actually: require('config.php3'); class Image { var $db; function Image() { $ID=$GLOBALS[ID]; echo "ID $ID"; $this->db = new proDB; $sql="SELECT photo FROM WLPphoto WHERE profileID='$ID'"; $this->db->query($sql); while ($this->db->next_record()) { Header("Content-type: image/jpeg"); print $this->db->Record['photo']; } } } Although this displays properly outside of the class... $ID=$GLOBALS[ID]; echo "ID $ID"; result is: ID 48 >>I just want to clarify though.. in the example you gave ($this->db = >>new nameOfdbClass;), if I was trying to add this to phpSlash 6.2 >>nameOfdbClass; would be DB_Sql (or would it be slashDB? > if all youre tables are in the same databse as the phpslash stuff, then > slashDB, else you'll need to make a new subclass of DB_Sql. Hmm.. That is essentially what I'm doing... Some folks on this list may remember me asking about/talking up a online bibliography 6 months or so ago.. It's mostly working now and sitting here (still in draft mode): http://www.openconcept.ca/WLP/biblio/categories.php3 I'm presently working up the portfolio side (harder to explain), but this is what I need the images for... In anycase, it's all based on the 6.2 code of phpSlash.. >>Both seem to produce the same result for me.. I even tried commenting >>out the header line (Header("Content-type: image/jpeg");) to see if that >>would just echo the raw jpg data.. It didn't.. So something's goofing >>up... > Make sure you're not outputing anything before that header() call. I bet > there's an error creeping in (probably from using the wrong db class) > that's casuing it. For something liek what you're doing I like to add a > construct like this to the top of my code: > if ($debug && $HTTP_GET_VARS[breakme]) { > echo "I'm outputing something to break the headers.<br>\n"; > echo "This will allow me to see what exactly I'm sending.<br>\n"; > echo "Including errors :)<br>\n"; > } This is usefull.. That way it is easy to make/break code.. http://localhost/WLP/profiles/image.php3?ID=48&breakme=yes However, I can't seem to get any output from within the class.. Putting this in the function and commenting out the header doesn't output anything.. echo "this isn't working"; The URL above does, but.. that isn't managing stuff within the code.. > Also, check to make sure (for debug pruposes) error_reporting is set to > E_ALL. And FWIW, I'd do a $this->db->nf() and make sure the returned > valus is 1 and if it isn't sending a "not availible" jpeg to the > browser before entering the while() loop. This ensures that if the script > freaks out and can't find a image in the databse, something is returned to > the user indicating so :) I've got a couple references of phpSlash 6.2 ending Variable.class with: }; /* end of Variable.class */ and not the ?> which would be standard.. I've never seen a php file ended like that before... In anycase, the whole file now looks like this: <?php error_reporting(E_ALL); require('config.php3'); if ($debug && $HTTP_GET_VARS[breakme]) { echo "I'm outputing something to break the headers.<br>\n"; echo "This will allow me to see what exactly I'm sending.<br>\n"; echo "Including errors :)<br>\n"; } class Image { var $db; function Image() { $ID=$GLOBALS[ID]; $this->db = new proDB; echo "this isn't working"; $sql="SELECT photo FROM WLPphoto WHERE profileID='$ID'"; echo $this->db->nf(); $this->db->query($sql); while ($this->db->next_record()) { // Header("Content-type: image/jpeg"); print $this->db->Record['photo']; } } } ?> And results in the following: Warning: Undefined variable: sitename in /usr/local/web/WLP/profiles/config.php3 on line 191 Warning: Use of undefined constant rootdir - assumed 'rootdir' in /usr/local/web/WLP/profiles/Variable.class on line 23 Warning: Use of undefined constant basedir - assumed 'basedir' in /usr/local/web/WLP/profiles/Variable.class on line 24 Warning: Use of undefined constant listvariable - assumed 'listvariable' in /usr/local/web/WLP/profiles/Variable.class on line 33 Warning: Use of undefined constant newvariable - assumed 'newvariable' in /usr/local/web/WLP/profiles/Variable.class on line 34 Warning: Use of undefined constant value - assumed 'value' in /usr/local/web/WLP/profiles/Variable.class on line 55 Warning: Undefined variable: siteowner in /usr/local/web/WLP/profiles/config.php3 on line 192 Warning: Use of undefined constant value - assumed 'value' in /usr/local/web/WLP/profiles/Variable.class on line 55 Warning: Undefined variable: xsitename in /usr/local/web/WLP/profiles/config.php3 on line 193 Warning: Use of undefined constant value - assumed 'value' in /usr/local/web/WLP/profiles/Variable.class on line 55 Warning: Use of undefined constant breakme - assumed 'breakme' in /usr/local/web/WLP/profiles/image.php3 on line 5 Warning: Undefined index: breakme in /usr/local/web/WLP/profiles/image.php3 on line 5 Which shouldn't be affecting things when the errors are turned off.. Those should be pretty innocent.. Mike -- Mike Gifford, OpenConcept Consulting, http://www.openconcept.ca Supporting progressive organizations in online campaigns and tools. Feature: Women's Learning Partnership http://learningpartnership.org Truth is that which confirms what we already believe. Northrop Frye |