SunQuest
           ASP Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreASP Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old August 27th, 2003, 05:09 PM
ozziec ozziec is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 14 ozziec User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 30 m 22 sec
Reputation Power: 0
asp/vbscrip to php/mysql - help!!!

hi,
sorry if this is not the right place to post this...

I am trying to convert some ASP/VScript code to PHP/Mysql but I am having some problems. Thanks so much in advance.

--- working ASP code ---
// Basic idea: customer orders 10 items. Code generates: 0zzie0001...ozzie0010. Customer orders 100 more items, code generates: ozzie0011-ozzie0100. untill it reaches ozzie9999. Get the idea? The following code works great in ASP but can't reproduce in PHP.

cID = "ozzie";
vQuantity = request.form("howmany");

sql = "SELECT MAX(accessionNum) AS lastNum FROM Customerorder WHERE customerNumber = '" & cID & "';"
set strRS = Conn.Execute(sql)

'now refer to alias
lastNumRS = strRS(0)

'test for null value
if lastNumRS ="" Then
lastNumRS = 0
end if

'Picks up(or chops off) the last 4 characters and Formats as Int.
lastNum = CInt(Trim(Right(lastNumRS,4)))

'READ THE LAST ENTRY FOR THE ACCESSION NUMBER, SAVE IT TO LastNum

'//Add quantity and lastNum, save it to temp
temp = Cint(lastNum) + cint(vQuantity) '// here is where it gets incremented to the next number.

FOR j = lastNumT TO temp-1
strNewItem = Cstr(j+1) '//this is done so we can concatenate the strings.

IF Len(strNewItem) < 4 THEN
strNewItem = String(4-Len(strNewItem),"0")
strNewItem = cID & strNewItem & j+1
else
strNewItem = cID & strNewITem
END IF
'// Result: ozzie0001 - ozzie9999.

--- end of working ASP code ---

---PHP/MYsql code ------
// same idea.

$user_accession_id = "SELECT MAX(accessionNumber) AS lastEntry FROM customerorder WHERE customerNumber = '".$row['id']."'";
$query = mysql_query($user_accession_id) or die("Invalid query: " . mysql_error());

$num_rows = mysql_num_rows($query);

//echo "$num_rows";
if ($lastEntry == NULL){
$lastEntry = 0;
//echo $lastEntry;
}
$quantity= 10; // debugg. Value coming from user.
$tmpVal = $lastEntry + $quantity; // sum of the two.
for($i = $lastEntry; $i < $tmpVal; $i++ )
{
//$id = $i+1;
if (strLen($tmpVal) < 4)
{
$total_num_char = (4 - strLen($tmpVal));
for ($j = 1; $j <= $total_num_char; $j++)
{
$item = $new_string . "0"; // I think here is the problem!!!!!!
$item = $item . ($i + 1);
}
echo ("$item<p>");
}
else {
$item = $new_string . $item;
}
}
//echo ("$item<br>");

?>
// RESULT: ozzie01; ozzie02; ozzie03 to ozzie010 instead of ozzie0001 - ozzie0100.

//if quantiy is 1000, the results are: ozzie01 - ozzie01000 not ozzie0001 - ozzie1000 which is what I want! Please help.

---PHP/MySql code -----

Last edited by ozziec : August 27th, 2003 at 05:14 PM.

Reply With Quote
  #2  
Old August 28th, 2003, 12:34 AM
unatratnag unatratnag is offline
Average Intelligence
Dev Shed Novice (500 - 999 posts)
 
Join Date: Apr 2003
Location: Ohio/Chicago
Posts: 678 unatratnag User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 m 22 sec
Reputation Power: 6
Send a message via AIM to unatratnag
wah, terrible ugly code, please use code tags

without getting into your logic because your indentation scares me, i don't see why you just don't do a loop 1 to max value requested, and then case the length of the iterator, if it's length = 1 you tack on 000 at the begginning, if it's length = 2 you tack on 00, simple case statement.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreASP Programming > asp/vbscrip to php/mysql - help!!!


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway