Jump to content

needsomephphelp

Members
  • Posts

    5
  • Joined

  • Last visited

needsomephphelp's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I would agree that if every function of finding part number attributes were that straight forward, letting MySQL do the work would be much easier. The problem is, not every attribute can use one layer of substr logic. The substr is a key function here, but then depending on the part model, each piece of the part number string can mean something different.
  2. Not quite sure I understand here. Are you saying I have to let the function pass in an array of my part numbers or return an array of return values? Not exactly sure how to go about doing that?
  3. Just to clarify, my function getModel() should only return one value for each part number. Essentially what I am trying to do is have the script read into a list of part number strings ($part) and find various attributes of the part numbers. In this case, my getModel function will return the model string value of one $part. One $part will only ever have one Model, returned from the getModel() function. I have a script that can read one $part and it properly finds the correct getModel. The stumbling block that I have is how to really make use of my getModel function by finding the getModel for hundreds or thousands of part numbers. I have created several functions that get the $part passed to them to find the one return value. So the reason for my loop then is to take several hundred or more $part (part numbers) and pass it through to find out what the model is, etc. I hope I am making sense here....
  4. Interesting, I tried that and now it appears that my script breaks when I try to assign the $Model variable the result of the getModel function. I dont get any errors, just a broken script. If I comment my $Model = getModel($part); line out, it processes. So theoretically I should be able to create a function return, and call that function on another page with an include to my function library and have a while loop pass through my $part array and assign the return value of that function to a variable? I dont know if the return is exiting the loop? Seems like it my problem is strictly tied to the line where I assign $Model the value of my getModel function.
  5. I have created a user defined function to return a string value function getModel($part) { $root = substr($part,0,4); $query = "SELECT Root, Model FROM tbl_Root WHERE Root = '$root'"; $result = mysql_query($query) or die ("Query Root failed: " . mysql_error()); while ($rec = mysql_fetch_array($result, MYSQL_ASSOC)) { if (in_array($root, $rec)): $Model = $rec['Model']; else: $Model = 'UNKNOWN'; endif; } return $Model; } When trying to find the attributes of several hundred part numbers, I pass them to a MySQL temp table that would then select the distinct part numbers and loop them through my functions. $query = "SELECT DISTINCT A FROM TempAttributes"; $result = mysql_query($query) or die ("Query failed: " . mysql_error()); while ($rec = mysql_fetch_array($result, MYSQL_ASSOC)) { $part = mysql_escape_string($rec['A']); $Model = getModel($part); $query = "REPLACE INTO tbl_Attributes (Part, Model) VALUES ('$part', '$Model')"; $endresult = mysql_query($query) or die ("Query Load failed: " . mysql_error()); } The line of code that stops the execution of my loop is $Model = getModel($part); I executed the loop with this line of code in and it stops after the first part number. When I comment this line of code out, my loop processes all of my part numbers, but of course not with the return values I am looking for. Why does my user defined function not process through the while loop to assign the $Model variable the return value of the getModel function? Please help!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.