php-general Digest 10 Sep 2002 15:53:46 -0000 Issue 1577

Topics (messages 115806 through 115859):

E-mail a submit
        115806 by: Chuck \"PUP\" Payne

Re: QUery success, but blank results/variables
        115807 by: Tom Rogers
        115809 by: David Freeman

Brainfart while uploading
        115808 by: César Aracena

form variables
        115810 by: Hans Prins
        115811 by: Chris Shiflett
        115815 by: Hans Prins
        115817 by: Justin French

Re: LDAP (NDS) authentication example...
        115812 by: joshua

Need more memory... possible to set?
        115813 by: Damian Harouff

Re: Problems with GD 2.0.1
        115814 by: Tim

Re: Brainfart while uploading <-- SOLVED -- Sorry ;)
        115816 by: César Aracena

message board and gb...
        115818 by: Matt Zur

Re: header("location: ") causes GET vars to be encoded in wrong charset in IE5.5
        115819 by: Jean-Christian Imbeault
        115825 by: Chris Shiflett
        115826 by: Chris Shiflett
        115827 by: . Edwin
        115828 by: . Edwin

Count in PHP
        115820 by: Chuck \"PUP\" Payne
        115821 by: Martin Towell
        115822 by: Tyler Longren
        115823 by: Jome
        115831 by: xdrag

changing session name
        115824 by: Mohd_Q
        115830 by: Luke Welling
        115833 by: Erwin

Re: POST form variables not being sent to destination page
        115829 by: Erwin

Re: dropdown Newbie question
        115832 by: Mario Ohnewald
        115834 by: yasin inat

Generating CSV files on the fly and getting the browser to download
        115835 by: Henry
        115836 by: lallous
        115837 by: Henry
        115838 by: Dave at Sinewaves.net
        115839 by: Erwin

DPHPEdit new version
        115840 by: Davor Pleskina

PhpMyAdmin and PHP4.2.* Too many I/Os
        115841 by: Jean-Pierre Arneodo

Mail() function problem
        115842 by: Alva Chew
        115852 by: Pekka Saarinen

Re: Upload Progress
        115843 by: electroteque

Re: checkbox question
        115844 by: B.C. Lance
        115850 by: Craig Donnelly

Trying to add table prefix variable to query
        115845 by: Verdon Vaillancourt
        115846 by: Jay Blanchard
        115847 by: bbonkosk.tampabay.rr.com

Populating Other People's Forms
        115848 by: Mike At Spy

Re: Trying to add table prefix variable to query (solved)
        115849 by: Verdon Vaillancourt

random array sort
        115851 by: ROBERT MCPEAK
        115853 by: Mike At Spy
        115854 by: David Rice
        115855 by: Mike At Spy
        115856 by: Jacob Miller

Handling variables POSTed from form
        115857 by: Wm

Verify phone format?
        115858 by: Jeff Lewis

Re: random array sort  -- array() selection quant??
        115859 by: ROBERT MCPEAK

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 ---
Hi,

Is there a way that when someone add a submit or edits a record that I can
have my php page e-mail that record? And is hard to do?

Chuck Payne

--- End Message ---
--- Begin Message ---
Hi,

Tuesday, September 10, 2002, 1:41:23 PM, you wrote:
PH> Hello everyone..tryin to run this qry against a mysql db, but after it runs, 
PH> it doesn't assign anything to the variables as it should. If i return all 
PH> rows, and spit out each record in the result in an array, i have the same 
PH> problem, but have 24 'blank' records instead of 1. Any ideas? Thanks for any 
PH> input. I tried doing a print mysql_error(); after the query and the result, 
PH> but it doesn't return anything. Column names, db name, and WHERE clause are 
PH> all spelled correctly, and the $currenttaskid is populated (as 1)...

PH> $detailqry = "SELECT id, parentitemid, itemtypeid, itemstatusid, 
PH> itemlevelid, shortdescription,
PH> createdby_memberid, assignedto_memberid, completedby_memberid, createddate, 
PH> assigneddate,
PH> estcompletiondate, completeddate, projectid, lastuserid, lastdate FROM item 
PH> WHERE id=$currenttaskid";

PH> $result = mysql_query($detailqry) or die("Failed finding task details");

PH>        $taskid = $result["id"];
PH>        $taskparentitemid = $result["parentitemid"];
PH>        $taskitemtypeid = $result["itemtypeid"];
PH>        $taskitemstatusid = $result["itemstatusid"];
PH>        $taskitemlevelid = $result["itemlevelid"];
PH>        $taskshortdescription = $result["shortdescription"];
PH>        $createdbyid = $result["createdby_memberid"];
PH>        $assignedtoid = $result["assignedto_memberid"];
PH>        $completedbyid = $result["completedby_memberid"];
PH>        $taskcreateddate = $result["createddate"];
PH>        $taskassigneddate = $result["assigneddate"];
PH>        $taskestcompletiondate = $result["estcompletiondate"];
PH>        $taskcompleteddate = $result["completeddate"];
PH>        $taskprojectid = $result["projectid"];
PH>        $tasklastuserid = $result["lastuserid"];
PH>        $tasklastdate = $result["lastdate"];

PH> mysql_free_result($result);


PH> -IrishBiotch
PH> [EMAIL PROTECTED]


PH> _________________________________________________________________
PH> Join the world’s largest e-mail service with MSN Hotmail. 
PH> http://www.hotmail.com

You need to do this:

if($result = mysql_query($detailqry)){
           $row = mysq_fetch_array($result);
}
else{
     echo "Error: Failed finding task details ".mysql_error();
}

All your fields will be in the array $row. $result is just an
identifier not the actual result set.

-- 
regards,
Tom

--- End Message ---
--- Begin Message ---

If you've typed your code in accurately then...

 > $detailqry = "SELECT id, parentitemid, itemtypeid, itemstatusid, 
[etc]

 > $result = mysql_query($detailqry) or die("Failed finding 
 > task details");

somewhere in about here you want to have something like:

$sqldata = mysql_fetch_array($result);

 >        $taskid = $result["id"];
[etc]


... and if you are doing a query that will return more than one row then
you should also look at some sort of looping mechanism to step through
your result set.

CYA, Dave



--- End Message ---
--- Begin Message ---
Hi all.
 
I just saw my code laugh at me when this exploded into my face. Can
anyone tell me why isn’t this working? I just copied it from another
page made by me for the same site, changed the parameters and tested it,
but it doesn’t work here… how’s this possible?
 
****************BEGIN CODE*******************
if (is_uploaded_file($_FILES['revpic']['tmp_name'])){
copy($_FILES['revpic']['tmp_name'],
"/usr/local/www/virtual1/66/175/7/45/html/revpics");
echo "Review's picture uploaded successfully<br>";
$query = "INSERT INTO saav_reviews VALUES (NULL, '$revdate', '$revname',
'$revrev', ".$_FILES['revpic']['tmp_name'].")";
$result = mysql_query($query) or die (mysql_error());
if (!$result){
//Do Things
}
else if ($result){
//Do Things
}
}
else if (!is_uploaded_file($_FILES['revpic']['tmp_name'])){
$query = "INSERT INTO saav_reviews VALUES (NULL, '$revdate', '$revname',
'$revrev', NULL)";
$result = mysql_query($query) or die (mysql_error());
if (!$result){
//Do Things
}
else if ($result){
//Do Things
}
}
****************END CODE*******************
 
What bothers me, is that I pointed this file to my phpinfo.php and got
an empty array, so there’s no [tmp_name] anywhere… how’s that possible?
And the obvious result, is that the code pass right through to the else
if (!is_uploaded_file… instead of stopping at the if decision, and
stores  everything but the uploaded image ¿anyone?
 
Thanks in advance,
 
 <mailto:[EMAIL PROTECTED]> Cesar Aracena
On Dial-Up
CE / MCSE+I
Neuquen, Argentina
+54.299.6356688
+54.299.4466621
 
--- End Message ---
--- Begin Message ---
Hello,

I have a form field of the type "scrolling text box" it lets users input a
multiline string. I then pass this string as a variable to a php document
that prints this string to the screen:

print "$mailingAddress<br>";

however..... this outputs it all in one line.
Does anyone have an idea as to how I can print this to the screen in the
same way the user has input the info: in multiple lines?

Thanks in advance :-)


--- End Message ---
--- Begin Message ---
I am guessing you mean the input is a textarea.

At any rate, I believe what you want is nl2br()

Happy hacking.

Chris

Hans Prins wrote:

>Hello,
>
>I have a form field of the type "scrolling text box" it lets users input a
>multiline string. I then pass this string as a variable to a php document
>that prints this string to the screen:
>
>print "$mailingAddress<br>";
>
>however..... this outputs it all in one line.
>Does anyone have an idea as to how I can print this to the screen in the
>same way the user has input the info: in multiple lines?
>

--- End Message ---
--- Begin Message ---
thank you very much :-)

"Chris Shiflett" <[EMAIL PROTECTED]> schreef in bericht
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> I am guessing you mean the input is a textarea.
>
> At any rate, I believe what you want is nl2br()
>
> Happy hacking.
>
> Chris
>
> Hans Prins wrote:
>
> >Hello,
> >
> >I have a form field of the type "scrolling text box" it lets users input
a
> >multiline string. I then pass this string as a variable to a php document
> >that prints this string to the screen:
> >
> >print "$mailingAddress<br>";
> >
> >however..... this outputs it all in one line.
> >Does anyone have an idea as to how I can print this to the screen in the
> >same way the user has input the info: in multiple lines?
> >
>


--- End Message ---
--- Begin Message ---
The text field only has newlines (\n) not breaks.


For starters, in the text area tag, you need wrap="virtual":

<TEXTAREA name="mailingAddress" wrap="virtual" rows="6"
cols="40"></TEXTAREA>


Then instead of
    print "$mailingAddress<br>";
try
    print nl2br($mailingAddress)."<br>";
... which converts all new lines (\n) into breaks (<br />)


Regards,

Justin


on 10/09/02 2:21 PM, Hans Prins ([EMAIL PROTECTED]) wrote:

> Hello,
> 
> I have a form field of the type "scrolling text box" it lets users input a
> multiline string. I then pass this string as a variable to a php document
> that prints this string to the screen:
> 
> print "$mailingAddress<br>";
> 
> however..... this outputs it all in one line.
> Does anyone have an idea as to how I can print this to the screen in the
> same way the user has input the info: in multiple lines?
> 
> Thanks in advance :-)
> 
> 

--- End Message ---
--- Begin Message ---
Hi Richard

If you're using Apache I'd recommend using .htaccess files
that way there is no php needed.

AuthName "Your Directory Service - Authentication"
AuthType basic
AuthLDAP on
AuthLDAPServer ldap://ldap.yourdomain.com/
AuthLDAPBase "ou=Your Division, ou=Staff, o=Your Company, c=US"

require valid-user

If on the other hand you actually want to retrieve data from your LDAP 
system then i suggest reading the manual. it's not actually a lot harder 
that connecting to RDBMS.

I managed to get a working script straight off the manual page.
http://www.php.net/manual/en/ref.ldap.php

Joshua




Richard Whittaker wrote:
> Greetings:
> 
> We've got a Netware 6.0 server setup, and this is our network's primary means of 
>authentication of users, and I would like to use NDS (eDirectory) to authenticate 
>various web pages of ours that are written in PHP. I know that NDS interfaces with 
>LDAP, and was wondering if I could use this for my authentication... Does anyone have 
>any practical examples of authentication using LDAP/NDS?...
> 
> Any help would be appreciated!
> 
> Thanks,
> Richard W.
> 
> 

--- End Message ---
--- Begin Message ---
Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to
allocate 53738 bytes) in /var/cli/mp3anal/mp3anal.php on line 68.
Segmentation fault

This is line 68: while ($found = fscanf ($fp, "%s - - [%[A-Za-z0-9/]:%[0-9:] %[+-0-9]] 
\"%[A-Z-] %s %[A-Z0-9/.]\" %[0-9-] %[0-9-]\n",
&$ip, &$date, &$time, &$ofset, &$request, &$file, &$protocol, &$code, &$bytes)) {

Since this is a command line program, is it possible to set the memory
allocation higher? It's a program to read the mp3 lines out of an apache
log file.

This is the entire program:
http://www.cekkent.net/upload/mp3anal/mp3anal.phps

--- End Message ---
--- Begin Message ---
Villie,

Might seem a silly question, but do you have gd-2.0.1 installed in 
/usr/local/gd-2.0.1? 

Which version does phpinfo() say you're running?

What does the libphp4.so file link to? Type "ldd libphp4.so" in your 
apache/libexec folder. Perhaps you need to put the path to libgd in 
/etc/ld.so.conf?

I can confirm that RH7 with GD-1.8 RPM and custom built PHP+GD-2.0.1 does 
work. I normally install libgd in /usr/local and have /usr/local/lib as the 
first entry in /etc/ld.so.conf (From memory, I think I did this to get 
libgd working with PHP)

Tim

Ville Mattila wrote:

> Hello everyone,
> 
> I should get GD 2.0.1 installed to my PHP 4.2.2 binary running as a module
> in the Apache 1.3. The box is RedHat 7.3. There is a previous version of
> GD (1.8.4) installed as a default and it seems that I can't even get
> ereased it due to depencies. Anyway, I'd need that GD 2.0.1 due to some
> functions previous versions of GD don't have at all.
> 
> I explored the PHP manual and found this little help:
> http://www.php.net/~rasmus/gd.html. Wonderful, or not! I followed those
> items in the Rasmus' file step by step, but still without results. I tried
> to build PHP with make clean (that was only way when the configure changes
> really affected to the configure command on phpinfo() -function) and then
> all steps. But no... My PHP script is still shouting "Warning:
> imagecreatetruecolor(): requires GD 2.0 or later". Grr...
> 
> My current PHP build is configured with following string:
> './configure' '--with-mysql' '--with-apxs=/etc/httpd/bin/apxs'
> '--with-curl' '--with-gd=/usr/local/gd-2.0.1' '--with-xml' '--enable-ftp'
> '--enable-sockets' '--with-freetype-dir=/usr' '--enable-gd-native-ttf'
> '--enable-gd-imgstrttf' '--with-zlib' '--with-jpeg-dir=/usr'
> '--with-png-dir=/usr'
> 
> Well. Any ideas?
> 
> Ville


--- End Message ---
--- Begin Message ---
The only brain cells I've got awake at this moment figure out that when
copying an upload form/code the "enctype" must be copied as well...
sorry for this. I had some more trouble, but it was solved by giving the
appropriate permissions to the folder.

Thanks again, C.

> -----Original Message-----
> From: César Aracena [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, September 10, 2002 1:04 AM
> To: PHP General List
> Subject: [PHP] Brainfart while uploading
> 
> Hi all.
> 
> I just saw my code laugh at me when this exploded into my face. Can
> anyone tell me why isn’t this working? I just copied it from another
> page made by me for the same site, changed the parameters and tested
it,
> but it doesn’t work here… how’s this possible?
> 
> ****************BEGIN CODE*******************
> if (is_uploaded_file($_FILES['revpic']['tmp_name'])){
> copy($_FILES['revpic']['tmp_name'],
> "/usr/local/www/virtual1/66/175/7/45/html/revpics");
> echo "Review's picture uploaded successfully<br>";
> $query = "INSERT INTO saav_reviews VALUES (NULL, '$revdate',
'$revname',
> '$revrev', ".$_FILES['revpic']['tmp_name'].")";
> $result = mysql_query($query) or die (mysql_error());
> if (!$result){
> //Do Things
> }
> else if ($result){
> //Do Things
> }
> }
> else if (!is_uploaded_file($_FILES['revpic']['tmp_name'])){
> $query = "INSERT INTO saav_reviews VALUES (NULL, '$revdate',
'$revname',
> '$revrev', NULL)";
> $result = mysql_query($query) or die (mysql_error());
> if (!$result){
> //Do Things
> }
> else if ($result){
> //Do Things
> }
> }
> ****************END CODE*******************
> 
> What bothers me, is that I pointed this file to my phpinfo.php and got
> an empty array, so there’s no [tmp_name] anywhere… how’s that
possible?
> And the obvious result, is that the code pass right through to the
else
> if (!is_uploaded_file… instead of stopping at the if decision, and
> stores  everything but the uploaded image ¿anyone?
> 
> Thanks in advance,
> 
>  <mailto:[EMAIL PROTECTED]> Cesar Aracena
> On Dial-Up
> CE / MCSE+I
> Neuquen, Argentina
> +54.299.6356688
> +54.299.4466621
> 

--- End Message ---
--- Begin Message ---
Does anyone know of a guestbook and messageboard similiar/equiv. to the 
ones found here:  http://www.scriptarchive.com/ on the homepage.

I know there is a link to PHP on the left, but I've been searching 
around and haven't been able to find one that are similiar to the link 
above.

Thanks.

-Matt

PHP TOOLBAR (v1.5) for HomeSite v5 - http://zurnet.com/dl/hsphptb

-- 
Matt Zur
[EMAIL PROTECTED]
http://www.zurnet.com

Need a Web Site??? - Visit... www.zurnet.com

1997 - 2002 - 5th Anniversary!!!

--- End Message ---
--- Begin Message ---
I have the following code which works fine in Netscape7 but doesn't in IE5.5

$maker_name   = $_POST["maker_name"];

$loc = "show_products.php?maker_name=$maker_name&".SID;

header("Location: $loc");

The problem is that the POST variables are coming in EUC-JP (japanese) 
correctly but for some reason IE re-encodes the variable into some other 
charset (SJIS I am guessing) when requesting the new page sent in the 
Header("location: ") ...

So in Netscape I get redirected to this page:

http://192.168.254.14/show_products_html.php?&maker_name=%C5%ED&PHPSESSID=34fbfc3284514b75887c0a6a593b919c

But in IE I get this instead:

http://192.168.254.14/show_products.php?maker_name=??&;


Is this a bug in IE (of course it is ;)? Is there a work around?

Help!

Jc

--- End Message ---
--- Begin Message ---
You should always use a proper full URL in the Location header. Try that 
first.

header("Location: 
http://192.168.254.14/show_products_html.php?&maker_name=$maker_name&PHPSESSID=$PHPSESSID";);

I doubt this will solve your problem, but it is good practice anyway.

One thing that would help debug a problem like this is to try and view 
the raw HTTP, because that will lend some insight as to what character 
encoding the Web clients (IE and Netscape) are declaring. My guess is 
that the problem lies with the POST (when you receive the maker_name 
form variable), because HTTP itself has an ISO-8859-1 character encoding 
by definition, so there should be no ambiguity there. Variables that are 
posted are contained in the content of the HTTP message itself which is 
subject to interpretation based on content encoding.

Anyway, hope that lends some insight and gives you some ideas.

Happy hacking.

Chris

Jean-Christian Imbeault wrote:

> I have the following code which works fine in Netscape7 but doesn't in 
> IE5.5
>
> $maker_name   = $_POST["maker_name"];
>
> $loc = "show_products.php?maker_name=$maker_name&".SID;
>
> header("Location: $loc");
>
> The problem is that the POST variables are coming in EUC-JP (japanese) 
> correctly but for some reason IE re-encodes the variable into some 
> other charset (SJIS I am guessing) when requesting the new page sent 
> in the Header("location: ") ...
>
> So in Netscape I get redirected to this page:
>
> 
>http://192.168.254.14/show_products_html.php?&maker_name=%C5%ED&PHPSESSID=34fbfc3284514b75887c0a6a593b919c
> 
>
>
> But in IE I get this instead:
>
> http://192.168.254.14/show_products.php?maker_name=??&;
>
>
> Is this a bug in IE (of course it is ;)? Is there a work around?
>
> Help!
>
> Jc
>
>


--- End Message ---
--- Begin Message ---
I also just noticed that your first variable in the query string (which 
begins after the ? character) begins with an &, which is a separator 
character. I'm not sure what's going on there, but it should be 
something more like this:

header("Location: 
http://192.168.254.14/show_products_html.php?maker_name=$maker_name&PHPSESSID=$PHPSESSID";);
 


Happy hacking.

Chris

> Jean-Christian Imbeault wrote:
>
>> 
>http://192.168.254.14/show_products_html.php?&maker_name=%C5%ED&PHPSESSID=34fbfc3284514b75887c0a6a593b919c
> 
>
>

--- End Message ---
--- Begin Message ---
Hello,

On Tuesday, September 10, 2002 1:52 PM
Jean-Christian Imbeault wrote:

<snip>
> The problem is that the POST variables are coming in EUC-JP (japanese)
> correctly but for some reason IE re-encodes the variable into some other
> charset (SJIS I am guessing) when requesting the new page sent in the
> Header("location: ") ...
</snip>

I just wonder how do you know that the POST variable are in EUC-JP. Did you
set this in your ini? Or, did you encode your php files in EUC-JP and you
have the directive inside <meta> tags?

I think you may want to play with these settings:

  mbstring.internal_encoding
  mbstring.http_input
  mbstring.http_output
  mbstring.detect_order

Or, you can try the "Multi-Byte String Functions" (
http://jp2.php.net/manual/en/ref.mbstring.php ) to convert from one encoding
to another. Just experiment a bit... still if nothing works, perhaps, we can
try something again later...

- E

--- End Message ---
--- Begin Message ---
And by the way, please check the NOTE: on
http://jp2.php.net/manual/en/function.header.php for the use of header().
Something's missing in the way you used it--perhaps, this is causing the
problem...

- E

<quoted>
Note:  HTTP/1.1 requires an absolute URI as argument to Location:  including
the scheme, hostname and absolute path, but some clients accept relative
URIs. You can usually use $_SERVER['HTTP_HOST'], $_SERVER['PHP_SELF']  and
dirname() to make an absolute URI from a relative one yourself:

header("Location: http://".$_SERVER['HTTP_HOST']
                      .dirname($_SERVER['PHP_SELF'])
                      ."/".$relative_url);
</quoted>

On Tuesday, September 10, 2002 3:15 PM


> Hello,
>
> On Tuesday, September 10, 2002 1:52 PM
> Jean-Christian Imbeault wrote:
>
> <snip>
> > The problem is that the POST variables are coming in EUC-JP (japanese)
> > correctly but for some reason IE re-encodes the variable into some other
> > charset (SJIS I am guessing) when requesting the new page sent in the
> > Header("location: ") ...
> </snip>
>
> I just wonder how do you know that the POST variable are in EUC-JP. Did
you
> set this in your ini? Or, did you encode your php files in EUC-JP and you
> have the directive inside <meta> tags?
>
> I think you may want to play with these settings:
>
>   mbstring.internal_encoding
>   mbstring.http_input
>   mbstring.http_output
>   mbstring.detect_order
>
> Or, you can try the "Multi-Byte String Functions" (
> http://jp2.php.net/manual/en/ref.mbstring.php ) to convert from one
encoding
> to another. Just experiment a bit... still if nothing works, perhaps, we
can
> try something again later...
>
> - E
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
--- End Message ---
--- Begin Message ---
I am wanting to do a count in PHP. I want to be able to count the number of
records from a given database and display this count on the page. Can this
be done using PHP or is the sql thing?

Chuck Payne

--- End Message ---
--- Begin Message ---
it's best done in sql using "select count(*)"
but can be done in php by looping through the result set

-----Original Message-----
From: Chuck "PUP" Payne [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, September 10, 2002 2:58 PM
To: PHP General
Subject: [PHP] Count in PHP


I am wanting to do a count in PHP. I want to be able to count the number of
records from a given database and display this count on the page. Can this
be done using PHP or is the sql thing?

Chuck Payne


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--- End Message ---
--- Begin Message ---
$sql = mysql_query("SELECT * FROM table ORDER BY whatever");
echo(mysql_num_rows($sql));

that should do it.

tyler

On Tue, 10 Sep 2002 00:58:26 -0400
"Chuck \"PUP\" Payne" <[EMAIL PROTECTED]> wrote:

> I am wanting to do a count in PHP. I want to be able to count the
> number of records from a given database and display this count on the
> page. Can this be done using PHP or is the sql thing?
> 
> Chuck Payne
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
--- End Message ---
--- Begin Message ---
> I am wanting to do a count in PHP. I want to be able to count the number
of
> records from a given database and display this count on the page. Can this
> be done using PHP or is the sql thing?

If you're using MySQL - I don't know if COUNT() is a part of SQL'92 - you
can use SELECT COUNT(*) FROM table like this:

<?
echo mysql_result(mysql_query("SELECT COUNT(*) FROM table"),0,0);
?>

The two zeros at the end means that mysql_result is to fetch the first row,
the first column of the result.

(Also, it'll be much faster than mysql_num_rows(mysql_query("SELECT * FROM
table"))

   Jome


--- End Message ---
--- Begin Message ---
why not:
"select count(*) as counter from table"

----- Original Message ----- 
From: "Tyler Longren" <[EMAIL PROTECTED]>
To: "Chuck "PUP" Payne" <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Tuesday, September 10, 2002 1:02 PM
Subject: Re: [PHP] Count in PHP


> $sql = mysql_query("SELECT * FROM table ORDER BY whatever");
> echo(mysql_num_rows($sql));
> 
> that should do it.
> 
> tyler
> 
> On Tue, 10 Sep 2002 00:58:26 -0400
> "Chuck \"PUP\" Payne" <[EMAIL PROTECTED]> wrote:
> 
> > I am wanting to do a count in PHP. I want to be able to count the
> > number of records from a given database and display this count on the
> > page. Can this be done using PHP or is the sql thing?
> > 
> > Chuck Payne
> > 
> > 
> > -- 
> > 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 want to change the default session name 'PHPSESSID'  to say ex. 'seid'.

How can I do this without editing to the php.ini since I'm having a site on
a virtual host.

Thanx for help in advance ...

Mohd Q.
--- End Message ---
--- Begin Message ---
> I want to change the default session name 'PHPSESSID'  to say ex. 'seid'.
>
> How can I do this without editing to the php.ini since I'm having a site
on
> a virtual host.

Try putting this at the start of your scripts:
ini_set ('session.name', 'seid');

Luke Welling.
--
PHP and MySQL Web Development
by Luke Welling and Laura Thomson
http://www.amazon.com/exec/obidos/ASIN/0672317842/tangledwebdesign



--- End Message ---
--- Begin Message ---
Mohd_q wrote:
> I want to change the default session name 'PHPSESSID'  to say ex.
> 'seid'.
>
> How can I do this without editing to the php.ini since I'm having a
> site on a virtual host.

http://www.php.net/session_name

HTH Erwin


--- End Message ---
--- Begin Message ---
> On the PHP Bug board, I managed to find that it was to do with the
> Apache configuration settings, namely, you should put
>
>   AddType application/x-httpd-php .php .php3
>
> instead of;
>
> <FilesMatch "\.php$">
>   SetOutputFilter PHP
> </FilesMatch>
>
> in the httpd.conf file.
>
> This took ages to find and was only posted within that last few days
> on the PHP bug board, hope it helps you with your elusive first POST
> variable.

Whow, thanks man. It works like a webserver should work. All my problems are
gone, even the huge POST problem I've had (bug #19263).

Grtz Erwin


--- End Message ---
--- Begin Message ---
Hello,
after a little break ( i really needed it ;P), i tried to get this thing
wotkig again.
I changed action to .$PHP_SELF. and i added the echo to test if it works:
echo $_POST['test'];
But still emtpy, what do i do wrong?

<?php

echo ' <form name="test" action="'.$PHP_SELF.'" method="POST"><br>

 <select id="colorPicker"
onChange="changeColor(this.options[this.selectedIndex].value)">
  <option>Background Color
  <option value="0000FF">Blue
  <option value="FF0000">Red
  <option value="00FF00">Green
  <option value="000000">Black
 </select>

  <input type="submit" value="Click To View Submission">

</form>
';

echo $_POST['test'];

?>
</body>
</html>

> From: Jay Blanchard [mailto:[EMAIL PROTECTED]]
>
>
> [snip]
> > Did you put a closing form tag? </form>
> you are right, the closeing tag was missing, well, it still doesnt
> work/stays emty ;/
> [/snip]
>
> Does this form refer to itself, or another page? Also, like
> Justin said,
> echo the variable before writing to a directory to see what is getting
> written, if anything.
>
> Jay
>
>
>

--- End Message ---
--- Begin Message ---
u   cannot   use   form's  name   as   variable .....
u   should   replace   this   row   ....

<select id="colorPicker"

like  this

<select name="test" id="colorPicker"

u  can   see   the  selected  option's   value ....



--- End Message ---
--- Begin Message ---
Hi All,

I suspect this is a commonly asked question but; how do I generate a CSV
files on the fly and get the browser to download it.

Do I actually need to generate a file or can I just generate a variable
contain the data that would be in the file?

Any help is greatly appreciated.

TIA

Henry


--- End Message ---
--- Begin Message ---
Try this:

<?php
$fileextension="csv";
$filename="report";
$fnsave = "$filename.$fileextension";

header("Content-disposition: filename=$fnsave");
header("Content-type: application/force-download");

// generate your CSV content here and print them to the browser via ECHO
echo 'a,b,c,d,1';
//.........................

?>

Elias

"Henry" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> Hi All,
>
> I suspect this is a commonly asked question but; how do I generate a CSV
> files on the fly and get the browser to download it.
>
> Do I actually need to generate a file or can I just generate a variable
> contain the data that would be in the file?
>
> Any help is greatly appreciated.
>
> TIA
>
> Henry
>
>


--- End Message ---
--- Begin Message ---
It didn'ti work ;-(

Just showed a page with the data in!

How would I do it with a file in any case?

Henry

"Lallous" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> Try this:
>
> <?php
> $fileextension="csv";
> $filename="report";
> $fnsave = "$filename.$fileextension";
>
> header("Content-disposition: filename=$fnsave");
> header("Content-type: application/force-download");
>
> // generate your CSV content here and print them to the browser via ECHO
> echo 'a,b,c,d,1';
> //.........................
>
> ?>
>
> Elias
>
> "Henry" <[EMAIL PROTECTED]> wrote in message
> [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> > Hi All,
> >
> > I suspect this is a commonly asked question but; how do I generate a CSV
> > files on the fly and get the browser to download it.
> >
> > Do I actually need to generate a file or can I just generate a variable
> > contain the data that would be in the file?
> >
> > Any help is greatly appreciated.
> >
> > TIA
> >
> > Henry
> >
> >
>
>


--- End Message ---
--- Begin Message ---
try making the generated csv file an attachment to the php file...  like
so...

<?php
$fileextension="csv";
$filename="report";
$fnsave = "$filename.$fileextension";

header("Content-type: application/force-download");
header("Content-disposition: attachment; filename=$fnsave");

echo '1,2,3,4,5,6,7,8';
?>

usually works for me.

incidentally, what browser version are you using?  on what os?

dave


-----Original Message-----
From: Henry [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, September 10, 2002 2:43 AM
To: [EMAIL PROTECTED]
Subject: [PHP] Re: Generating CSV files on the fly and getting the
browser to download


It didn'ti work ;-(

Just showed a page with the data in!

How would I do it with a file in any case?

Henry

"Lallous" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> Try this:
>
> <?php
> $fileextension="csv";
> $filename="report";
> $fnsave = "$filename.$fileextension";
>
> header("Content-disposition: filename=$fnsave");
> header("Content-type: application/force-download");
>
> // generate your CSV content here and print them to the browser via ECHO
> echo 'a,b,c,d,1';
> //.........................
>
> ?>
>
> Elias
>
> "Henry" <[EMAIL PROTECTED]> wrote in message
> [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> > Hi All,
> >
> > I suspect this is a commonly asked question but; how do I generate a CSV
> > files on the fly and get the browser to download it.
> >
> > Do I actually need to generate a file or can I just generate a variable
> > contain the data that would be in the file?
> >
> > Any help is greatly appreciated.
> >
> > TIA
> >
> > Henry
> >
> >
>
>



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

--- End Message ---
--- Begin Message ---
Henry wrote:
> It didn'ti work ;-(
>
> Just showed a page with the data in!
>
> How would I do it with a file in any case?
>

You can give the PHP script the extension .csv and use AddType
application/x-httpd-php .csv to your httpd.conf or .htaccess file.

If you want to use a temporary file, you should use something like

$string = 'a, b, c, d, e, f';
$fp = fopen( 'tempfile.csv', 'w' );
fwrite( $fp, $string );
fclose( $fp );

After file creation you should redirect the user to the .csv file.
The problem here is that you cannot delete the temporary file afterwards.

My first option is the one I'm using myself. You can't put all your faith in
header("Content-disposition: filename=$fnsave");
because most browsers won't understand it (and ignore it). If you give your
php file the .csv extension, then no browser can ignore it. They think it's
a normal .csv file, which should be opened with (for instance) Excel...

HTH
Erwin


--- End Message ---
--- Begin Message ---
Hi Everyone, specially DPHPEdit users!

There is a new version of DPHPEdit - 0.9.4.2, which brings:

- Highlighting method for current file can be manually changed in edit
session
- Custom highlighting support with Keywords and Functions editor
- PHP Highlighter now recognizes different code segments in same file (must
be closed properly)
- Custom Syntax Coloring added! See "Options->PHP/HTML Syntax Coloring"
- Project Tree is sorted after the project is loaded
- Updated help file (HTML)

Please check home page (http://www.pleskina.com/dphped) for program and
manual changes,
or download directly from http://www.pleskina.com/downloads/DPHPedit.zip

Regards,

--
Davor Pleskina
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[EMAIL PROTECTED]  http://www.pleskina.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[EMAIL PROTECTED]; [EMAIL PROTECTED]
ICQ#: 38632789

Programmers don't die;
they just GOSUB without RETURN...




--- End Message ---
--- Begin Message ---
Hi,
I have some troubles with PhpMyAdmin and PHP4.2.*
I experimented these couples of installations:
PhpMyAdmin / PHP
2.2.6 / 4.1.2
2.2.7pl1 / 4.1.2
2.3.0 / 4.1.2
2.2.6 / 4.2.1
2.2.7pl1 / 4.2.1
2.3.0 / 4.2.1
2.2.6 / 4.2.3
2.2.7pl1 / 4.2.3
2.3.0 / 4.2.3
with MySQL v3.23.49 on RedHat7.2

PhpMyAdmin works perfectly with PHP 4.1.2 but
with 4.2.* one http request took more than 10 seconds
and the linux box performed a lot of disk I/Os.

PHP MySQL extension seems to be changed since v4.2.0
Where is the problem?
I want to move to 4.2.3 :(

Jean-Pierre



___________________________________________________________
Do You Yahoo!? -- Une adresse @yahoo.fr gratuite et en français !
Yahoo! Mail : http://fr.mail.yahoo.com
--- End Message ---
--- Begin Message ---
Hi Everyone,

I did a simple test with this script:

<?php
mail("[EMAIL PROTECTED]", "test", "this is a test mail");
echo "done";
?>

I run the script from web accounts on different servers. I can receive the
test mail from some but not from others. Is there any configurations that I
am missing here?
Thanks and regards.

--
Alva Chew
Stridec Systems
mobile: +65 9144-8023
email: [EMAIL PROTECTED]
website: www.stridec.com


--- End Message ---
--- Begin Message ---
At 9/10/2002, you wrote:
>Hi Everyone,
>
>I did a simple test with this script:
>
><?php
>mail("[EMAIL PROTECTED]", "test", "this is a test mail");
>echo "done";
>?>
>
>I run the script from web accounts on different servers. I can receive the
>test mail from some but not from others. Is there any configurations that I
>am missing here?

My guesses:

Many mail servers are configured so that they send mail only if the sender 
receives mail at the same time. One other possible pitfall is that reverse 
IP lookup is not working correctly and your server rejects the mail as it 
cannot verify the sender host. Also, many (well configured) servers do not 
send when there is no live account for that sender.


-------------------------
Pekka Saarinen
http://photography-on-the.net
-------------------------


--- End Message ---
--- Begin Message ---
http://electroteque.dyndns.org:1023/demo/uploader/

following my other posts i have a working flash progress bar , although i
cannot remove the empty arrays in the count how can i remove empty arrays in
an array , the empty file inputs seem to still contain something , so
instead of 1 as the count if you upload only one file , its still 5 for 5
file input fields

"Jed Verity" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> You're right about it costing more money. But we had one server handling a
> bunch of uploads, most of them over 25 MB, and 99% being instigated by
very
> impatient, not very technical, people. People who kept canceling and
> canceling, despite our directions, because they thought it was stuck or
> frozen or taking too long. It was worth $150 for us to buy the ASP
component
> (I think we used ABCUpload, maybe?). The development time required for a
> creative PHP solution -- and one that might not have worked as well --
would
> have been dramatically more expensive than the almost out-of-the-box
> solution with ASP's components. (And much of the site was already written
in
> ASP.)
>
> Other than that, you'll get know argument from me about ASP vs. PHP. I'm
> head over heels for PHP and, in any context other than the one stated
above
> (and maybe one or two others), I would choose to use God Blessed PHP over
> anything else.
>
> Cheers!
> Jed
>
> P.S. I knew I'd get some fighters with that comment. Haven't learned my
> lesson yet... ;-)
>
> On the threshold of genius, Jay Blanchard wrote:
>
> > [snip]
> > There really isn't a great solution for this, that I know of. It's one
of
> > the few things that makes an argument for ASP over PHP, as far as I'm
> > concerned (if you have the luxury of choosing). Below is what I did once
to
> > try to get around the problem. It worked *okay*.
> > [/snip]
> >
> > How does this argue for ASP over PHP? I don't see how. File upload on
PHP is
> > built in and therefore free. ASP file upload mechs cost more money. And,
> > having used ASP for a while, and having looked for this feature, no
upload
> > progress bar exists there either. And PHP is a language, where ASP is a
> > service ... please do not confuse the two. If you want to argue VBScript
vs.
> > PHP , well ,come on ... let's go. :^] PHP can beat VBScript with one
> > curly-brace tied behind its back.
> >
> > I mentioned a while back, when this came up before (see the archives)
that
> > this could probably be done with an IFRAME in the upload dialog box. Now
I
> > haven't given this much thought, but maybe it could be done. The largest
> > problem that I see is the communication back and forth between client
and
> > server. The server would have to know the original size of the file at
the
> > point the upload is started, then it would be checked for original_size
> > minus bits_uploaded, flush the reults to the IFRAME drawing a GD graph,
and
> > continue to do this as it went on.
> >
> > Another method is to start the upload with a non-progressive animation
that
> > quits when is_upload_file() returns true.
> >
> > Jay
> >
> >
>


--- End Message ---
--- Begin Message ---
if you can't use [] for the checkbox, the only way out is to have unique 
name for each checkbox.

otherwise, php will always be returning the value of the last checked 
checkbox if all checkboxes share the same name without the [].

--lance

Alex Shi wrote:
> How to ontain data from a group of checkbox using same name?
> For example, in a form there're 6 checkboxes and all named as
> "Interesting_Area". I know if put a pairs of square brackets at the
> end of the name then in php all the values of them can be ontained.
> However, for some reason I cannot use square brackets. Please
> help me out if anyone know how to do the trick. THanks!
> 
> Alex
> 
> 

--- End Message ---
--- Begin Message ---
This will work:
                          http://www.php.net/array_merge

Call your checkboxes like so:

a.php
==========================================
 <form action="b.php" method="post">
     <input type="checkbox" name="a1" value="A"><br>
     <input type="checkbox" name="a2" value="B"><br>
     <input type="checkbox" name="a3" value="C"><br>
     <input type="checkbox" name="a4" value="D"><br>
     <input type="checkbox" name="a5" value="E"><br>
     <input type="checkbox" name="a6" value="F"><br>
     <input type="submit" name="submit" value="SUBMIT">
</form>
==========================================

then post it to the desired page and do something like this:

b.php
==========================================
<?php

    $foo =
array_merge($_POST['a1'],$_POST['a2'],$_POST['a3'],$_POST['a4'],$_POST['a5']
,$_POST['a6']);

 echo $foo; // Returns an array

 echo "<pre>";
 print_r($foo);  // Look whats in the array
 echo "</pre>";
?>
==========================================


Best of luck,

Craig




"B.C. Lance" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> if you can't use [] for the checkbox, the only way out is to have unique
> name for each checkbox.
>
> otherwise, php will always be returning the value of the last checked
> checkbox if all checkboxes share the same name without the [].
>
> --lance
>
> Alex Shi wrote:
> > How to ontain data from a group of checkbox using same name?
> > For example, in a form there're 6 checkboxes and all named as
> > "Interesting_Area". I know if put a pairs of square brackets at the
> > end of the name then in php all the values of them can be ontained.
> > However, for some reason I cannot use square brackets. Please
> > help me out if anyone know how to do the trick. THanks!
> >
> > Alex
> >
> >
>


--- End Message ---
--- Begin Message ---
This query worked until I tried to add support for a table prefix in the
config file. Now it can¹t seem to find the table. Any pointers to what I am
doing wrong?

Thanks, v

Original query:
<?php
...
    include("config.php");

        $open = mysql_pconnect($hostname,$user,$password);
        mysql_select_db("$db",$open);
        $result = mysql("$db","SELECT * FROM teams WHERE username =
'admin'");
        $i = 0;
    $total_rows = mysql_numrows($result);

...
?>

This is my query:
<?php
...
    include("config.php");

        $open = mysql_pconnect($hostname,$user,$password);
        mysql_select_db("$db",$open);
        $result = mysql("$db","SELECT * FROM  " . $table_prefix . " teams
WHERE username = 'admin'");
        $i = 0;
    $total_rows = mysql_numrows($result);

...
?>

This is my config file:
<?php

        $db = "sports";
        $hostname = "localhost";
        $password = "mypassword";
        $user = "myuser";
        $table_prefix = "ccl_";

?>

This is my table name:
ccl_teams

This is the error:
Warning: Supplied argument is not a valid MySQL result resource in...
--- End Message ---
--- Begin Message ---
[snip]
This is my query:
<?php
...
    include("config.php");

        $open = mysql_pconnect($hostname,$user,$password);
        mysql_select_db("$db",$open);
        $result = mysql("$db","SELECT * FROM  " . $table_prefix . " teams
WHERE username = 'admin'");
        $i = 0;
    $total_rows = mysql_numrows($result);

...
?>

This is my config file:
<?php

        $db = "sports";
        $hostname = "localhost";
        $password = "mypassword";
        $user = "myuser";
        $table_prefix = "ccl_";

?>

This is my table name:
ccl_teams
[/snip]

You're query reads like this now

"SELECT * FROM  ccl_ teams WHERE username = 'admin'

You need to concatenate the variable with the text (remove the space);

"SELECT * FROM  " . $table_prefix . "teams WHERE username = 'admin'

Here is a useful troubleshooting method; if the query returns an error,
print it out. You can generally find errors quite easily.

HTH!

Jay

Guys have feelings too. But, like…who cares?

*****************************************************
* Texas PHP Developers Conf  Spring 2003            *
* T Bar M Resort & Conference Center                *
* New Braunfels, Texas                              *
* Contact [EMAIL PROTECTED]       *
*                                                   *
* Want to present a paper or workshop? Contact now! *
*****************************************************


--- End Message ---
--- Begin Message ---
Maybe you should assign the query to is's own value doing your string 
concatenation...

i.e.
$query = "select * ...";

then echo out the query:
echo $query;

I think you will see the problem them, I would guess that when you are adding 
the table_prefix to the table name that you are getting an extra space in 
there...
So, try that out, and see if it helps
-Brad

> This query worked until I tried to add support for a table prefix in the
> config file. Now it can¹t seem to find the table. Any pointers to what I am
> doing wrong?
> 
> Thanks, v
> 
> Original query:
> <?php
> ....
>     include("config.php");
> 
>         $open = mysql_pconnect($hostname,$user,$password);
>         mysql_select_db("$db",$open);
>         $result = mysql("$db","SELECT * FROM teams WHERE username =
> 'admin'");
>         $i = 0;
>     $total_rows = mysql_numrows($result);
> 
> ....
> ?>
> 
> This is my query:
> <?php
> ....
>     include("config.php");
> 
>         $open = mysql_pconnect($hostname,$user,$password);
>         mysql_select_db("$db",$open);
>         $result = mysql("$db","SELECT * FROM  " . $table_prefix . " teams
> WHERE username = 'admin'");
>         $i = 0;
>     $total_rows = mysql_numrows($result);
> 
> ....
> ?>
> 
> This is my config file:
> <?php
> 
>         $db = "sports";
>         $hostname = "localhost";
>         $password = "mypassword";
>         $user = "myuser";
>         $table_prefix = "ccl_";
> 
> ?>
> 
> This is my table name:
> ccl_teams
> 
> This is the error:
> Warning: Supplied argument is not a valid MySQL result resource in...
> 





--- End Message ---
--- Begin Message ---

I would like to write a script that would populate someone else's form on
the net and get the results.

Off hand, I imagine I would use fopen() to open up the web page and pass
some variables to it.  The problem I have is that the form I want to
populate is a multi-step CGI.  Is this possible?  How do I continue to pass
variables to a second or third step, sending variables passed on what the
form says to do next (which is predictable)?

This is considering I do not have the cooperation of the web site I am
trying to fill out the form for step by step, and I would like to write this
so it is done in a behind-the-scenes, automated way.

For example:  A customer registered with me could ask for a product.  My
'agent' would go to the site where the product is sold, login, submit all of
the appropriate information for purchase and shipment, and then come back
with (hopefully) a success message (along with any pertinent information
from the purchase).

Anyone have any ideas, suggestions, or can point me in the right direction?

Thanks,

-Mike


--- End Message ---
--- Begin Message ---
Doh,... Thanks to all who replied so promptly with similar answers.

:) vern


On 9/10/02 9:13 AM, "Jacob Miller" <[EMAIL PROTECTED]> wrote:

> Make sure you don't have a space before the 2nd half of the table name
> 
> Wrong:
> 
> .. "FROM " . $table_prefix . " teams"
> 
> this will produce "FROM ccl_ teams"
> 
> Right:
> 
> .. "FROM " . $table_prefix . "teams"
> 
> this will product "FROM cc_teams"
> 
> - jacob

--- End Message ---
--- Begin Message ---
Could someone show me a quick and simple way to randomly sort array
elements?  I can't seem to pinpoint the correct parameters in the docs.

Thanks!
--- End Message ---
--- Begin Message ---

You could use array_rand() to take stuff out of the array at random and then
stuff it all back into another array.

-Mike



> -----Original Message-----
> From: ROBERT MCPEAK [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, September 10, 2002 10:22 AM
> To: [EMAIL PROTECTED]
> Subject: [PHP] random array sort
>
>
> Could someone show me a quick and simple way to randomly sort array
> elements?  I can't seem to pinpoint the correct parameters in the docs.
>
> Thanks!
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


--- End Message ---
--- Begin Message ---
But if array_rand() truly pulls out random keys, how do you guarantee 
that you are not randomly pulling out the same key as you iterate 
through the array?

Perhaps you could set the number of keys to return, to the size of the 
array, and somehow, magically, all the keys would be included in the 
returned array of keys.
i.e. array_rand ( array , array_size)
I have no idea what this would produce...
-David

On Tuesday, September 10, 2002, at 10:33 AM, Mike At Spy wrote:

>
> You could use array_rand() to take stuff out of the array at random and 
> then
> stuff it all back into another array.
>
> -Mike
>
>
>
>> -----Original Message-----
>> From: ROBERT MCPEAK [mailto:[EMAIL PROTECTED]]
>> Sent: Tuesday, September 10, 2002 10:22 AM
>> To: [EMAIL PROTECTED]
>> Subject: [PHP] random array sort
>>
>>
>> Could someone show me a quick and simple way to randomly sort array
>> elements?  I can't seem to pinpoint the correct parameters in the docs.
>>
>> Thanks!
>>
>> --
>> 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 ---

>From what I understand about array_rand() and the example in the manual, it
does only pull one of each element of the array.  You could easily set up a
script to compare what it is pulling to what the array you putting it into
currently has in it if it didn't.

-Mike



> -----Original Message-----
> From: David Rice [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, September 10, 2002 10:49 AM
> To: [EMAIL PROTECTED]
> Subject: Re: [PHP] random array sort
>
>
> But if array_rand() truly pulls out random keys, how do you guarantee
> that you are not randomly pulling out the same key as you iterate
> through the array?
>
> Perhaps you could set the number of keys to return, to the size of the
> array, and somehow, magically, all the keys would be included in the
> returned array of keys.
> i.e. array_rand ( array , array_size)
> I have no idea what this would produce...
> -David
>
> On Tuesday, September 10, 2002, at 10:33 AM, Mike At Spy wrote:
>
> >
> > You could use array_rand() to take stuff out of the array at random and
> > then
> > stuff it all back into another array.
> >
> > -Mike
> >
> >
> >
> >> -----Original Message-----
> >> From: ROBERT MCPEAK [mailto:[EMAIL PROTECTED]]
> >> Sent: Tuesday, September 10, 2002 10:22 AM
> >> To: [EMAIL PROTECTED]
> >> Subject: [PHP] random array sort
> >>
> >>
> >> Could someone show me a quick and simple way to randomly sort array
> >> elements?  I can't seem to pinpoint the correct parameters in the docs.
> >>
> >> Thanks!
> >>
> >> --
> >> 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
> >
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>


--- End Message ---
--- Begin Message ---
This appears to work

// Normal array
$a1 = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);

srand((float) microtime() * 10000000);
$a_temp = array_rand($a1, sizeof($a1));

// Random array
while (list(, $value) = each($a_temp)) {
         $a2[] = $a1[$value];
}

print_r($a2);

- jacob

At 22:22 09/10/2002, you wrote:
>Could someone show me a quick and simple way to randomly sort array
>elements?  I can't seem to pinpoint the correct parameters in the docs.
>
>Thanks!
>
>--
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, visit: http://www.php.net/unsub.php

--- End Message ---
--- Begin Message ---
I'm working on a project for a javascript class, but am having trouble with
passing variables.  Unfortunately, I can't do this with PHP (that would be
too easy), but I have to use Javascript to do some calculations and output
based on input from a form on a previous page.  I am trying to understand
what all I would need to access the variables from page one:

index.html --> summary.html --> payment.html --> thankyou.html
Order Form     Order Summary      CC info            Thank You/Confirmation
(I understand that these will become .PHP pages when I incl the PHP code)

The Order Form page collects 7 variables:
$state, $Widget1, $Widget2, $Widget3, $Widget4, $Widget5, $Widget6

The Summary page needs to do some calculations, but I can't access the
variables ("variable undefined..." errors) with JavaScript:
$cost1 = $Widget1 * 10.00
$cost2 = $Widget2 * 20.00
etc...
$subTotal = ($cost1 + $cost2 + etc...)
$shipping = ($Widget1 + $Widget2...etc) * 0.1   // fixed 10% charge
$tax = $subTotal * 0.08
$total = $subTotal + $shipping + $tax

What I am *trying* to do, for lack of a better idea, is on the Summary page:

<?PHP
     import_request_variables("P");
?>

>From here, I'm not sure what to do.  Do I need to print an array?  Should
this be done in the <HEAD> of the page?  Can anyone offer any suggestions
here???

THANX for any/all assistance!

Wm



--- End Message ---
--- Begin Message ---
Just wondering what the best way to validate an entered phone format is? Is
anyone doing this currently?

I have a form field that people enter in information and I want to force
phone entries to XXX-XXX-XXXX.

Jeff

--- End Message ---
--- Begin Message ---
Thanks all for you submissions.  This is what I came up with, where
$this_key is a random selection from the array $the_exploded_ids.  I
don't know why, but,  array_rand() won't work with selection quanity
parameter of less than 2.  Anybody know why?

srand ((float) microtime() * 10000000);
$input = $the_exploded_ids;
$rand_keys = array_rand ($the_exploded_ids, 2);
$this_key=$input[$rand_keys[0]];



$this_key=trim($this_key);

>>> "ROBERT MCPEAK" <[EMAIL PROTECTED]> 09/10/02 10:22AM >>>
Could someone show me a quick and simple way to randomly sort array
elements?  I can't seem to pinpoint the correct parameters in the
docs.

Thanks!

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

--- End Message ---

Reply via email to