Page 3 of 3 FirstFirst 123
Results 21 to 25 of 25
  1. #21
    Join Date
    Jan 2004
    Posts
    66,450
    Plugin Contributions
    81

    Default Re: Custom serial display help

    Try this:
    Code:
    function getSetial($productID)
      {
      	global $db; 
    	$code = 'No serial required for this product. If you do need a serial and did not receive one please contact our staff.';
    	$dbres = $db->Execute("SELECT codeID, code FROM zen_codes WHERE viewed = 0 AND itemID = '" . $productID . "' LIMIT 1");
    	
    	if ($dbres->RecordCount() == 1)
    	{
    		$code = $dbres->fields['code'];
    	
    		$db->Execute("UPDATE zen_codes SET viewed = 1 WHERE codeID = " . $dbres->fields['codeID']);
    	}
    	
    	return $code;
      }
    It's only slightly different. You don't really need a "while" loop on something that can only ever get maximum of 1 result.
    If you *were* using a "while" loop, you'd need to do a MoveNext() inside the loop in order to cycle through the results. But, again, in this case you don't need to use a while loop.
    .
    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  2. #22
    Join Date
    Jul 2008
    Posts
    15
    Plugin Contributions
    0

    Default Re: Custom serial display help

    still the same result (no serial needed message), its like its not even finding those serials in there....

  3. #23
    Join Date
    Jul 2008
    Posts
    15
    Plugin Contributions
    0

    Default Re: Custom serial display help

    ok i figured out that the problem was with the product ID, its the productID:session thats how it was formatted so i edited the script to look like this:
    PHP Code:
            global $db
        
          
    $productArray explode(":"$productID);
        
        
    $code 'No serial required for this product. If you do need a serial and did not recieve one please contact our staff.';
        
    $dbres $db->Execute("SELECT codeID, code FROM zen_codes WHERE viewed = 0 AND itemID = '" $productArray[0] . "' LIMIT 1");
        
        
    $i 0;
        while(
    $dbres->RecordCount() == && $i 1)
        {
            
    $code $dbres->fields['code'];
        
            
    $db->Execute("UPDATE zen_codes SET viewed = 1 WHERE codeID = " $dbres->fields['codeID']);
            
    $i++;
        }
        
        return 
    $code
    now that should work because its pulling the number from the array but when i go to check out (the 3rd step) it just keeps loading, no error message or anything, like its on an infinite loop...

    but the i should stop it from looping right?

  4. #24
    Join Date
    Jul 2008
    Posts
    15
    Plugin Contributions
    0

    Default Re: Custom serial display help

    ok another edit i got it to work with this:

    PHP Code:
    global $db
        
          
    $productArray explode(":"$productID);
        
        
    $code 'No serial required for this product. If you do need a serial and did not recieve one please contact our staff.';
        
    $dbres $db->Execute("SELECT codeID, code FROM zen_codes WHERE viewed = 0 AND itemID = '" $productArray[0] . "' LIMIT 1");
        
        if(
    $dbres->RecordCount() > 0)
        {
            
    $i 0;
            while(
    $i 1)
            {
                
    $code $dbres->fields['code'];
            
                
    $db->Execute("UPDATE zen_codes SET viewed = 1 WHERE codeID = " $dbres->fields['codeID']);
                
    $i++;
            }
        }
        
        return 
    $code
    but it loads sooo slowly, could it be database performance?

    there are only 13095 records in the zen_codes table

  5. #25
    Join Date
    Jan 2004
    Posts
    66,450
    Plugin Contributions
    81

    Default Re: Custom serial display help

    I don't see any need for the $i variable, nor the while loop.
    As to performance, I can't speak for how you've optimized your table. You might want to put an index on the fields you're using.
    .
    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

 

 
Page 3 of 3 FirstFirst 123

Similar Threads

  1. v151 Custom layout help wanted for Radio buttons with display:block or white-space:nowrap
    By dw08gm in forum Templates, Stylesheets, Page Layout
    Replies: 8
    Last Post: 21 May 2013, 03:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg