Re: [PHP] Simplifying MySql queries

2011-02-14 Thread Simcha Younger
On Sat, 12 Feb 2011 22:40:27 +0200
Andre Polykanine an...@oire.org wrote:

 Hi all,
 I'm using in my PHP script the following four MySql queries:
 $q1=mysql_query(SELECT *FROM`CandidateQuestions`WHERE
 `Category`='1' ORDER BY RAND() LIMIT 1);
 $q2=mysql_query(SELECT *FROM`CandidateQuestions`WHERE
 `Category`='2' ORDER BY RAND() LIMIT 1);
 $q3=mysql_query(SELECT *FROM`CandidateQuestions`WHERE
 `Category`='3' ORDER BY RAND() LIMIT 1);
 $q4=mysql_query(SELECT *FROM`CandidateQuestions`WHERE
 `Category`='4' ORDER BY RAND() LIMIT 1);
 
 and  here  goes the question: is there a way to make these four in one
 so  strictly  one  random  question  is  selected from all of the four
 categories?
 Thanks!

select * from (select * from `CandidateQuestions` order by rand() ) t group by 
`Category`;


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


-- 
Simcha Younger sim...@syounger.com

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



Re: [PHP] Problem with Include

2010-12-19 Thread Simcha Younger
On Sun, 19 Dec 2010 17:41:20 +
a...@ashleysheridan.co.uk a...@ashleysheridan.co.uk wrote:

 Is your server even set up to recognise .inc files as php? You can't just put 
 any old extension on and expect the server to know what to do with it.
 
 Thanks,
 Ash
 http://www.ashleysheridan.co.uk

Since it is being included by PHP, and not served by Apache, the extension is 
not important.


-- 
Simcha Younger sim...@syounger.com

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



Re: [PHP] MySQL Query Help

2010-11-20 Thread Simcha Younger
On Sat, 20 Nov 2010 13:54:29 -0700
Ben Miller biprel...@gmail.com wrote:

 Hi,
 
 I'm building a website for a client in which I need to compare their
 products, side-by-side, but only include criteria for which all selected
 products have a value for that criteria.
 
 In my database (MySQL), I have a tables named products,criteria and
 criteria_values
 
 If I have something like
 
 $selected_product = array(1=Product 1,2=Product 2...)  //  All
 products selected for comparison by the user
 
 I need to get only rows from criteria where there is a row in
 criteria_values matching criteria.criteria_id for each $selected_product
 - in other words, if any of the $selected_product does not have a row in
 criteria_values that matches criteria.criteria_id, that criteria would
 not be returned.  I hope that makes sense.

It would be a lot easier to think about this if you could provide the table 
structure or create table statements.

If I understood correctly, you have products which reference a criteria ID 
which has no matching value. If this is the problem you have a to first take 
care of the integrity of your data, as this should never happen. 


-- 
Simcha Younger sim...@syounger.com

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



Re: [PHP] Character encoding hell

2010-10-26 Thread Simcha Younger
On Tue, 26 Oct 2010 11:56:17 -0400
Marc Guay marc.g...@gmail.com wrote:

 
 I have a directory with a bunch of PDFs in it that my webpage displays
 links to.  All of the files have the french character  in them. The
 operating system is Linux (I did not experience this problem on a
 Windows machine). I don't want to type the display name of these files
 twice and the website has no database capability 

If you are not constantly adding/changing the files there, you can use a csv 
file in place of a database.


-- 
Simcha Younger sim...@syounger.com

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



Re: [PHP] Auto-generating HTML

2010-09-21 Thread Simcha Younger
On Sep 20, 2010, at 2:56 PM, Andy McKenzie wrote:

 
 Hey folks,
 
  Here's the problem.  I'm writing a lot of pages, and I hate going in
 and out of PHP.  At the same time, I want my HTML to be legible.  When
 you look at it, that's kind of a problem, though... for instance
 (assume this had some PHP in the middle, and there was actually a
 reason not to just put this in HTML in the first place):

Unless you are looking at the HTML alot, you can just paste the source into an 
editor which can auto-format the code, or look at the code in firebug (that is 
the usual place where I look at my HTML.)

If there is a specific place you want to look at in the html, just change the 
lines there to look like this:
echo 'html
';
but this will make your PHP quite messy if you do it alot.

I would go with templating, as many here suggested. 

-- 
Simcha Younger simcha.youn...@gmail.com

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



Re: [PHP] MySQL select matching

2010-07-21 Thread Simcha Younger
On Mon, 19 Jul 2010 10:36:40 -0600
Ashley M. Kirchner ash...@pcraft.com wrote:


 mysql select * from table where id='1';
 +---+-+-+---+
 | 1 | 123 | 0.0 | C |
 | 1 | 234 | 0.1 | D |
 | 1 | 345 | 0.0 | D |
 | 1 | 456 | 0.1 | C |
 | 1 | 567 | 0.1 | G |
 +---+-+-+---+
 
  Now, I have to find other IDs that match the above result.  In the 
 table, that would be ID '3' (and in the entire DB, there may be 
 others as well - I need to find all those IDs.)  But, notice how ID 0003 
 isn't in the same order as ID 1, but the data is still the same.
 
select distinct id from `table` where concat(`b`, `c`, `d`) in (select 
concat(`b`,`c`,`d` from `table` where id = '0001') AND id != '0001';
(untested)

-- 
Simcha Younger sim...@syounger.com

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



Re: [PHP] functions and global variables

2010-07-19 Thread Simcha Younger




On Mon, 19 Jul 2010 13:37:12 +0530
Shreyas Agasthya shreya...@gmail.com wrote:

 My two cents on this one.
 
 Modify the $name within the function and print it.
 
 Modify the$name outside the function (means the non-global-declared $name)
 and print it. You will know the difference.
 
 --Shreyas
 
 On Mon, Jul 19, 2010 at 7:41 AM, Paul M Foster pa...@quillandmouse.comwrote:
 
  On Sun, Jul 18, 2010 at 06:37:30PM -0400, David Mehler wrote:
 
   Hello,
   I've got a file with a variable declared in it. For purposes of this
  post:
  
   $name = $_POST['name'];

  
   I'm wondering do I have to have $name declared as a global variable
   within that function? For example:
  
   function customFunction() {
   global $name
   }
  
   I've tried it both ways and both ways it works, with and without the
   global statement. I was under the impression that to be useful in a
   function variables outside were not accessible.
   Thanks.
   Dave.



It sounds like 'register globals' is turned on in your php.ini, and therefore 
$name will be visible everywhere, since it is taken from $_POST['name'].

-- 
Simcha Younger sim...@syounger.com

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



Re: [PHP] What am I missing here?

2010-06-21 Thread Simcha Younger
On Sat, 19 Jun 2010 13:21:02 -0400
Rick Dwyer rpdw...@earthlink.net wrote:

 Hello List.
 
 I am completely at a loss for why the line of code below returns the  
 desired value:
 
 $PATH_INFO= substr($_SERVER['REQUEST_URI'],strlen($_SERVER['SCRI
 PT_NAME']), strlen($_SERVER['REQUEST_URI']));
 
 BUT, putting the same line of code on 1 line fails to return anything:
 
 $PATH_INFO=  
 substr($_SERVER['REQUEST_URI'],strlen($_SERVER['SCRIPT_NAME']),  
 strlen($_SERVER['REQUEST_URI']));
 
 
 
   --Rick
 
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 

It looks like since you broke your key in the first line, the value returned is 
0, since the key 'SRI PT_NAME' does not exist.
When you fixed this, SCRIPT_NAME was the same length as REQUEST_URI so nothing 
was returned.

look at the documentation on substr, you need to fix you parameters.
-- 
Simcha Younger sim...@syounger.com

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



Re: [PHP] Preg Match Problem

2010-06-03 Thread Simcha Younger
On Wed, 2 Jun 2010 12:14:47 -0400
Alice Wei aj...@alumni.iu.edu wrote:

 
 Hi, 
 
 I have a code snippet here as in the following:
 
 [CODE]
 $keywords = preg_split(/[\s,]+/, $day);
 $count = count($keywords);
   if(preg_match((Mon|Tue|Wed|Thu|Fri)/i, $keywords[$i])) { //line 40
$day_query =start_time.day='12345' AND end_time.day='12345';  
}  
if(preg_match(Sat/i, $keywords[$i])) { //line 43
$day_query = start_time.Sat_route != 'NULL' AND end_time.Sat_route != 
 'NULL';
}  
else {
echo $keywords[i] .  is not a term that exists in the database. Make sure 
 the pattern looks like bMon, Tue/bbr /;
footer();
exit;
}
 [/CODE]
 
 For some reason, when I type in Mon, Tue
 
 It gives me this: 
 
 Warning: preg_match() [function.preg-match]: Unknown modifier '/' in line 40
 Warning: preg_match() [function.preg-match]: Delimiter must not be 
 alphanumeric or backslash on line 43
 is not a term that exists in the database. Make sure the pattern looks like 
 Mon, Tue

You need a leading slash as a delimiter, eg
/Sat/i
also note that you will match any phrase that contains 'sun', 'mon' etc, which 
can also have irrelevant text, eg 'Mars Jupiter Saturn' will match, but thats 
probably not what you want
-- 
Simcha Younger sim...@syounger.com

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



Re: [PHP] can't retrieve more than 1 record at the time

2009-12-09 Thread Simcha Younger
On Wed, 09 Dec 2009 11:39:55 -0800
Catherine Madsen cmad...@berkeley.edu wrote:
It looks like you have to take out this line:
 $stmt = NULL; /* release the connection */
You are destroying the variable instead of just deleting the data, so the while 
statement terminates after the first record.
-- 
Simcha Younger sim...@syounger.com

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



RE: [PHP] Math problems (No not high school math!)

2008-09-25 Thread Simcha


 -Original Message-
 From: Jason Pruim [mailto:[EMAIL PROTECTED]
 Subject: [PHP] Math problems (No not high school math!)
 
 So I'm trying to figure out how to do a little math in php to add up
 the number of hours that people have worked (Still on the timecard for
 anyone following along at home)

Something like this should work:
Select SUM(timediff(`timeout`, `timein`)) where date = X;
And for a week:
Select SUM(timediff(`timeout`, `timein`)) where week(date) = week_of_year ;

(Not tested)


Simcha Younger




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



RE: [PHP] PHP tags - any reasons to close ?

2008-09-23 Thread Simcha Younger


 -Original Message-
 From: Martin Zvarík [mailto:[EMAIL PROTECTED]
 
 3) What's the reason of making an empty space after ?
 I've also seen this in some projects.
 

I often put a number of empty lines at the end of a script since I enjoy
editing with the script higher up on the screen, and very few editors allow
you to scroll the last lines of the program above the bottom of the screen.
(Crimson Editor is the only one I have found that does this.)


 
 Thanks for ideas,
 Martin
 

Simcha Younger


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



RE: [PHP] Function parameters and arrays

2008-09-18 Thread Simcha
This would be a little neater:

  foreach(func_get_arg(2) as $k = $WhereArray) {
   //echo $WhereArray[0][0];
$SQLStmt .= ' ' . $WhereArray[0] . ' ' . $WhereArray[1] . ' ' .
$WhereArray[2];
if($k != 0) $SQLStmt .=' ' . $WhereArray[3];
   };

Simcha Younger

-Original Message-
From: Frank Stanovcak [mailto:[EMAIL PROTECTED] 
Sent: Thursday, September 18, 2008 5:30 PM
To: php-general@lists.php.net
Subject: [PHP] Function parameters and arrays

I am trying to pass a multi dimmed array as a variable parameter to a custom

function to build a query for me.  Here is the basic code and what I am 
getting.

$WhereList[0][0] = 'OESalesOrder.OrderNo';
$WhereList[0][1] = '=';
$WhereList[0][2] = '2272';
$SQLString = SQLCall('OESalesOrder',$FieldList,$WhereList);

I then use a foreach in the function to process it.

$i = 0;
  foreach(func_get_arg(2) as $WhereArray) {
   echo $WhereArray[0][0];
   if($i == 0) {
$SQLStmt .= ' ' . $WhereArray[$i][0] . ' ' . $WhereArray[$i][1] . ' ' . 
$WhereArray[$i][2];
$i += 1;
   } else {
$SQLStmt .= ' ' . $WhereArray[$i][0] . ' ' . $WhereArray[$i][1] . ' ' . 
$WhereArray[$i][2] . ' ' . $WhereArray[$i][3];
$i += 1;
   };
  };

What I get when it processes is the first three letters of [0][0]
[0][0] = O
[0][1] = E
[0][2] = S

Did I do something wrong, or is this not possible?  I have done an array 
processing this way before, but not multidimmed.

Frank. 



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

No virus found in this incoming message.
Checked by AVG - http://www.avg.com 
Version: 8.0.169 / Virus Database: 270.6.21/1675 - Release Date: 17/09/2008
17:07


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



RE: [PHP] Confused

2008-09-02 Thread Simcha
This does not seem to be an installation problem -

Your test [(!$connect_id = ] fails, since the connect returns false, so it
does not run the condition.

Compare:
?php

if($a = false){echo no good;}else{echo condition true;}

?



-Original Message-
From: Dan Shirah [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, September 02, 2008 7:31 PM
To: PHP List
Subject: [PHP] Confused

All,

Okay, I am a bit confused.   I'm setting up another server to host PHP
pages.  I followed everything in the Manual for installing PHP.  I'm running
Windows Server 2003, IIS6.0 and PHP 5.2.6.

And...it kind of works...

If I do: ?php echo Test; ? it prints fine.
If I do: Today is: ?php echo date(l, F j, Y); ? it prints fine.

If I do: You are recognized as: ?php echo substr($_SERVER['AUTH_USER'],
13); ? I get no output.
If I do:
 if (!$connect_id = ifx_connect([EMAIL PROTECTED], $user, $pass)) { //
THE ACTUAL CONNECTION
 echo Unable to connect to Informix Database\n; // DISPLAY IF
CONNECTION FAILS
 exit();
  }

I don't get a connection to the database and the Unable to connect to
Informix Database\n; does not even display.

I get no errors output to the screen and I have display_errors = On
And I have error_reporting = E_ALL  ~E_NOTICE

Any ideas?

No virus found in this incoming message.
Checked by AVG - http://www.avg.com 
Version: 8.0.169 / Virus Database: 270.6.14/1646 - Release Date: 02/09/2008
06:02


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



RE: [PHP] Confused

2008-09-02 Thread Simcha

Ignore my previous email - 
It was sloppy. I was not focusing on the email.

SY
-Original Message-
From: Simcha [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, September 02, 2008 8:41 PM
To: 'Dan Shirah'; 'PHP List'
Subject: RE: [PHP] Confused

This does not seem to be an installation problem -

Your test [(!$connect_id = ] fails, since the connect returns false, so it
does not run the condition.

Compare:
?php

if($a = false){echo no good;}else{echo condition true;}

?



-Original Message-
From: Dan Shirah [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, September 02, 2008 7:31 PM
To: PHP List
Subject: [PHP] Confused

All,

Okay, I am a bit confused.   I'm setting up another server to host PHP
pages.  I followed everything in the Manual for installing PHP.  I'm running
Windows Server 2003, IIS6.0 and PHP 5.2.6.

And...it kind of works...

If I do: ?php echo Test; ? it prints fine.
If I do: Today is: ?php echo date(l, F j, Y); ? it prints fine.

If I do: You are recognized as: ?php echo substr($_SERVER['AUTH_USER'],
13); ? I get no output.
If I do:
 if (!$connect_id = ifx_connect([EMAIL PROTECTED], $user, $pass)) { //
THE ACTUAL CONNECTION
 echo Unable to connect to Informix Database\n; // DISPLAY IF
CONNECTION FAILS
 exit();
  }

I don't get a connection to the database and the Unable to connect to
Informix Database\n; does not even display.

I get no errors output to the screen and I have display_errors = On
And I have error_reporting = E_ALL  ~E_NOTICE

Any ideas?

No virus found in this incoming message.
Checked by AVG - http://www.avg.com 
Version: 8.0.169 / Virus Database: 270.6.14/1646 - Release Date: 02/09/2008
06:02


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

No virus found in this incoming message.
Checked by AVG - http://www.avg.com 
Version: 8.0.169 / Virus Database: 270.6.14/1646 - Release Date: 02/09/2008
06:02


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



RE: [PHP] Re: Variable name as a string

2008-08-28 Thread Simcha
The reason why... (I think)
Id defines the element as a part of the DOM - it is the identifier of the
element
Name tells the browser the name of the parameter (i.e. the mane to associate
with the value), not of the element.

PHP and JS are looking for two different things - one wants the element, one
the parameter - so it makes sense (sort of) to use two different terms.


Simcha Younger


-Original Message-
From: tedd [mailto:[EMAIL PROTECTED] 
Sent: Thursday, August 28, 2008 4:40 PM
To: php-general@lists.php.net
Subject: RE: [PHP] Re: Variable name as a string

At 11:50 AM +0100 8/28/08, Ford, Mike wrote:
On 28 August 2008 00:04, tedd advised:

   One of the ways to get around this is to:

  input type=checkbox name=my_checkboxes[]
  id=my_checkbox_1 value=1 
  
  That way php will use name and javascript will use id.

Why???

   form name=my_form ... 
  input type=checkbox name=my_checkboxes[] ... 
   /form

   script language=Javascript
   checkboxes = document.my_form[my_checkboxes[]];
   /script

Cheers!

Mike

Mike:

There is no Why?, this is just another way to do it. In fact, there 
are other ways to accomplish this than what both of us have shown.

What's nice about the technique I described here, at least for me, is 
that the value attribute applies to both name and id. PHP uses name 
and javascript uses id -- it's simple.

However, I've been leaning to using getElementById() to create 
unobtrusive javascript, which can be used to isolate and use name 
as well, thus reducing the html code.

I think my next demo will be to show these various techniques.

Cheers,

tedd

-- 
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

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

No virus found in this incoming message.
Checked by AVG - http://www.avg.com 
Version: 8.0.138 / Virus Database: 270.6.10/1638 - Release Date: 27/08/2008
19:06


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



RE: [PHP] Search Suggestions

2008-08-26 Thread Simcha Younger

You could have (and I assume you already have) an id for each
customer_name-DIV . This id should correspond to the customer id in your DB.
You can then send out an AJAX request with the search term and have it
return a list of the ids of the customer-DIV's to expand.
A similar solution is to send back a list of names to expand, and then have
Javascript go through the whole listing to find those names.

Simcha Younger


-Original Message-
From: Dan Shirah [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, August 26, 2008 3:31 PM
To: PHP-General List
Subject: [PHP] Search Suggestions

Hello,

I'm hoping to get a few good ideas on the best way to perform a search of
PHP results.

Currently I have a page that returns a list of collapsed customer data:

Example
+ John Smith
+ Jane Doe
+ Robert Jones
+ Dale Bennett

If the user clicks on a customer name it will expand the selection:

Example
 - John Smith
  - 123 Anywhere Street
  - myCity
  - myState
  - myZipcode
  - myWebsite
+ Jane Doe
+ Robert Jones
+ Dale Bennett

Now, what my client wants is a Search functionality that will allow him to
type in myState and have the application automatically expand and focus on
the first match. Then, be able to click Next and have it collapse the
first result and expand the next result that contains the same state.

Any ideas?

I was thinking that maybe I would have to create a temp table so it could be
searched against, but I'm not sure if that is the best idea.  Also, in order
to save processing time, the way I made the above expanding/collapsing list
is I don't not pull in the customer details intially but instead run a query
and get the details when the name is clicked for expansion.  This is because
there could be potentially 1,000's of result and getting all of the names
and all of the details at page load would 1) take longer than a user is
willing to wait 2) exceed the timeout 3) exceed the memory allocation

Thanks for any help/ideas.

Dan

No virus found in this incoming message.
Checked by AVG - http://www.avg.com 
Version: 8.0.138 / Virus Database: 270.6.7/1632 - Release Date: 25/08/2008
07:05


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



RE: [PHP] Large/unreliable file uploading over HTTP

2008-08-26 Thread Simcha Younger

Is this what you are looking for -- It's a java applet that has most of the
features you mentioned. I have used it for very large files with no problem.

http://www.javazoom.net/applets/jclientupload/jclientupload.html

(Sorry, its not free software.)

-Original Message-
From: mike [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, August 26, 2008 10:07 AM
To: PHP General list
Subject: [PHP] Large/unreliable file uploading over HTTP

Let's face it - HTTP is not very good for file uploads. It's stateless
nature, slow connections, inability to resume (technically), etc, etc.

What I've been thinking about is a way to skip all the normal
annoyances with file uploading - multipart form encodings, file upload
tools with specific needs, PUT vs POST, connection resets, ... the
list goes on and on.

Usenet and BitTorrent and other protocols have the right idea - split
up the workload into smaller sets of data. It's easier to operate on.
Usenet has NZB files. BitTorrent splits everything up into chunks. Not
only would it make working with the data more portable (no need to set
your PHP memory limit or POST limits to insane amounts to support
large files) but it could also support multiple segments of the file
being transferred at once...

Here's somewhat of a process braindump of what I'm thinking. It still
requires a 'smart' applet (Flash, Java, anything that can split a file
up and send data over HTTP/HTTPS) - no special socket needs, no PUT
support needed, don't even need to use multipart POST encoding (as far
as I know) - just send the data in chunks over the wire and have a PHP
script on the other side collect the data and reassemble it.

Does this sound insane? I think this is a pretty good approach - no
PUT needed, no large POST configuration required, anything could
upload to it as long as it sends the information properly (I'm
thinking HTTP POST for the header info, and the data could be sent as
another POST field maybe base64 encoded or something that will stay
safe during transit...)



- take input file, checksum it (md5 / sha1)
- calculate number of chunks to split it up based on $chunk configured
size (for example 128k chunks)
- split the file into chunks of $chunk size and create checksums for
all (could use sfv?)
- send request to the server - with the info - use JSON?
action=begin
filename=$filename
filesize=$filesize
checksum=$checksum
segments=list of segments (unique segment id, checksum, bytes)
- server sends back a server ready and unique $transaction_id
- start sending to the server, send header with transaction key and
unique chunk identifier in it
action=process
transaction=$transaction_id
segment=$unique_segment_id
   data=base64_encode($segment_data)
- when done, server sends back $transaction_id, $segment_id, $status
(okay, fail)
- client compares checksum for identifier, if okay, move to next chunk
- if it does not match, retry uploading to server again
- when all chunks are done, send request with transaction key and
action=finish
transaction=$transaction_id
   - when the server receives this, it assembles the file
from the segments and does a final checksum, and reports the checksum
back to the client (warning: on a large file this could take a bit?)
and sends back $transaction_id, $checksum
- client does one last check against the file's original checksum, if
it matches report success, otherwise report failure (would need to
determine why though - if all segments match this should not be able
to happen...)

I'd appreciate everyone's thoughts. This would also allow for file
upload progress, more or less, as the server and client are constantly
communicating when chunks are done and in progress (but again, that
has to be done with an applet)

I can't think of any method to do it in-browser, but doing it this way
could open the gates for things like Google Gears to possibly work
too...

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

No virus found in this incoming message.
Checked by AVG - http://www.avg.com 
Version: 8.0.138 / Virus Database: 270.6.7/1632 - Release Date: 25/08/2008
07:05


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



RE: [PHP] Negative Look Ahead Regex - Code Mistake or Bug?

2008-08-18 Thread Simcha Younger

Hi


You did not put a question mark in your character class  ([\/\w\.-] and
instead you put it together with the session id.
The expression looks for a sequence without which is not followed by the
next expression --- ?PHPSESSID\=2u0cca.
If it would count the last `p` of `.php` then the next expression would
violate the negative lookahead.
Instead it stops just before it, after the `.ph` which is the longest
expression it could find that fulfills your negative lookahead, and then it
inserts the new sessionid over there.

Try instead 
$buffer =
preg_replace('/http\:\/\/www\.domain\.com([\/\w\.\-]*\??)(?!PHPSESSID\=2u0c
caffoh6jaeapkke35qpp87;?)/',
'http://www.domain.com$1?PHPSESSID=t9gksvpdcuobsnqt98qloe6lg4;', $buffer);

(not tested)



Simcha Younger

-Original Message-
From: Cameron B. Prince [mailto:[EMAIL PROTECTED] 
Sent: Monday, August 18, 2008 12:56 AM
To: php-general@lists.php.net
Subject: [PHP] Negative Look Ahead Regex - Code Mistake or Bug?

Hello,

I¹ve run into a problem with a regex and need help determining if this is my
mistake or a bug. The regex is for inserting a SID into every link in the
buffer before it¹s flushed, but only when each link doesn¹t already have a
SID.

An example of the code is here:

$buffer = 
preg_replace('/http\:\/\/www\.domain\.com([\/\w\.-]*)(?!\?PHPSESSID\=2u0cca
ffoh6jaeapkke35qpp87;?)/',
'http://www.domain.com$1?PHPSESSID=t9gksvpdcuobsnqt98qloe6lg4;', $buffer);

The code works correctly in most cases except when a SID already exists and
there is a path after the .com such as:

http://www.domain.com/path1/path2.php?PHPSESSID=2u0ccaffoh6jaeapkke35qpp87;

When this URL is processed by the regex, it becomes:

http://www.domain.com/path1/path2.ph?PHPSESSID=t9gksvpdcuobsnqt98qloe6lg4;p?
PHPSESSID=2u0ccaffoh6jaeapkke35qpp87;


So the problem is the regex not only falsely matches, it's inserting the SID
in between 2nd and 3rd letters of the extension.

You can see the code in action here:

http://kottmann.com/test.php

The full source for the test code is also available when viewing the source
of this page.

I've tested this on PHP v5.1.6 and PHP v5.2.6.

TIA,
Cameron








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

No virus found in this incoming message.
Checked by AVG - http://www.avg.com 
Version: 8.0.138 / Virus Database: 270.6.4/1617 - Release Date: 17/08/2008
12:58


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



RE: [PHP] preg_replace strange behaviour, duplicates

2008-08-18 Thread Simcha Younger
?php

$string = The new Intel Core 2 Duo T8300;

 

$name = Intel Core 2;

$extra =  Duo;

 

 $insert =  Processor Technology;

 echo preg_replace(/({$name}{$extra}?)/, $1.$insert, $string);

 

 ?

 

 

Simcha Younger

 

-Original Message-

From: Adz07 [mailto:[EMAIL PROTECTED]

Sent: Monday, August 18, 2008 10:17 AM

To: php-general@lists.php.net

Subject: Re: [PHP] preg_replace strange behaviour, duplicates

 

 

Problem is that a negative assertion assumes i know what is going to come

after the match, but i don't. I am a bit stuck now :(

 

 

Adz07 wrote:

 

 I am trying to nail down a bit of code for changing processor names

 depending on matches.

 Problem i am having is the replacement takes place then it seems to do it

 again replacing the text just replaced as there are similar matches

 afterwards. example (easier)

 

 $string = The new Intel Core 2 Duo T8300;

 

 $patterns = array(/Intel Core 2 Duo/,/Intel Core 2/);

 

 $replacements = array(Intel Core 2 Duo Processor Technology,Intel Core

 2 Processor Technology);

 

 I would expect to get the following:

 

 The new Intel Core 2 Duo Processor Technology T8300

 

 but i get 

 

 The new Intel Core 2 Processor Technology Duo Processor Technology T8300

 

 I can see why its doing it, reading the string in and making the

 replacement but then reading the string in for the next pattern, but i

 don't want it to do this. How do i stop preg_replace from reading in the

 same part of the string that has been replaced already?

 

 (it's a bad day! :( )

 

 

-- 

View this message in context:
http://www.nabble.com/preg_replace-strange-behaviour%2C-duplicates-tp1900116
6p19027490.html

Sent from the PHP - General mailing list archive at Nabble.com.

 

 

-- 

PHP General Mailing List (http://www.php.net/)

To unsubscribe, visit: http://www.php.net/unsub.php

 

No virus found in this incoming message.

Checked by AVG - http://www.avg.com http://www.avg.com/  

Version: 8.0.138 / Virus Database: 270.6.4/1617 - Release Date: 17/08/2008
12:58

 

 



RE: [PHP] Negative Look Ahead Regex

2008-08-18 Thread Simcha Younger
Hi

I do not know if this is possible using negative assertions, but you can do
it with a search for any links, and then applying a callback which will
conditionally add your session id.

This seems to do the trick:

function addid($href){
$id = ?PHPSESSID=t9gksvpdcuobsnqt98qloe6lg4;;
$href = $href[1];
if(!strpos($href, PHPSESSID)) $href = preg_replace(/^([^#?]*)\??/,
$1$id, $href);
return $href.\;
}
$buffer = preg_replace_callback(/(href=\.*?)\/, addid, $buffer);


Simcha Younger

-Original Message-
From: Cameron B. Prince [mailto:[EMAIL PROTECTED] 
Sent: Monday, August 18, 2008 4:41 PM
To: Simcha Younger; php-general@lists.php.net
Subject: Re: [PHP] Negative Look Ahead Regex - Code Mistake or Bug?

Hi Simcha,

I tried your suggestion and it does prevent the SID from being inserted
inside the extension, but causes double ?'s and SID's in some cases.

Thanks,
Cameron


On 8/18/08 2:25 AM, Simcha Younger [EMAIL PROTECTED] wrote:

 
 Hi
 
 
 You did not put a question mark in your character class  ([\/\w\.-] and
 instead you put it together with the session id.
 The expression looks for a sequence without which is not followed by the
 next expression --- ?PHPSESSID\=2u0cca.
 If it would count the last `p` of `.php` then the next expression would
 violate the negative lookahead.
 Instead it stops just before it, after the `.ph` which is the longest
 expression it could find that fulfills your negative lookahead, and then
it
 inserts the new sessionid over there.
 
 Try instead 
 $buffer =

preg_replace('/http\:\/\/www\.domain\.com([\/\w\.\-]*\??)(?!PHPSESSID\=2u0c
 caffoh6jaeapkke35qpp87;?)/',
 'http://www.domain.com$1?PHPSESSID=t9gksvpdcuobsnqt98qloe6lg4;',
$buffer);
 
 (not tested)
 
 
 
 Simcha Younger
 
 -Original Message-
 From: Cameron B. Prince [mailto:[EMAIL PROTECTED]
 Sent: Monday, August 18, 2008 12:56 AM
 To: php-general@lists.php.net
 Subject: [PHP] Negative Look Ahead Regex - Code Mistake or Bug?
 
 Hello,
 
 I¹ve run into a problem with a regex and need help determining if this is
my
 mistake or a bug. The regex is for inserting a SID into every link in the
 buffer before it¹s flushed, but only when each link doesn¹t already have a
 SID.
 
 An example of the code is here:
 
 $buffer = 

preg_replace('/http\:\/\/www\.domain\.com([\/\w\.-]*)(?!\?PHPSESSID\=2u0cca
 ffoh6jaeapkke35qpp87;?)/',
 'http://www.domain.com$1?PHPSESSID=t9gksvpdcuobsnqt98qloe6lg4;',
$buffer);
 
 The code works correctly in most cases except when a SID already exists
and
 there is a path after the .com such as:
 

http://www.domain.com/path1/path2.php?PHPSESSID=2u0ccaffoh6jaeapkke35qpp87;
 
 When this URL is processed by the regex, it becomes:
 

http://www.domain.com/path1/path2.ph?PHPSESSID=t9gksvpdcuobsnqt98qloe6lg4;p?
 PHPSESSID=2u0ccaffoh6jaeapkke35qpp87;
 
 
 So the problem is the regex not only falsely matches, it's inserting the
SID
 in between 2nd and 3rd letters of the extension.
 
 You can see the code in action here:
 
 http://kottmann.com/test.php
 
 The full source for the test code is also available when viewing the
source
 of this page.
 
 I've tested this on PHP v5.1.6 and PHP v5.2.6.
 
 TIA,
 Cameron
 
 
 
 
 
 
 



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

No virus found in this incoming message.
Checked by AVG - http://www.avg.com 
Version: 8.0.138 / Virus Database: 270.6.4/1617 - Release Date: 17/08/2008
12:58


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



RE: [PHP] import XLS sheet into DB

2008-08-17 Thread Simcha
Try using:
http://sourceforge.net/docman/display_doc.php?docid=22092group_id=99160


I have never used it, but it looks very straightforward. Docs are here: 
http://sourceforge.net/docman/display_doc.php?docid=22092group_id=99160


code should be something like this: (for mysql, based on docs)
?php
include('reader.php');
//Make an instance of the class:
$xl_reader = new Spreadsheet_Excel_Reader();
$xl_reader-read(filename.xls);
$data = $xl_reader-sheets[0]['cells'];
Foreach($cells as $c){
foreach($c as $cd) $row[] = \.$cd.\;
$row = implode(,, $row);
mysql_query(insert into `table` values(.$row.));
}
?


-Original Message-
From: Jason Pruim [mailto:[EMAIL PROTECTED] 
Sent: Friday, August 15, 2008 12:29 PM
To: Alain R.
Cc: php-general@lists.php.net
Subject: Re: [PHP] import XLS sheet into DB


On Aug 15, 2008, at 4:29 AM, Alain R. wrote:

 Hi,

 I would like to import content of an XLS sheet into a PostgreSQL DB  
 (table).

 How can i do that ?
 thanks a lot,

 A.

Alain,

I haven't done it with PostgreSQL... But assuming it's not far from  
MySQL just save the excel file as a csv, or a tab separated file and  
import that. If you find away to import a strict xls file let me know,  
I have a project that could really benefit from that :)


--

Jason Pruim
Raoset Inc.
Technology Manager
MQC Specialist
11287 James St
Holland, MI 49424
www.raoset.com
[EMAIL PROTECTED]





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

No virus found in this incoming message.
Checked by AVG - http://www.avg.com 
Version: 8.0.138 / Virus Database: 270.6.3/1612 - Release Date: 14/08/2008
18:03


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



RE: [PHP] Removing an element from the middle of an mdlti-dimentsional array

2008-08-15 Thread Simcha Younger

array_splice($a, 1, 1);

This will remove the second element, and reset the keys.



Simcha Younger

-Original Message-
From: Don [mailto:[EMAIL PROTECTED] 
Sent: Friday, August 15, 2008 4:30 AM
To: php-general@lists.php.net
Subject: [PHP] Removing an element from the middle of an mdlti-dimentsional
array

Hi,

Let's say I have the following array:

$myArray = array(array('1','2','3'), array('4','5','6'), array('7','8','9'),

array('10','11','12'));

How do I remove say the second element?

I have tried: $myArray = array_splice($myArray, 1, 1);

But this seems to remove the second element as well as all the following 
elements and I am left with:

$myArray = array(array('1','2','3'));

when I really want:

$myArray = array(array('1','2','3'), array('7','8','9'), 
array('10','11','12'));


Thanks,
Don 



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

No virus found in this incoming message.
Checked by AVG - http://www.avg.com 
Version: 8.0.138 / Virus Database: 270.6.3/1612 - Release Date: 14/08/2008
18:03


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