php-general Digest 7 Mar 2002 10:17:11 -0000 Issue 1212
Topics (messages 87544 through 87595):
Re: data from service into array
87544 by: Jim Winstead
87549 by: Craig Westerman
87550 by: Jim Winstead
Re: Perl and PHP
87545 by: Steve Cayford
Stopping PHP from sending any headers
87546 by: Nico Vrouwe
Looking for a combo of include() and eval() ????
87547 by: Philip Hallstrom
87553 by: Philip Hallstrom
87554 by: Philip Hallstrom
Session Array Problems - Please Help
87548 by: Jordan
Re: php-general Digest 31 Jan 2001 00:15:17 -0000 Issue 483
87551 by: wesley
Re: preload dynamic image problems
87552 by: Tom Rogers
wordwrapping by width
87555 by: Michael P. Carel
Question on subscription
87556 by: Zenith
Binary Tree Implimentation???
87557 by: Bradley Goldsmith
Re: PHPBuilder.com Has an Easy File Upload Article, does any1 know
87558 by: Tom Rogers
Spruce Tree???
87559 by: Bradley Goldsmith
image creation to file
87560 by: Craig Westerman
87561 by: Tom Rogers
87563 by: Craig Westerman
87564 by: Jim Koutoumis
87581 by: Tom Rogers
HELP UNIX vs Windows
87562 by: Christopher J. Crane
87573 by: michael kimsal
Crontab
87565 by: Uma Shankari T.
87571 by: Philip Hallstrom
File/Directory Permissions
87566 by: Alan McFarlane
87578 by: jtjohnston
Use of flock()
87567 by: Alan McFarlane
header() and frames
87568 by: Alan McFarlane
87570 by: Jim Winstead
87588 by: Paul A. Procacci
A good PHP Shop
87569 by: Peter Haywood
writing to a file
87572 by: Marc-Andre Vallee
87580 by: Marc-Andre Vallee
Re: include() and paths
87574 by: Patrick Teague
87577 by: michael kimsal
$db_list = mysql_list_dbs
87575 by: jtjohnston
87587 by: Kearns, Terry
how to access an ini file using PHP
87576 by: jtjohnston
Is flock necessary?
87579 by: jtjohnston
Calling a Variable in a weird Way
87582 by: Phillip S. Baker
87583 by: Jason Murray
Caching Problem
87584 by: Paul A. Procacci
87585 by: Paul A. Procacci
Re: #!/usr/bin/php in output?
87586 by: Kearns, Terry
Re: case insenstive
87589 by: Kearns, Terry
Compilation of PHP with socket module
87590 by: Fr�d�ric Vissault
Re: CheckBoxes....
87591 by: Kearns, Terry
mail() & getenv() problems (after 4.1.2 update)...
87592 by: Paul
Database Error
87593 by: Navid Yar
87594 by: Jason Wong
87595 by: Navid Yar
Administrivia:
To subscribe to the digest, e-mail:
[EMAIL PROTECTED]
To unsubscribe from the digest, e-mail:
[EMAIL PROTECTED]
To post to the list, e-mail:
[EMAIL PROTECTED]
----------------------------------------------------------------------
--- Begin Message ---
Craig Westerman <[EMAIL PROTECTED]> wrote:
> I'm just now trying to learn PHP. I don't know ANYTHING about XML. I don't
> even have any XML reference books yet. I did create a PHP script that is
> usable (see below), but there has to be a more efficient way to do it with
> PHP. I'll hunt up your post on XML in the archives after I get a XML book.
the example you provided isn't xml. (it has some resemblance, but it isn't
xml.) here's a code snippet that will turn that format into an array:
$fp = fopen($url,"r");
if (!$fp) die("could not open URL");
$out = array();
while (!feof($fp)) {
$line = fgets($fp,512);
if (preg_match('!<(\w+?)>(.*?)</\1>!', $line, $m)) {
$out[$m[1]] = $m[2];
}
}
fclose($fp);
print_r($out);
jim
--- End Message ---
--- Begin Message ---Thanks Jim. Works like a charm. Real sweet. Would you explain what this line does? $out[$m[1]] = $m[2]; Learning is a real blast. Wish I would have jumped in a couple of years ago. Thanks again. Craig ><> [EMAIL PROTECTED] -----Original Message----- From: Jim Winstead [mailto:[EMAIL PROTECTED]] Sent: Wednesday, March 06, 2002 4:23 PM To: [EMAIL PROTECTED] Subject: Re: [PHP] data from service into array Craig Westerman <[EMAIL PROTECTED]> wrote: > I'm just now trying to learn PHP. I don't know ANYTHING about XML. I don't > even have any XML reference books yet. I did create a PHP script that is > usable (see below), but there has to be a more efficient way to do it with > PHP. I'll hunt up your post on XML in the archives after I get a XML book. the example you provided isn't xml. (it has some resemblance, but it isn't xml.) here's a code snippet that will turn that format into an array: $fp = fopen($url,"r"); if (!$fp) die("could not open URL"); $out = array(); while (!feof($fp)) { $line = fgets($fp,512); if (preg_match('!<(\w+?)>(.*?)</\1>!', $line, $m)) { $out[$m[1]] = $m[2]; } } fclose($fp); print_r($out); jim -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php--- End Message ---
--- Begin Message ---On Wed, Mar 06, 2002 at 06:02:15PM -0600, Craig Westerman wrote: > Would you explain what this line does? > > $out[$m[1]] = $m[2]; it assigns an entry to the output array. $m is populated by preg_match (where it was passed as the third argument) with the entire match in $m[0], the first parenthesized expression in $m[1] (which is the element name), and the second parenthesized expression in $m[2] (which is the value). jim--- End Message ---
--- Begin Message ---
If the value you want to send back to php is an integer you could just
say
exit $number;
from perl and that will be put into your $var.
Otherwise use exec() instead of system.
exec("/path/to/perlscript.pl", $scriptOutputArray, $scriptExitValue);
Anything that gets printed from the perl script should show up in the
$scriptOuputArray.
-Steve
On Wednesday, March 6, 2002, at 04:19 PM, Michael Hess wrote:
>
>
> Thanks,
>
> Ok,
> I got it to work.....now how do I take a varaible back into PHP
>
>
> I do a $var = system("/path/to/cgi $varforCGI")
> and in the CGI script I do a print $varforPHP
>
> however it prints the varforPHP to the broswer, I need it saved it var
>
> Any (more) help would be great!!
>
> Michael
>
> On
> Wed, 6
> Mar 2002, Steve Cayford wrote:
>
>> If you're running a perl script on the command line you would use
>> /path/to/perl/script.pl value1 value2 value3 ...
>>
>> In your perl script $ARGV[1] should hold value1, $ARGV[2] should hold
>> value2, etc.
>>
>> -Steve
>>
>> On Wednesday, March 6, 2002, at 02:48 PM, [EMAIL PROTECTED] wrote:
>>
>>> I need to pass a variable to Perl from a PHP script. I am somewhat
>>> know
>>> PHP but I do NOT know perl....I am running my perl script off of the
>>> command line. I tried /path/to/somewhere/script.pl?var=var
>>>
>>> but it did not work.
>>>
>>> I would love any help you could provide me
>>>
>>> Thanks,
>>> Michael
>>>
>>>
>>> --
>>> PHP General Mailing List (http://www.php.net/)
>>> To unsubscribe, visit: http://www.php.net/unsub.php
>>>
>>
>
--- End Message ---
--- Begin Message ---Hi there! I am wondering if there is any way to stop PHP from sending any headers at all. I know about php -q, but unfortunately I want it to work with the module version of PHP as well. What I do is collect all output with the ob_ functions, and send it to a pipe. And there the output is encoded, headers are sent and the content is sent to stdout. However, after this is done, more headers are being sent by PHP. I want to keep it as much as possible outside the PHP code (I have my reasons :) I guess I could grab the output from the pipe, but if there's a way to make php not send any headers at all that'd be much nicer. Right now I "fixed" it by printing <!-- in the external prog, and after that --> in the php code, so at least the headers don't show up in the browser.. Nice is something else tho. Any ideas? Thanks! /Nico--- End Message ---
--- Begin Message ---
Hi -
Here's my dilema.
include() will include a *file* and if there are PHP tags in it will run
that PHP code, otherwise pass it along as is.
eval() will parse a *string* of PHP code, but assumes it's valid PHP code.
I want to something like this:
- read a file that contains a mixture of text and PHP code into $string.
- evaluate $string in the same way include() does it.
The reasoning for this is that include() works great if what you're
including is in the filesystem, but what if it's in the database? There
doesn't seem to be a way to do it then.
What I really want is a include_string() function.
Anyone know if something like this exists? I looked, but couldn't find
it. I also looked through the source code and while I found the parts
that deal with includes/evals I don't know enough to know how to add it.
Any and all help appreciated.
thanks!
-philip
--- End Message ---
--- Begin Message ---Looking around, I see someone else has submitted a feature request for this exact thing... http://bugs.php.net/bug.php?id=5435 Not that this helps *me*, but there's more than one of us :) On Wed, 6 Mar 2002, Philip Hallstrom wrote: > Hi - > Here's my dilema. > > include() will include a *file* and if there are PHP tags in it will run > that PHP code, otherwise pass it along as is. > > eval() will parse a *string* of PHP code, but assumes it's valid PHP code. > > I want to something like this: > > - read a file that contains a mixture of text and PHP code into $string. > - evaluate $string in the same way include() does it. > > > The reasoning for this is that include() works great if what you're > including is in the filesystem, but what if it's in the database? There > doesn't seem to be a way to do it then. > > What I really want is a include_string() function. > > Anyone know if something like this exists? I looked, but couldn't find > it. I also looked through the source code and while I found the parts > that deal with includes/evals I don't know enough to know how to add it. > > > Any and all help appreciated. > > thanks! > > -philip > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php >--- End Message ---
--- Begin Message ---
Well, it sort of helps me (dang my quick sends :)
He has a workaround... for anyone else that needs it.
function my_eval($my_eval_str) {
$eval_str = "?>";
$eval_str .= $my_eval_str;
$eval_str .= "<?";
return eval($eval_str);
}
On Wed, 6 Mar 2002, Philip Hallstrom wrote:
> Looking around, I see someone else has submitted a feature request for
> this exact thing...
>
> http://bugs.php.net/bug.php?id=5435
>
> Not that this helps *me*, but there's more than one of us :)
>
> On Wed, 6 Mar 2002, Philip Hallstrom wrote:
>
> > Hi -
> > Here's my dilema.
> >
> > include() will include a *file* and if there are PHP tags in it will run
> > that PHP code, otherwise pass it along as is.
> >
> > eval() will parse a *string* of PHP code, but assumes it's valid PHP code.
> >
> > I want to something like this:
> >
> > - read a file that contains a mixture of text and PHP code into $string.
> > - evaluate $string in the same way include() does it.
> >
> >
> > The reasoning for this is that include() works great if what you're
> > including is in the filesystem, but what if it's in the database? There
> > doesn't seem to be a way to do it then.
> >
> > What I really want is a include_string() function.
> >
> > Anyone know if something like this exists? I looked, but couldn't find
> > it. I also looked through the source code and while I found the parts
> > that deal with includes/evals I don't know enough to know how to add it.
> >
> >
> > Any and all help appreciated.
> >
> > thanks!
> >
> > -philip
> >
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
--- End Message ---
--- Begin Message ---
I'm having issues registering and then updating a value for specific items
in an array. I've read through the manual and MARC but I can't seem to find
the right answer. Here's what I'm trying to do...
Basic Backgroung: This is a "view cart" page. Depending on products that
they have selected I pull information from a MySQL database to give details
about their product. To do so I have set up a loop (duh) and on each pass
of the loop I add information to the session array. Here's the code...it
will make more sense...
First...I clean the arrays so that I don't have conflicting data...this is
done first thing on the page after session_start();
session_start();
session_register('subtotal');
session_unregister('kitem');
session_unregister('kquan');
session_unregister('kscale');
session_unregister('kdetail');
session_unregister('kdriver');
session_unregister('ksponsor');
session_unregister('kcompany');
session_unregister('kprice');
Then comes the loop which adds data to the now empty arrays...
for ($index = 0; $index < $indexLimit; $index++)
//connect and query MySQL database
include ("connect.php");
$result = mysql_query("SELECT * FROM ar
LEFT JOIN company on ar.company_id=company.company_id
LEFT JOIN scale on ar.scale_id=scale.scale_id
WHERE ar.item_number = '".$i[$index]."'\n");
//sort through results
if ($myrow = mysql_fetch_array($result))
{
do
{
if ($quan != 0 && $quan != "" && $quan != "0")
{
//the following vars will be used on the order form as hidden
fields.
$kitem[$index] = $myrow[item_number];
$kquan[$index] = $quan;
$kscale[$index] = $myrow[size];
$kdetail[$index] = $myrow[details];
$kdriver[$index] = $myrow[driver_name];
$ksponsor[$index] = $myrow[sponsor];
$kcompany[$index] = $myrow[value];
$kprice [$index] = $myrow[price];
}
}
while($myrow = mysql_fetch_array($result));
}
And then finally I reset my session variables (arrays) like this...
session_register('kitem');
session_register('kquan');
session_register('kscale');
session_register('kdetail');
session_register('kdriver');
session_register('ksponsor');
session_register('kcompany');
session_register('kprice');
I get mixed and varied results...usually the items show up twice or don't
show up at all. Please help if you can see anything that is being done
wrong. Thanks...
-Jordan
--- End Message ---
--- Begin Message ------ End Message ---
--- Begin Message ---Hi I use the following construct to avoid the "?" in the url which stops the image being cached... img src="http://www.domain.com.au/buttons/image.gif-System-3-ffffff-9-L/test" then have a rewrite rule that redirects anything at /buttons/ to index.php This way I can send file name of the background image, font, size, colour, offset,alignment and finaly the text to use. and it is still cacheable. If you want a copy of my index.php which unscrambles that lot let me know... Tom At 06:09 AM 7/03/2002, Adrian Murphy wrote: >This seems strange to me but i promise it's happening. >I'm dynamically creating images for a page ,calling them so: ><img src="butonn.php?string=hello"> >I'm also preloading the mouseover versions. >the problem is that the images are not being preloaded: >javascript problem you say? >the strange thing is that when i use the source of the php >page and save it as a html page,the html page works fine! >I've encountered a few strange problems with image generation stuff.any ideas >adrian--- End Message ---
--- Begin Message ---Hi to all, Just want to ask if there is any function that will force to wrap character by it width length and not by its character length. Wordwrap function can force wrapping by its character and not by its width. Please help. Regards, Mike--- End Message ---
--- Begin Message ---Right, I'd like to post messag to this newsgroup. However, a auto reply message tell me to subscript the mailing list first. Hence, I join the mailing list, but I got near a hundred more mail than. Can I use this newgroup but don't recieve any mailing list mail from php.general mailinglist anymore?? Zenith--- End Message ---
--- Begin Message ---
Hi,
Are there any binary tree implimentations avaliable for php4?
Cheers,
Brad
--- End Message ---
--- Begin Message ---
Hi
Here is a script that will send any file for download, even .html files. I
called it send.php
<?
$headertxt = "Content-Disposition: attachment; filename=\"".$filename."\"";
header("Content-Type: application/force-download");header($headertxt);
$fd = fopen("$filename","r");
fpassthru($fd);
?>
usage is send.php?filename=file_to_send
Looks weird but it works
Tom
At 06:31 AM 7/03/2002, Caleb Carvalho wrote:
>Hi all,
>
>PHPBuilder.com Has an Easy File Upload Article, i find it to be very
>useful and helpful for my situation, does any one know of a similar but
>for download the uploaded file?
>
>I would like to upload and download file in my server directory using php,
>
>please, please let me know of any article that can help me,
>
>in the mean time i'll keep searching for solution;
>
>many thanks
>
>Caleb
>
>_________________________________________________________________
>Send and receive Hotmail on your mobile device: http://mobile.msn.com
>
>
>--
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, visit: http://www.php.net/unsub.php
>
--- End Message ---
--- Begin Message ---
Hi All,
Below is a bit of a post that I found in the archives...
Is the Spruce tree implimentation available somewhere?
Cheers,
Brad
From: Spruce Weber ([EMAIL PROTECTED])
Date: 09/21/00
I've created from scratch a tree class that utilizes templates. What makes
this class worth using is the fact that it uses templates and the ease with
which it is extended. Heirarchical data is often stored in a database table
as follows:
record_id, parent_record_id, field_1, field_two, field_three...
The only data my class requires for each record/branch is its ID and its
parent's ID (or 0 if it's a top-level record/branch). The vars element can
contain one or more var=>val pairs that can be used when parsing each branch
of the tree. Data returned by a query of a table in the above format can be
easily prepared for use by my tree class as follows...
While($db->next_record()) {
$data[$db->f("record_id")] =
array("parent" => $db->f("parent_record_id"),
"vars" => array("field_1"=>$db->f("field_1"),
"field_2"=>$db->f("field_2"),
"field_3"=>$db->f("field_3")
));
}
The following code will then parse and display the tree, complete with links
that will expand and collapse branches that have children.
if(!$sess->is_registered("tree")) {
$tree = new Spruce_Tree("/some/directory");
$sess->register("tree");
}
if($sprout) $tree->sprout($sprout); // expand a branch
if($prune) $tree->prune($prune); // collapse a branch
$tree->set_tree_target("a_target"); // only necessary when using frames
$tree->pparse($data); // parse tree and print results
The branches can contain as much or as little data as you like depending on
the fields you place in the template and the data you insert into each
"vars" element.
The only data that is stored in the session is the name of the template file
being used (spruce_tree.tpl by default), the directory in which the template
is located, and an array containing the IDs of branches that are currently
expanded.
Yes, my name is Spruce, and this is my Tree class! If there's any interest
I'll be happy to share the implementation.
--- End Message ---
--- Begin Message ---
The following creates a red rectangle png image
<?
Header("Content-Type: image/png");
$im = ImageCreate(500, 75);
$red = ImageColorAllocate($im, 255, 0, 0);
ImageFill($im, 100, 100, $red);
ImagePNG($im);
?>
This sends created image to browser
ImagePNG($im);
How would I save this image as test.png to file to be hard coded in static
web pages?
Thanks
Craig ><>
[EMAIL PROTECTED]
--- End Message ---
--- Begin Message ---
Hi
use ImagePNG($im,"test.png")
Tom
At 12:17 PM 7/03/2002, Craig Westerman wrote:
>The following creates a red rectangle png image
>
><?
>Header("Content-Type: image/png");
>$im = ImageCreate(500, 75);
>$red = ImageColorAllocate($im, 255, 0, 0);
>ImageFill($im, 100, 100, $red);
>ImagePNG($im);
>?>
>
>
>This sends created image to browser
>ImagePNG($im);
>
>
>How would I save this image as test.png to file to be hard coded in static
>web pages?
>
>Thanks
>
>Craig ><>
>[EMAIL PROTECTED]
>
>
>--
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, visit: http://www.php.net/unsub.php
--- End Message ---
--- Begin Message ---
Hi Tom,
At first it didn't work. I had to create a blank png image in Photoshop and
uploaded it. I then changed file permissions and then the image creation
worked. Is there a way to write to test.png when it doesn't already exist
and file permissions are set?
Thanks for your help.
Craig ><>
[EMAIL PROTECTED]
Hi
use ImagePNG($im,"test.png")
Tom
At 12:17 PM 7/03/2002, Craig Westerman wrote:
>The following creates a red rectangle png image
>
><?
>Header("Content-Type: image/png");
>$im = ImageCreate(500, 75);
>$red = ImageColorAllocate($im, 255, 0, 0);
>ImageFill($im, 100, 100, $red);
>ImagePNG($im);
>?>
>
>
>This sends created image to browser
>ImagePNG($im);
>
>
>How would I save this image as test.png to file to be hard coded in static
>web pages?
>
>Thanks
>
>Craig ><>
>[EMAIL PROTECTED]
--- End Message ---
--- Begin Message ---An alternative is to put the code into makeImage.php and then call it directly from your HTML page with your <IMG SRC="makeImage.php"> whenever you want that image displayed. Jim..... "Tom Rogers" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > Hi > use ImagePNG($im,"test.png") > > Tom > > At 12:17 PM 7/03/2002, Craig Westerman wrote: > >The following creates a red rectangle png image > > > ><? > >Header("Content-Type: image/png"); > >$im = ImageCreate(500, 75); > >$red = ImageColorAllocate($im, 255, 0, 0); > >ImageFill($im, 100, 100, $red); > >ImagePNG($im); > >?> > > > > > >This sends created image to browser > >ImagePNG($im); > > > > > >How would I save this image as test.png to file to be hard coded in static > >web pages? > > > >Thanks > > > >Craig ><> > >[EMAIL PROTECTED] > > > > > >-- > >PHP General Mailing List (http://www.php.net/) > >To unsubscribe, visit: http://www.php.net/unsub.php >--- End Message ---
--- Begin Message ---
Hi
You have to make sure that the user that your web server is running as has
permission to write where you want to create the file.
Tom
At 12:56 PM 7/03/2002, Craig Westerman wrote:
>Hi Tom,
>
>At first it didn't work. I had to create a blank png image in Photoshop and
>uploaded it. I then changed file permissions and then the image creation
>worked. Is there a way to write to test.png when it doesn't already exist
>and file permissions are set?
>
>Thanks for your help.
>
>Craig ><>
>[EMAIL PROTECTED]
>
>
>
>Hi
>use ImagePNG($im,"test.png")
>
>Tom
>
>At 12:17 PM 7/03/2002, Craig Westerman wrote:
> >The following creates a red rectangle png image
> >
> ><?
> >Header("Content-Type: image/png");
> >$im = ImageCreate(500, 75);
> >$red = ImageColorAllocate($im, 255, 0, 0);
> >ImageFill($im, 100, 100, $red);
> >ImagePNG($im);
> >?>
> >
> >
> >This sends created image to browser
> >ImagePNG($im);
> >
> >
> >How would I save this image as test.png to file to be hard coded in static
> >web pages?
> >
> >Thanks
> >
> >Craig ><>
> >[EMAIL PROTECTED]
>
>
>--
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, visit: http://www.php.net/unsub.php
--- End Message ---
--- Begin Message ---
I am a PERL scripter and I am just getting into PHP. My first few pages are
simple but I am running into a few problems when changing OS. I included
below a piece of code that works fine in windows but not on a linux box. Not
sure what the differences would be....
The problem is that on the windows platform all information is returned. On
the linux platform the "$Details" variable is not populated. The nothing
changes...so what could it be. The only thing I can think of is that maybe
the version of php is different on the linux server.
Here is the code.....after reading in a file with "|" deliminations
while ($i < $length):
$tok = strtok($cartFile[$i],"|");
$Category = $tok; $tok = strtok("|");
$SKU = $tok; $tok = strtok("|");
$Name = $tok; $tok = strtok("|");
$SubCategory = $tok; $tok = strtok("|");
$Price = $tok; $tok = strtok("|");
$Image1 = $tok; $tok = strtok("|");
$Image2 = $tok; $tok = strtok("|");
$OnSale = $tok; $tok = strtok("|");
$SalePrice = $tok; $tok = strtok("|");
$Details = $tok; $tok = strtok("|");
if($MCat == "$Category") {
$Count++;
if($OnSale == "1") { $Price = "<s>$$Price</s> <font color=\"red\">On
Sale Now!</font> $$SalePrice"; }
displayProd($Category,$SKU,$Name,$SubCategory,$Price,$Image1,$Image2,$OnSale
,$SalePrice,$Details);
}
$i++;
endwhile;
--- End Message ---
--- Begin Message ---
Christopher J. Crane wrote:
> I am a PERL scripter and I am just getting into PHP. My first few pages are
> simple but I am running into a few problems when changing OS. I included
> below a piece of code that works fine in windows but not on a linux box. Not
> sure what the differences would be....
>
> The problem is that on the windows platform all information is returned. On
> the linux platform the "$Details" variable is not populated. The nothing
> changes...so what could it be. The only thing I can think of is that maybe
> the version of php is different on the linux server.
>
> Here is the code.....after reading in a file with "|" deliminations
> while ($i < $length):
> $tok = strtok($cartFile[$i],"|");
> $Category = $tok; $tok = strtok("|");
> $SKU = $tok; $tok = strtok("|");
> $Name = $tok; $tok = strtok("|");
> $SubCategory = $tok; $tok = strtok("|");
> $Price = $tok; $tok = strtok("|");
> $Image1 = $tok; $tok = strtok("|");
> $Image2 = $tok; $tok = strtok("|");
> $OnSale = $tok; $tok = strtok("|");
> $SalePrice = $tok; $tok = strtok("|");
> $Details = $tok; $tok = strtok("|");
>
It could be a different version - what are the versions on the two systems?
In the meantime, could you not use explode() or split() instead?
list($category,$sku,$name,$sub,$price,$etc) = split("|",$cartFile[$i]);
(might need to be "\|" instead of "|" - I can't remember, it's late,
and I don't have easy access to test it. :0
---------------------------
Michael Kimsal
http://www.phphelpdesk.com
734-480-9961
--- End Message ---
--- Begin Message ---
Hello,
I am facing some problem in the crontab...Can anyone tell me how to
solve this
Actually i have written the php script to send mail to the users after a
week.In the crontab i have made a entry so that it will trigger after
12.05.
5 0 * * * lynx http://info/php/MailForm.php
I have received a mail like this.And also it didn't send the mail to
the users....why it is so
"" Your terminal lacks the ability to clear the screen or position the
cursor.""
-Uma
--- End Message ---
--- Begin Message ---Try... lynx -dump .... -philip On Thu, 7 Mar 2002, Uma Shankari T. wrote: > > > Hello, > > I am facing some problem in the crontab...Can anyone tell me how to > solve this > > Actually i have written the php script to send mail to the users after a > week.In the crontab i have made a entry so that it will trigger after > 12.05. > > 5 0 * * * lynx http://info/php/MailForm.php > > I have received a mail like this.And also it didn't send the mail to > the users....why it is so > > > "" Your terminal lacks the ability to clear the screen or position the > cursor."" > > > > -Uma > > > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php >--- End Message ---
--- Begin Message ---I've seen and successfully used the built-in function 'mkdir()' on several occasions, but I am having trouble understanding the mode parameter. I've seen 0771, 0775 and 0777 used on several occasions but I am never quite sure what to use. Since I write and normally run scripts on a Windows platform (NT WorkStation SP5), I'm pretty sure it does not affect me, but I would like my code to run without modification on a *nix platform. So, can anyone explain the mode parameter for me please? As a slight side note - can these permissions be applied to files - if so, when (and how) would it be done? -- Alan McFarlane--- End Message ---
--- Begin Message --- I know you would want to code your chmod, but I use my CuteFTP window to auto-calculate which permissions I want to use/code. Not necessary on Windows, but on Unix it's an absolute.I use 644 (Read Owner, Read Group, Read Public,Write Owner, on a Unix server with no trouble for normal *.PHP files.
![]()
--- End Message ---
--- Begin Message ---
I've just written a couple of simple routines which read an write small text
files to the server:
function readData( $filename, &$data )
{
if (!$fd = @fopen($filename, "r"))
{
return false;
}
flock($fd, LOCK_SH);
$data = fread($fd, filesize($filename));
fclose($fd);
return true;
}
function writeData( $filename, $data )
{
if (!$fd = @fopen($filename, "w"))
{
return false;
}
flock($fd, LOCK_EX);
fwrite($fd, $data);
fclose($fd);
return true;
}
Now, the question is... How much time elapses between the fopen() statement
and the flock() statements?
Looking at the code, it would appear that two separate threads may call
writeData() almost simultaneously giving the following execution:
assume $filename = "sample.txt";
Thread #1 - $fd = fopen($filename, "w"); // succeeds
Thread #2 - $fd = fopen($filename, "w"); // succeeds (I think)
Thread #1 - flock($fd, LOCK_EX); // Does this succeed or fail?
Thread #2 - flock($fd, LOCK_EX); // fails (I think)
--- End Message ---
--- Begin Message ---
I've got a site where the administration facilities use frames. Now, as the
authentication
expires after a fixed period of no use, I check to see if we are an
authenticated user. If not,
I would like to redirect them to a non-framed page.
I'm trying something like:
header("location: index.php; target: _top");
Anyone got any suggestions or pointers?
--
Alan McFarlane
--- End Message ---
--- Begin Message ---
Alan McFarlane <[EMAIL PROTECTED]> wrote:
> header("location: index.php; target: _top");
header("Location: index.php");
header("Window-target: _top");
jim
--- End Message ---
--- Begin Message ---
Does that actually work? I'm using Mozilla, and it didn't work for me? :)
Paul
Jim Winstead wrote:
>Alan McFarlane <[EMAIL PROTECTED]> wrote:
>
>>header("location: index.php; target: _top");
>>
>
>header("Location: index.php");
>header("Window-target: _top");
>
>jim
>
--- End Message ---
--- Begin Message ---Hello,, I am looking at setting up PHP driven shop. Can anyone recommend one? Or which ones to stay away from? And why? I am reviewing phpShop at the moment, and it looks pretty nicely featured. Thanks, Pete--- End Message ---
--- Begin Message ---Hi, Here is a foo.txt file : name=foo age=100 sex=y I want to open the file, find the age line, and then replace the 100 with another value. The only way i see, is to rewrite the entire file........ Maybe this is a stupid question, but, i tried the online doc, and saw nothing about this.... Thanks a lot Marc-Andre Vallee [EMAIL PROTECTED]--- End Message ---
--- Begin Message ---Hi, Here is a foo.txt file : name=foo age=100 sex=y I want to open the file, find the age line, and then replace the 100 with another value. The only way i see, is to rewrite the entire file........ Maybe this is a stupid question, but, i tried the online doc, and saw nothing about this.... Thanks a lot -- Marc-Andre Vallee [EMAIL PROTECTED]--- End Message ---
--- Begin Message ---ok, so this makes alot of since... if I move my website from one server to another server I'll have to go through every single file & redo the directory structure? Isn't this the reason for the includes... so you don't have to go through every single file to make changes? Maybe I should go back to ASP... #include virtual="/includes/myinclude.inc" or is there a way to get this to work via php on apache? Patrick--- End Message ---
--- Begin Message ---Patrick Teague wrote: > ok, so this makes alot of since... if I move my website from one server to > another server I'll have to go through every single file & redo the > directory structure? Isn't this the reason for the includes... so you > don't have to go through every single file to make changes? Maybe I should > go back to ASP... > > #include virtual="/includes/myinclude.inc" > > or is there a way to get this to work via php on apache? Per http://www.php.net/manual/en/function.ini-set.php, PHP_INCLUDE_PATH is an 'ini' setting which you can change - you could either set it in your php.ini once, and point it to one common 'includes' direcotry. Or possibly set it per apache virtual server (via .htaccess perhaps in a main root directory). Another thought is to simply make all your include statements use a constant, such as DOCUMENT_ROOT or something else (we use something else but the idea is the same). Yes, all includes need to be written as include(MYDIRPATH."/relative/stuff.php"); Also, try ini_set(PHP_INCLUDE_PATH,DOCUMENT_ROOT); at the top of your page(s). That might do the trick. but it makes everything a heck of a lot more portable. Don't go back to ASP. If you really want to use <!--#include virtual--> stuff Apache supports that via .shtml files. There are probably ways of getting the two to work together (PHP and SSI) though I'm not sure why you'd want to do so. :) Remember ASP is a framework, and VBScript is the popular language there. VBScript doesn't support includes at all - it's ASP calling an SSI interpreter, include()ing things, then passing to the language. PHP is just a language. There are some pretty ugly, inelegant things going on under the hood with respect to includes under ASP - if you want gorey details let me know. :) After writing all this I see it's basically a rehash of the 9/2/2001 posting in the user comments under include at the php manual site. Is there a reason one of those 3 options isn't viable? Michael Kimsal http://www.phphelpdesk.com Taking the ? out of <?php 734-480-9961--- End Message ---
--- Begin Message ---mysql-list-dbs works but displays all databases. How do I limit to display those that a user has access rights to? http://www.php.net/manual/en/function.mysql-list-dbs.php $link = mysql_connect($server, $user, $password); $db_list = mysql_list_dbs($link); while ($row = mysql_fetch_object($db_list)) { echo $row->Database . "\n"; }--- End Message ---
--- Begin Message ---Do a select on mysql's system database/table Mysql.db There's a column called db and one called user. Put a where clause on user. If you want more help, there is a PHP-DB mailing list. [TK] > -----Original Message----- > From: jtjohnston [mailto:[EMAIL PROTECTED]] > Sent: Thursday, 7 March 2002 3:31 PM > To: [EMAIL PROTECTED] > Subject: [PHP] $db_list = mysql_list_dbs > > > mysql-list-dbs works but displays all databases. How do I > limit to display those that a user has access rights to? > http://www.php.net/manual/en/function.mysql-list-dbs.php $link = mysql_connect($server, $user, $password); $db_list = mysql_list_dbs($link); while ($row = mysql_fetch_object($db_list)) { echo $row->Database . "\n"; } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php--- End Message ---
--- Begin Message ---[Posted and Replied] Salut Marc, You could find an ini file function. Something like: http://www.zend.com/apidoc/c1948.php http://ca.google.yahoo.com/bin/query_ca?p=how+to+access+an+ini+file+using+PHP&y=on&hc=0&hs=0 You would have to add one line: [MyData] name=foo age=100 sex=y I've done it with Perl, but have never found anything for PHP. Have you thought of a mysql database? That's all I use now.--- End Message ---
--- Begin Message ---
Group: Is flock even necessary?
Allan: You look like you have Perled. It was necessary for Perl.
Have you thought of MySQL instead?
Alan McFarlane wrote:
> I've just written a couple of simple routines which read an write small text
> files to the server:
>
> function readData( $filename, &$data )
> {
> if (!$fd = @fopen($filename, "r"))
> {
> return false;
> }
>
> flock($fd, LOCK_SH);
> $data = fread($fd, filesize($filename));
> fclose($fd);
>
> return true;
> }
>
> function writeData( $filename, $data )
> {
> if (!$fd = @fopen($filename, "w"))
> {
> return false;
> }
>
> flock($fd, LOCK_EX);
> fwrite($fd, $data);
> fclose($fd);
>
> return true;
> }
>
> Now, the question is... How much time elapses between the fopen() statement
> and the flock() statements?
>
> Looking at the code, it would appear that two separate threads may call
> writeData() almost simultaneously giving the following execution:
>
> assume $filename = "sample.txt";
>
> Thread #1 - $fd = fopen($filename, "w"); // succeeds
> Thread #2 - $fd = fopen($filename, "w"); // succeeds (I think)
> Thread #1 - flock($fd, LOCK_EX); // Does this succeed or fail?
> Thread #2 - flock($fd, LOCK_EX); // fails (I think)
--
John Taylor-Johnston
-----------------------------------------------------------------------------
' ' ' Coll�ge de Sherbrooke:
��� http://www.collegesherbrooke.qc.ca/languesmodernes/
- Universit� de Sherbrooke:
http://compcanlit.ca/
819-569-2064
--- End Message ---
--- Begin Message ---
I am not sure I can articulate this well.
But I will try.
I want to combine either two variables or a variable and string to bring up
the name of a previous variable name to display the data from the first.
So in the first part I will have a listing that will look like
<type=radio name=state_1 value=No>
<type=radio name=state_1 value=Yes>
<type=radio name=state_1 value=Maybe>
<type=radio name=state_2 value=No>
<type=radio name=state_2 value=Yes>
<type=radio name=state_2 value=Maybe>
// Submit etc....
Then later I will call a for loop to try and do something like
for ($i=1; $i < 12; $i++) {
echo state_$i; // This would print out either Yes No or Maybe.
}
Is there a way I can do this.
I thought I heard something about how I can but I do not remember.
Phillip
--- End Message ---
--- Begin Message ---
> for ($i=1; $i < 12; $i++) {
> echo state_$i; // This would print out either Yes No or Maybe.
> }
What you actually want is:
for ($i=1; $i < 12; $i++)
{
$mystate = "state_".$i;
echo $$mystate; // This would print out either Yes No or Maybe.
}
$$X tells PPH to use the value contained in the variable named $X.
Jason
--- End Message ---
--- Begin Message ---
Hey all,
I'm trying not to cache a page. I have the following code:
$return = split(" ", exec("vmstat"));
$cpu_top = 100;
$return = $cpu_top - $return[count($return) -1];
which returns the amount of idle cpu time. The problem is this, every
time the page is loaded, it always show the first value when the page
was first loaded. I tried adding :
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
all randomly, and together, but nothing seems to work. I can run one of
my binaries in a forever loop causing the cpu not ever to be idle, but
still nothing. Help?
Thanks in advance,
Paul
--- End Message ---
--- Begin Message ---
Hah,
I found the problem. It's because vmstat when called always,
initially has the cpu idle at 99. This explains it. So, how would I go
abouts returning used cpu time on a system?
Thanks,
Paul
Paul A. Procacci wrote:
> Hey all,
> I'm trying not to cache a page. I have the following code:
>
> $return = split(" ", exec("vmstat"));
> $cpu_top = 100;
> $return = $cpu_top - $return[count($return) -1];
>
> which returns the amount of idle cpu time. The problem is this, every
> time the page is loaded, it always show the first value when the page
> was first loaded. I tried adding :
>
> header("Cache-Control: no-store, no-cache, must-revalidate");
> header("Cache-Control: post-check=0, pre-check=0", false);
> header("Pragma: no-cache");
>
>
> all randomly, and together, but nothing seems to work. I can run one
> of my binaries in a forever loop causing the cpu not ever to be idle,
> but still nothing. Help?
>
> Thanks in advance,
> Paul
>
--- End Message ---
--- Begin Message ---
OK, the only reason you would have #!/usr/bin/php is if you're going to run
it as a shell script under unix.
You approach should _still_ be 2 scripts (3 if you count the include file).
<file_content file="for_shell.php">
#!/usr/bin/php
<?php include('main_code.php'); ?>
</file_content>
<file_content file="for_cgi.php">
<?php include('main_code.php'); ?>
</file_content>
If the script really must be one and the same (name and path), then maybe
<file_content file="called_script.php">
#!/usr/bin/php
<html><head><title>redirect</title>
<?php
if(!isset(HTTP_REFERRER)):
echo '<meta http-equiv="refresh" content="0;URL=cgi_code.php">';
else:
include('cgi_code.php');
endif;
?>
</head><body></body></html>
</file_content>
Maybe the php executable will ignore the stuff not in <? ?> and not output
the HTML
[TK]
> -----Original Message-----
> From: Mike Eheler [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, 6 March 2002 9:26 AM
> To: [EMAIL PROTECTED]
> Subject: Re: [PHP] #!/usr/bin/php in output?
>
>
> It needs to run as a CGI script.
>
> The reason is maybe it needs to be a dual-purpose script that
> can be run
> from the console, or from the web, or maybe it needs to run as a user
> other than the web server. Whatever my actual reason is
> doesn't matter,
> but trust me, the script must be run as a CGI.
>
> Mike
>
> Anas Mughal wrote:
> > Why do you have "#!/usr/bin/php" in your script?!
> > You are running it thru the webserver. You shouldn't
> > need that line.
> >
> >
> >
> > --- Mike Eheler <[EMAIL PROTECTED]> wrote:
> >
> >>Having a bit of a weird problem with using PHP as
> >>CGI. The problem is
> >>this.. the output is returning the #!/usr/bin/php
> >>line from the file.
> >>
> >>Example:
> >>
> >>/cgi-bin/test:
> >>
> >>#!/usr/bin/php
> >><?
> >> echo "Hello World!\n";
> >>?>
> >>
> >>Then in a web browser:
> >>http://www.example.com/cgi-bin/test:
> >>
> >>#!/usr/bin/php
> >>Hello World!
> >>
> >>Has anyone else experienced this problem or know
> >>what's causing it?
> >>
> >>Mike
> >>
> >>--
> >>PHP General Mailing List (http://www.php.net/)
> >>To unsubscribe, visit: http://www.php.net/unsub.php
> >>
> >>
> >
> >
> > =====
> > Anas Mughal
> > [EMAIL PROTECTED]
> > [EMAIL PROTECTED]
> > Tel: 973-249-6665
> >
> > __________________________________________________
> > Do You Yahoo!?
> > Try FREE Yahoo! Mail - the world's greatest free email!
> > http://mail.yahoo.com/
> >
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
--- End Message ---
--- Begin Message ---Just substitute strstr() with stristr() The extra I in stristr() stands for "Insensitive". If I was insensitive, I would say RTFM >:) If you look under http://www.php.net/manual/en/function.strstr.php It tells you about stristr [TK] > -----Original Message----- > From: jtjohnston [mailto:[EMAIL PROTECTED]] > Sent: Tuesday, 5 March 2002 5:08 PM > To: [EMAIL PROTECTED] > Subject: [PHP] case insenstive > > > I need to make this case insensitive. This seems like over kill? > > if((substr($author, 0, 1) == "a") or (substr($author, 0, 1) > == "a")) { } > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php >--- End Message ---
--- Begin Message ---Hi, Please, is there anybody who can help me to compile PHP with socket module? I work under W2000 with VC++ 6! Thanks in advance Fred--- End Message ---
--- Begin Message ---
Don't name the checkboxes all the same, instead:
Option1 <input type="checkbox" name="ck0"><br>
Option2 <input type="checkbox" name="ck1"><br>
Option3 <input type="checkbox" name="ck2"><br>
Then handle it with
function getCheckboxResults($prefix=FALSE)
{
global $_POST ;
$results = NULL ; // needed for 'return' in case no items (v4.1.x)
if(is_string($prefix)){
For($i=0;$i<=count($_POST);$i++){
if(isset($_POST[$prefix.$i])) $results[] = $i ;
}
} else { return -1 ; } // throw exception in script
return $results ;
}
$selectedCKItems = getCheckboxResults('ck');
if(!$selectedCKItems) makeError('Please select at least one item.');
If a checkbox is not selected, the CGI will drop it (as in, not pass on the
name/value pair - meaning the name is not there - which is why you test for
it's existance).
I didn't test that example. But if it works, the function might be a nice
addition to your (and mine) library :)
you might use it like to:
$prefix = 'ck';
Forech($arrLabels AS $i=>$label)
printf('%s <input type="checkbox" name="%s%d"><br>\n',$label,$prefix,$i);
Then put this member functions in a class deinition and register instatiated
objects with a session to use them across pages. $arrLabels would be a
property of the class. 'ck' would be the value of another property. Maybe
your foreach statement was in a member function.
OK, I'll shut up now :)
[TK]
> -----Original Message-----
> From: Erik Price [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, 5 March 2002 2:24 AM
> To: bvr
> Cc: Ben Turner; [EMAIL PROTECTED]
> Subject: Re: [PHP] CheckBoxes....
>
>
>
> On Sunday, March 3, 2002, at 11:15 AM, bvr wrote:
>
> > If you append '[]' to the name, an array will be returned
> after submit
> > with the values of the checked checkboxes.
> >
>
>
> Is there any other way of doing this? Using the brackets at
> the end of
> the input's name is super-convenient, making it relatively
> easy to work
> with arrays and user input in PHP. I love that. But I also wish I
> could validate my pages as XHTML Strict. I know it's not
> really a big
> deal, it's just a pride-in-work thing.
>
> Alternatively, is there any plans to change the DTD for XHTML
> Strict to
> allow brackets? IMO it's not something that cause problems
> if it were
> to be supported. Kind of lame that it's not, actually.
>
> Until then, I'll keep using them (brackets) b/c there's some
> things that
> it seems I can't do without this technique, but it would be nice....
>
>
> Erik
>
>
>
>
> ----
>
> Erik Price
> Web Developer Temp
> Media Lab, H.H. Brown
> [EMAIL PROTECTED]
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
--- End Message ---
--- Begin Message ---
Hello,
I wonder if anyone can help me with a problem I have. I have some sites
hosted on a Cobalt Raq4 server (not sure if this is relevant). I recently
upgraded PHP from a package at www.pkgmaster.com, and since making this
upgrade I have problems with PHP that I cannot find the solution to.
I have conacted their 'team' who have thus far offered no explanation,
saying it must be something else causing these issues with PHP, but I
haven't made any more changes, just installed the new PHP version.
The problems are with the mail() function taking an AGE to excecute, and
environmental HTTP header information not being sent/recieved by getenv().
Some examples follow..
For example, as an extremely basic example of the mail function going slow,
this simple script:
<?
mail("[EMAIL PROTECTED]", "Test subject", "Test message");
print "finished!";
?>
Which can be found at http://www.clicktolearn.co.uk/test/mail.php in action,
ran (as it should do) extremely fast the week before I made the upgrade from
the packages. Now, as you will see, it runs dog slow.
Secondly, the following script shows the lack of headers:
http://www.clicktolearn.co.uk/test/ (click the link, so there's a referer
to the script page)...
<?
function get_http_headers($url, $proto="HTTP/1.0", $timeout=10) {
$return = false;
if (substr($url,0,7)=="http://") {
$url = substr($url,7);
}
$parts = parse_url("http://".$url);
$ips = gethostbynamel($parts["host"]);
if ($ips[0]) {
$ip = $ips[0];
$host = $parts["host"];
$path = ($parts["path"]) ? $parts["path"] : "/";
$port = ($parts["port"]) ? $parts["port"] : 80;
$start = time();
$timeout = $timeout + $start;
if($sock = fsockopen($host, $port)) {
set_socket_blocking($sock, 0);
switch($proto) {
case "HTTP/1.1":
set_socket_blocking($sock, 1);
fputs($sock, sprintf("HEAD %s %s\n",
$path, $proto));
fputs($sock, sprintf("Host: %s\n\n",
$host));
break;
default:
fputs($sock, sprintf("HEAD %s
%s\n\n", $path, $proto));
}
while(!feof($sock) && $t<$timeout) {
$line .= fgets($sock,1);
$t = time();
}
fclose($sock);
$end = time();
if ($t>=$timeout) {
$http = parse_output($line);
$http["result"] = 502;
$http["message"] = "Timed Out";
$http["time_used"] = $end - $start;
$return = $http;
} elseif($line) {
$http = parse_output($line);
$http["time_used"] = $end - $start;
$return = $http;
}
}
}
return $return;
}
function parse_output($line) {
$lines = explode("\n", $line);
if(substr($lines[0],0,4)=="HTTP") {
list($http["protocol"], $http["result"], $http["message"]) =
split("[[:space:]]+",$lines[0],3);
} else if(substr($lines[0],0,7)=="Server:") {
$http["server"] = substr($lines[0],8);
}
for ($i=1; $i<count($lines); $i++) {
list($key, $val) = split(":[[:space:]]*", $lines[$i],2);
$key = strtolower(trim($key));
if ($key) {
$http[$key] = trim($val);
} else {
break;
}
}
return($http);
};
var_dump(getallheaders());
print "<br><br>";
var_dump(get_http_headers('http://www.clicktolearn.co.uk/test/testheaders.ph
p'));
print "<br><br>";
print $HTTP_REFERER;
print "<br><br>";
print "<a href='Javascript: history.back();'>Back</a>";
print "<br><br>";
var_dump(getenv($HTTP_REFERER));
?>
Under the "Back" link is the output of: var_dump(getenv($HTTP_REFERER));
Now I know that this was working before the upgrade, as a log in script I
use on the main site uses getenv($HTTP_REFERER) to send them back to where
they came from. This again worked 100% fine before PHP upgrade.
Sorry to take up your time, but there is a problem somewhere that has
certainly only begun with PHP since I upgraded to 4.1.2, and I dont know
what it could be!?
Thanks in advance.
Paul Mullett
--- End Message ---
--- Begin Message ---
Ok guys, I need help with this one. I am getting the error: Error in
query: SELECT label FROM menu WHERE id = '1'. Why am I getting this
error? It seems right to me. I have the following code to call the class
object, and I listed the class below it (I'm fairly new to classes):
// Object being called from get.php
<?php
require("menu.class.php");
$obj = new Menu();
echo $obj->get_label(1);
?>
// Class in the file menu.class.php
class Menu {
var $hostname;
var $user;
var $pass;
var $db;
var $table;
function Menu() {
$this->set_database_parameters("localhost", "username",
"password", "apps", "menu");
}
function set_database_parameters($hostname, $user, $password, $db,
$table) {
$this->hostname = $hostname;
$this->user = $user;
$this->password = $password;
$this->db = $db;
$this->table = $table;
}
function query($query) {
$connection = mysql_connect($this->hostname, $this->user,
$this->pass) or die ("Cannot connect to database");
$ret = mysql_db_query($this->db, $query, $connection) or die
("Error in query: $query");
return $ret;
}
function get_label($id) {
$query = "SELECT label FROM $this->table WHERE id = '$id'";
$result = $this->query($query);
$row = mysql_fetch_row($result);
return $row[0];
}
}
Thanks to anyone, in advance, that can help me with this one.
--- End Message ---
--- Begin Message ---On Wednesday 06 March 2002 17:56, Navid Yar wrote: > Ok guys, I need help with this one. I am getting the error: Error in > query: SELECT label FROM menu WHERE id = '1'. Why am I getting this > error? It seems right to me. I have the following code to call the class > object, and I listed the class below it (I'm fairly new to classes): > Try plugging your query directly into mysql (at the command-line) to see whether it's a mysql problem or a php one. -- Jason Wong -> Gremlins Associates -> www.gremlins.com.hk /* "If anything can go wrong, it will." -- Edsel Murphy */--- End Message ---
--- Begin Message ---I'm thinking that it probably has to do with the quoting scheme or something else. I tried it on the command line, and it worked fine. I don't even think it matters what types of quotes I use around the id field. I tried both (single and double) on the command line, and it worked just fine. In other words, the SQL is fine, and there's nothing wrong with it. It must either be how I placed the sql statement into the query or how the class is executed. I'm not sure. It might entirely be something else. But, any help on this is really appreciated. -----Original Message----- From: Jason Wong [mailto:[EMAIL PROTECTED]] Sent: Thursday, March 07, 2002 3:51 AM To: [EMAIL PROTECTED] Subject: Re: [PHP] Database Error On Wednesday 06 March 2002 17:56, Navid Yar wrote: > Ok guys, I need help with this one. I am getting the error: Error in > query: SELECT label FROM menu WHERE id = '1'. Why am I getting this > error? It seems right to me. I have the following code to call the class > object, and I listed the class below it (I'm fairly new to classes): > Try plugging your query directly into mysql (at the command-line) to see whether it's a mysql problem or a php one. -- Jason Wong -> Gremlins Associates -> www.gremlins.com.hk /* "If anything can go wrong, it will." -- Edsel Murphy */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php--- End Message ---

