Re: [PHP] Any Ideas?

2004-03-22 Thread Robert Cummings
On Mon, 2004-03-22 at 18:51, Matthew Oatham wrote:
 Hi,
 
 are there any functions that retrieve the last primary key created in
 the MySQL table?

http://www.php.net/manual/en/function.mysql-insert-id.php

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

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



Re: [PHP] Any Ideas?

2004-03-22 Thread John W. Holmes
Matthew Oatham wrote:

I have a MySQL table which uses a auto_increment 
int as the primary key - when I do an insert I want 
to create another id based on the primary key and 
insert this into the same table i.e. if I do an 
insert and the primary key is 3 I want to generate 
the ID CR-003, if the primary key was 34 I would 
want to generate the id CR-034. So I guess I need 
to know the following. 
You don't want or need to do this. You're just repeating data. The 34 
is already there in one column, why repeat it (especially if the CR 
bit never changes).

Just select out when you need in the query or use PHP to make the 
combination.

SELECT CONCAT('CR-',id) AS formatted_number FROM table WHERE ...

Or use PHP, where $id is the primary key

$formatted_number = 'CR-' . $id;

You can use a ZEROFILL attribute on your column to ensure the leading 
zeros get returned or use sprintf() in PHP to format the number.

Even if the CR changes, then just put that bit in another column and 
join them together later.

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

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


Re: [PHP] Any Ideas?

2004-03-22 Thread John W. Holmes
Robert Cummings wrote:

On Mon, 2004-03-22 at 18:51, Matthew Oatham wrote:

Hi,

are there any functions that retrieve the last primary key created in
the MySQL table?


http://www.php.net/manual/en/function.mysql-insert-id.php
If you read the whole question, though, the poster wanted to use the ID 
in the same query, just in another column. mysql_insert_id() or 
LAST_INSERT_ID() wouldn't help in this case.

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

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


Re: [PHP] Any Ideas?

2004-03-22 Thread Matthew Oatham
The idea was that the user uploads a file and I insert details about the
file into the mysql table and rename the file using the generated id.

so if the next primary key is 4 I generate the file id CR-004 and rename the
uploaded file to CR-004 whilst also storing CR-004 in the table.

Thanks for your ideas so far - very useful! How do you get to know about all
these useful functions?

Cheers

Matt
- Original Message - 
From: John W. Holmes [EMAIL PROTECTED]
To: Robert Cummings [EMAIL PROTECTED]
Cc: Matthew Oatham [EMAIL PROTECTED]; PHP-General
[EMAIL PROTECTED]
Sent: Tuesday, March 23, 2004 12:25 AM
Subject: Re: [PHP] Any Ideas?


 Robert Cummings wrote:

  On Mon, 2004-03-22 at 18:51, Matthew Oatham wrote:
 
 Hi,
 
 are there any functions that retrieve the last primary key created in
 the MySQL table?
 
 
  http://www.php.net/manual/en/function.mysql-insert-id.php

 If you read the whole question, though, the poster wanted to use the ID
 in the same query, just in another column. mysql_insert_id() or
 LAST_INSERT_ID() wouldn't help in this case.

 -- 
 ---John Holmes...

 Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

 php|architect: The Magazine for PHP Professionals  www.phparch.com

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



Re: [PHP] Any Ideas?

2004-03-22 Thread Raditha Dissanayake
Matthew Oatham wrote:

The idea was that the user uploads a file and I insert details about the
file into the mysql table and rename the file using the generated id.
 

Even with this scenario you probably can do with out the extra column as 
John has suggested.

so if the next primary key is 4 I generate the file id CR-004 and rename the
uploaded file to CR-004 whilst also storing CR-004 in the table.
 

You are still following a pattern. COuld you perhaps clarify if CR is 
common for all users or do you choose a different prefix for different 
users. If you do use different combinations of letters yes you might 
need a different field and then the solution would be what Robert 
suggested mysql_insert_id() you will need to use an update an update 
query where the condition has the insert id returned by this call.

Thanks for your ideas so far - very useful! How do you get to know about all
these useful functions?
 

by RTFM. :-)

Cheers

Matt
-
--
Raditha Dissanayake.
-
http://www.radinks.com/print/upload.php
SFTP, FTP and HTTP File Upload solutions 

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


Re: [PHP] Any Ideas?

2004-03-22 Thread Matthew Oatham
Bit rough at the moment but I have come up with the following - it doesn't
rename the file using the new ID yet but I am more concerned about my method
for creating the new ID - can anyone see any potential problems such as
database problems, i.e duplicate keys, bad coding practices etc... cheers
matt

if(!empty($_FILES[cr])) {
$uploaddir = cr/; // set this to wherever
//copy the file to some permanent location
if (move_uploaded_file($_FILES[cr][tmp_name], $uploaddir .
$_FILES[cr][name])) {
echo(file uploaded\n);
echo(generateCrId(insertChangeRequest()));
} else {
echo (error!);
}
}

function insertChangeRequest() {

$sql = mysql_query(INSERT INTO dis_status(status, description)
VALUES('status1', 'status1 description')) or die (mysql_error());

return mysql_insert_id();
}

function generateCrId($key) {

$crId = sprintf(CR-%03d, $key);

return $crId;
}


- Original Message - 
From: John W. Holmes [EMAIL PROTECTED]
To: Robert Cummings [EMAIL PROTECTED]
Cc: Matthew Oatham [EMAIL PROTECTED]; PHP-General
[EMAIL PROTECTED]
Sent: Tuesday, March 23, 2004 12:25 AM
Subject: Re: [PHP] Any Ideas?


 Robert Cummings wrote:

  On Mon, 2004-03-22 at 18:51, Matthew Oatham wrote:
 
 Hi,
 
 are there any functions that retrieve the last primary key created in
 the MySQL table?
 
 
  http://www.php.net/manual/en/function.mysql-insert-id.php

 If you read the whole question, though, the poster wanted to use the ID
 in the same query, just in another column. mysql_insert_id() or
 LAST_INSERT_ID() wouldn't help in this case.

 -- 
 ---John Holmes...

 Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

 php|architect: The Magazine for PHP Professionals  www.phparch.com

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



RE: [PHP] Any Ideas?

2004-03-22 Thread Chris W. Parker
Matthew Oatham mailto:[EMAIL PROTECTED]
on Monday, March 22, 2004 4:56 PM said:

 can anyone see any
 potential problems such as database problems, i.e duplicate keys, bad
 coding practices etc... cheers matt
 
 if(!empty($_FILES[cr])) {
 $uploaddir = cr/; // set this to wherever
 //copy the file to some permanent location
 if (move_uploaded_file($_FILES[cr][tmp_name], $uploaddir .
 $_FILES[cr][name])) {
 echo(file uploaded\n);
 echo(generateCrId(insertChangeRequest()));
 } else {
 echo (error!);
 }
 }

yeah i see a few already. the following is better:

if(!empty($_FILES[cr]))
{
// code
}
else
{
// other code
}

:P


chris.

p.s. no rebuttals please. there's nothing to say. kthxbye.

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



Re: [PHP] Any Ideas?

2004-03-22 Thread Robert Cummings
On Mon, 2004-03-22 at 19:25, John W. Holmes wrote:
 Robert Cummings wrote:
 
  On Mon, 2004-03-22 at 18:51, Matthew Oatham wrote:
  
 Hi,
 
 are there any functions that retrieve the last primary key created in
 the MySQL table?
  
  
  http://www.php.net/manual/en/function.mysql-insert-id.php
 
 If you read the whole question, though, the poster wanted to use the ID 
 in the same query, just in another column. mysql_insert_id() or 
 LAST_INSERT_ID() wouldn't help in this case.

Actually I did read the entire question. The poster includes mention of
using insert, then update, or possibly locking the table. This logically
implies that he does not necessarily care whether the construction of
the ID occurs in the original query or not.

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

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



Re: [PHP] Any Ideas?

2004-03-22 Thread John W. Holmes
Matthew Oatham wrote:

Bit rough at the moment but I have come up with the following - it doesn't
rename the file using the new ID yet but I am more concerned about my method
for creating the new ID - can anyone see any potential problems such as
database problems, i.e duplicate keys, bad coding practices etc... cheers
matt
if(!empty($_FILES[cr])) {
$uploaddir = cr/; // set this to wherever
//copy the file to some permanent location
if (move_uploaded_file($_FILES[cr][tmp_name], $uploaddir .
$_FILES[cr][name])) {
echo(file uploaded\n);
echo(generateCrId(insertChangeRequest()));
} else {
echo (error!);
}
}
function insertChangeRequest() {

$sql = mysql_query(INSERT INTO dis_status(status, description)
VALUES('status1', 'status1 description')) or die (mysql_error());
return mysql_insert_id();
}
function generateCrId($key) {

$crId = sprintf(CR-%03d, $key);

return $crId;
}
Looks fine. Just realize that you don't have to insert $crId into the 
database as you can just recreate it when you need to know the file 
name. You just retrieve the id and add the CR- to it.

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

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


Re: [PHP] Any Ideas @ becomes _Xy

2002-05-20 Thread Analysis Solutions

On Sat, May 18, 2002 at 11:45:49AM +0100, Henry wrote:
 
 http://GetResponse.com/k.cgi?a=blahblahf=henry_Xyteacake.force9.co.uk
 I subscribed using the email address [EMAIL PROTECTED]
 They appear to have translated the @ symbol to _Xy.
 Any guess why? Is there a PHP function that does this translation for me? Is
 it some sort of standard?

That's something they did manually to their own standard.  The standard 
encoding for @ is %40.  Why?  Beats me.  They don't really need to.  
Encoding URL's can be done via urlencode() and urldecode().

If you want to do the same thing they're doing, you can use
str_replace(): http://www.php.net/manual/en/function.str-replace.php

Enjoy,

--Dan

-- 
   PHP classes that make web design easier
SQL Solution  |   Layout Solution   |  Form Solution
sqlsolution.info  | layoutsolution.info |  formsolution.info
 T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
 4015 7 Av #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409

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




RE: [PHP] Any Ideas @ becomes _Xy

2002-05-20 Thread Scott Hurring

 -Original Message-
 From: Analysis  Solutions [mailto:[EMAIL PROTECTED]]
 Subject: Re: [PHP] Any Ideas @ becomes _Xy
 
 On Sat, May 18, 2002 at 11:45:49AM +0100, Henry wrote:
  
  
 http://GetResponse.com/k.cgi?a=blahblahf=henry_Xyteacake.force9.co.uk
  I subscribed using the email address [EMAIL PROTECTED]
  They appear to have translated the @ symbol to _Xy.
  Any guess why? Is there a PHP function that does this 
 translation for me? Is
  it some sort of standard?
 
 That's something they did manually to their own standard.  
 The standard 
 encoding for @ is %40.  Why?  Beats me.  They don't really need to.  
 Encoding URL's can be done via urlencode() and urldecode().
 
 If you want to do the same thing they're doing, you can use
 str_replace(): http://www.php.net/manual/en/function.str-replace.php
 
 Enjoy,
 
 --Dan

Perhaps they did it to thwart smart spambots that can
translate %40 to @.

---
Scott Hurring
Systems Programmer
EAC Corporation
[EMAIL PROTECTED]
Voice: 201-462-2149
Fax: 201-288-1515

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




RE: [PHP] Any ideas on content management system for Apache+PHP+MySQL

2002-05-02 Thread Jay Blanchard

[snip]
I am a webmaster for an agency.
I looked at many content management pieces for
Linux+Apache+PHP+MySQL like ezPublish and etc. but
they look overly complex for my needs.
I just need to have something that would allow me to
insert picture, text, and list of links into a
template. I don't want a heavy system, just something
lighweight. Any ideas?
Page would be like:
Picture

Text

List of links

All this would be taken from a MySQL and parsed via
PHP.
Thank you in advance

Or is there a nice program like Fireworks or GoLive,
but with ability to have object be pulled from database?
[/snip]

There are many options, including building your own.
[shameless plug]
I am writing a series of articles on building a CMS from scratch, The ABC's
of CMS;
http://www.evolt.org/article/The_ABCs_of_CMS/20/24182/index.html
[/shameless plug]

There is other good information about CMS there as well. Here are some other
resources;
http://www.cms-list.org/
http://www.cmswatch.com/
http://www.contentmanager.eu.com/
http://developer.ez.no/

HTH!

Jay Blanchard




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




Re: [PHP] Any ideas on combining arrays????

2002-04-05 Thread Michael Virnstein

perhaps:

$FFR = array(TU4R = array(data = array(array(count = TU4R is 0),
 array(count = TU4R is 1),
 array(count = TU4R is
2))),
  PH01 = array(data = array(array(count = PH01 is
0;
print_r($FFR);


Rick Emery [EMAIL PROTECTED] schrieb im Newsbeitrag
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 ok...so what problem are you having?  what's the error?
 your code worked for me, i.e., it compiled and executed

 -Original Message-
 From: Scott Fletcher [mailto:[EMAIL PROTECTED]]
 Sent: Wednesday, April 03, 2002 11:15 AM
 To: [EMAIL PROTECTED]
 Subject: [PHP] Any ideas on combining arrays


 Hi!

 Need some ideas on combining some arrays into one!  I have array for
 data and other array for counter.  How do I make an array that would show
 different data for each counter number?

 -- clip --
$FFR = array (
   TU4R  = array( data = , count =  ),
   PH01  = array( data = , count =  ),
);
 -- clip --

 The response should look something like this when I pick the correct
 data and correct count;

$FFR[TU4R][data][0][count]  = TU4R is 0;
$FFR[TU4R][data][1][count] = TU4R is 1;
$FFR[TU4R][data][2][count]  = TU4R is 2;

 I tried to do something like this but it doesn't work.  I have been
 working for 2 days trying to figure it out.  I appreciate any help you can
 provide for me.

 Thanks,
   Scott



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




RE: [PHP] Any ideas on combining arrays????

2002-04-03 Thread Rick Emery

ok...so what problem are you having?  what's the error?
your code worked for me, i.e., it compiled and executed

-Original Message-
From: Scott Fletcher [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, April 03, 2002 11:15 AM
To: [EMAIL PROTECTED]
Subject: [PHP] Any ideas on combining arrays


Hi!

Need some ideas on combining some arrays into one!  I have array for
data and other array for counter.  How do I make an array that would show
different data for each counter number?

-- clip --
   $FFR = array (
  TU4R  = array( data = , count =  ),
  PH01  = array( data = , count =  ),
   );
-- clip --

The response should look something like this when I pick the correct
data and correct count;

   $FFR[TU4R][data][0][count]  = TU4R is 0;
   $FFR[TU4R][data][1][count] = TU4R is 1;
   $FFR[TU4R][data][2][count]  = TU4R is 2;

I tried to do something like this but it doesn't work.  I have been
working for 2 days trying to figure it out.  I appreciate any help you can
provide for me.

Thanks,
  Scott



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




Re: [PHP] Any ideas on combining arrays????

2002-04-03 Thread Hugh Bothwell

I'm not sure I understand what problem
you're trying to solve.

It looks something like the number of times
a given piece of data occurs per user?

Where does the data come from and what
are you trying to accomplish?


 Need some ideas on combining some arrays
 into one!  I have array for data and other array
 for counter.  How do I make an array that would show
 different data for each counter number?

 -- clip --
$FFR = array (
   TU4R  = array( data = , count =  ),
   PH01  = array( data = , count =  ),
);
 -- clip --




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




Re: [PHP] any ideas : Unexpected character

2002-02-14 Thread Girish Nath

Hi

I got this error :

Warning: Unexpected character in input: ' in
/home/altdesign/public_html/php/new admin/do_addauthor.php on line 14

Can you post the section around Line 14 from do_addauthor.php so we can take
a look at it ?

Regards


Girish
--
www.girishnath.co.uk


- Original Message -
From: Will Hives [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Thursday, February 14, 2002 4:34 PM
Subject: [PHP] any ideas : Unexpected character



I have put together this script with the help of some of you kind members
here. It seems to do what I set out for it to do, but when it finished the
upload it comes up with the following error:

Unexpected character

try for yourself: http://www.alt-design.net/php/new%20admin/add.php

I would be very grateful for any ideas.

Cheers
Will



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




Re: [PHP] any ideas : Unexpected character

2002-02-14 Thread Will Hives

== image/jpg || $type == image/gif || $type ==
image/pjpeg || $type == image/jpeg){ // is this a valid image?
 
 $time_tmp = time();
 $time_tmp = substr($time_tmp, -4);
 $filename = $time_tmp._.$name; // just in case someone
uploads matched filenames.
 $savepath = /home/*/***/php/.$filename;  //
change the path here.  make sure the directory it is going to can be written
to by the web user.
 
 $moved = move_uploaded_file($file, $savepath); // place the
file on the server's filesystem
 $path = $filename;
 
 } else { // wrong file type
 $path = Sorry, but the file type of this file is not
recognised. Please check and try again.p;
 }
 } else { // upload failed.
 $path =Sorry, but the upload failed. Please try again in a
short while.p;
 }
 return $path;
 }
 
 // uploaded file info-zone - prepare variables to be passed to the upload
function
 
$name = $HTTP_POST_FILES['picture']['name']; // orginal name
$type = $HTTP_POST_FILES['picture']['type']; // get MIME type of file
 
$path = fileUpload($name,$type,$picture); // yer actual upload function call

// I'd recommend you check the value of $path here - if it contains a text
string starting with Sorry then something has failed.

// and off to the database it goes.
$sql = INSERT INTO $table_name (id, name, email, picture_name)
VALUES ('$id', '$name', '$email', '$path') ;

$result = mysql_query($sql, $connection) or die (couldn't execute query);





in article 005301c1b576$31479df0$0a0a@AERIS, Girish Nath at
[EMAIL PROTECTED] wrote on 2/14/2002 4:39 PM:

 Hi
 
 I got this error :
 
 Warning: Unexpected character in input: ' in
 /home/altdesign/public_html/php/new admin/do_addauthor.php on line 14
 
 Can you post the section around Line 14 from do_addauthor.php so we can take
 a look at it ?
 
 Regards
 
 
 Girish
 --
 www.girishnath.co.uk
 
 
 - Original Message -
 From: Will Hives [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Sent: Thursday, February 14, 2002 4:34 PM
 Subject: [PHP] any ideas : Unexpected character
 
 
 
 I have put together this script with the help of some of you kind members
 here. It seems to do what I set out for it to do, but when it finished the
 upload it comes up with the following error:
 
 Unexpected character
 
 try for yourself: http://www.alt-design.net/php/new%20admin/add.php
 
 I would be very grateful for any ideas.
 
 Cheers
 Will
 
 
 
 --
 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




Re: [PHP] Any Ideas

2002-01-28 Thread Jason G.

$str = ereg_replace('[-!@#$%^*()_+=-\';:/.,?]', '', $str);

You may need to escape some of these characters with \

On the other hand, they are contained in a character class [] so you may 
not need to escape them.  Note how the `-' is in the beginning.

-Jason Garber
IonZoft.com


At 09:13 AM 1/27/2002 +1300, Philip J. Newman wrote:
Any Ideas how I can remove   !@#$%^*()_+=-';:/.,? charactors from a 
string?

Philip J. Newman
Philip's Domain - Internet Project.
http://www.philipsdomain.com/
[EMAIL PROTECTED]
Phone: +64 25 6144012


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]