|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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. |
|
#2
|
|||
|
|||
|
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. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ASP Programming > asp/vbscrip to php/mysql - help!!! |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|