random numbers vs sequential numbers

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the entire section of code that uses $ID needs to be moved to after $num is set up with the file.. way down the script.

I don't have the energy to walk you through all the changes that may be necessary, mostly because of the volume of code in that script.. which contains zero functions.. I haven't seen code like that in years..
skydivelouie
Forum Newbie
Posts: 23
Joined: Tue Jan 18, 2005 7:07 pm

Post by skydivelouie »

I thought I already submitted this...but didn't see it after I rebooted...

This script is designed for newbies like me...I understand you are used to more complicated scripts...although I am not...This script was written into subsections in order for idiots like me to attempt to make simple modifications...You have offered substantial help and I do appreciate it...

I believe there are only 2 sections in this code that are preventing my from accomplishing my sequential numbering code...one of which you have helped SUBSTANTIALLY...Thank You...


This portion seems to tell the $ID where to begin counting...

Code: Select all

#===========================================================
# ADJUST A FEW VARIABLES
#===========================================================

$ID = $num;

for ($x=0;$x<count($EMAIL);$x++)&#123;
 if ($EMAIL&#1111;$x]) $SendFrom = $EMAIL&#1111;$x];&#125;
if (!$SendFrom)
 $SendFrom = $Recipient;

$_EMAIL = $_POST;
$_HTML = $_POST;
$_SQL = $_POST;
$_CSV = $_POST;
$_FILE = $_POST;
$_AUTO = $_POST;

$AttachmentField = explode(",",$AttachmentFields);

$x=0;
foreach ($AttachmentField as $ThisAttachment)
&#123;
 $ATTACH&#1111;$x]&#1111;0] = $_FILES&#1111;$ThisAttachment]&#1111;'name'];
 $ATTACH&#1111;$x]&#1111;1] = $_FILES&#1111;$ThisAttachment]&#1111;'tmp_name'];
 $x++;
&#125;

if ($SMTPServer)
&#123;
 ini_set('SMTP',$SMTPServer);
 ini_set('sendfrom_mail',$Recipient);
&#125;
And this is the portion where you helped out substantially...

Code: Select all

#########################################################################
# FLAT-FILE FUNCTIONS                                                   #
#########################################################################
if ($Action == "F" or $Action == "EF" or $Action == "DF")&#123;

$seqfile = 'ID.txt'; 

if(!file_exists($seqfile)) 
  $num = 100; 
else 
  $num = intval(file_get_contents($seqfile)) + 1; 

$fp = fopen($seqfile, 'w'); 
fwrite($fp, $num); 
fclose($fp); 

// send the form's data
$handle = @fopen($FlatFile,'a');
@flock($handle,LOCK_EX);
@fwrite($handle,$FileData);
@flock($handle,LOCK_UN);
@fclose($handle);

&#125; // END OF ACTION
I believe the answer to what I'm trying to acomplish is within these 2 portions of code...you seem to be the one who has the most consistent and successful answers...

I appreciate your help thusfar...this is so close to being accomplished I can't give up now...If you choose to help me I would truly be grateful...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

roughly, code block 1 needs to come after code block 2.

code blocks 1 and 2 are references to your last post.
skydivelouie
Forum Newbie
Posts: 23
Joined: Tue Jan 18, 2005 7:07 pm

Post by skydivelouie »

I switched them around in the code...I received the same results...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

k... delete this

Code: Select all

$seqfile = 'ID.txt';

if(!file_exists($seqfile))
  $num = 100;
else
  $num = intval(file_get_contents($seqfile)) + 1;

$fp = fopen($seqfile, 'w');
fwrite($fp, $num);
fclose($fp);
and put this

Code: Select all

$seqfile = 'ID.txt';

if(!file_exists($seqfile))
  $ID = 100;
else
  $ID = intval(file_get_contents($seqfile)) + 1;

$fp = fopen($seqfile, 'w');
fwrite($fp, $ID);
fclose($fp);
after the code from "choose action", and before "email functions" section.


I seriously hope that takes care of it.. :? :|
skydivelouie
Forum Newbie
Posts: 23
Joined: Tue Jan 18, 2005 7:07 pm

Post by skydivelouie »

Dude...you...are...a...freakin'...GENIUS!!!...

I can't thank you enough...

Your genius far exceeds what I feel I could offer in gratitude...Thank you...Exponentially...!!!...

I am still curious as to why the number continues to grow from 10000...to which is currently at 10022...even though I've changed the beginning number from what I see as a point of reference to 100 and then 1000...it seems to increase in the same increments...

http://www.skydivelouie.com/mmex/ID.txt

I don't know if this is something I did or what...

Ya know...whatever...you have set me leaps and bounds beyond where I was earlier in the day...

I continue to value your advice...

Thank You...


User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the part where it adds 1, is what keeps the increment moving at the correct rate, whether you start it at -500000 or 10..
skydivelouie
Forum Newbie
Posts: 23
Joined: Tue Jan 18, 2005 7:07 pm

Post by skydivelouie »

I am exhausted for the night...I can't think anymore...

I will post again tomorrow AM...quite possibly PM...

I do sincerely appreciate your help...you are a PHP genius...

Thanks again...my personal email is hidden...

Feel free to contact whenever for whatever...

TTYS...
skydivelouie
Forum Newbie
Posts: 23
Joined: Tue Jan 18, 2005 7:07 pm

Post by skydivelouie »

Thanks again Feyd...

Appreciated...
Post Reply