Current location: Hot Scripts Forums » Programming Languages » PHP » Skips array on second pass


Skips array on second pass

Reply
  #1 (permalink)  
Old 09-21-06, 01:28 PM
patter patter is offline
Newbie Coder
 
Join Date: Jul 2006
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Skips array on second pass

My database has a table of products with similar names except for the numeric end. So the products might look like:

prod1-30
prod1-36
prod2-24
prod2-30

I need to have all of the products have all of the proper endings. If one doesn't exist, I need to add it to the database so that it ends up looking like this:

prod1-24
prod1-30
prod1-36
prod2-24
prod2-30
prod2-36

To do this, I came up with this code to find the missing products:

PHP Code:

    $products_query mysql_query("SELECT ..."

    
    
$type = array();
    
$type[] = "-20";
    
$type[] = "-20";
    
$type[] = "-36"
    
    for (
$i 0$i count($type); ++$i)
    {
      while (
$products mysql_fetch_array($products_query)) 
      {
         if (
strpos($products['products_model'], $type[$i]) === FALSE)
         {
           echo 
'Add '.$type[$i] . ' to ' .$products['products_model'].'<br>';
         }  
      } 
    } 
This will work on the first pass but when it goes back to check the next "type," the code gets skipped. I thought it has something to do with the array pointer but using reset($products_query) results in an invalid argument error.

Would someone please point out my mistake? Is there a better way to code what I need to do?

Last edited by nico_swd; 09-21-06 at 01:41 PM.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ')' Dr. Forensics PHP 3 07-15-06 03:54 PM
how to pass php array to javascript jaishalg PHP 2 12-23-05 03:28 AM
Sorting a massive multidimensional array dave111 PHP 1 12-12-05 04:09 PM
Serializing a set of arrays dannyallen PHP 2 10-11-04 03:04 AM
linking to iframe not working :( j0d JavaScript 5 01-19-04 08:14 PM


All times are GMT -5. The time now is 07:29 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.