Re: Check if any items in an array (php) is in a table (mysql).



rjames.clarke@xxxxxxxxx wrote:
I want to check if any of the items in a PHP array exist in a MySQL
table.
What is the best way to do this with making repeated calls to the
database for each item?

Actual application is:
I have an array (in PHP) of serial numbers of units about to be
shipped.
I want to check the ship record (a table in a MySQL database) to check
if that serial number has been used before.
According to our quality policy we never reuse serial numbers, serial
numbers are unique. So prior to printing the packing slip I want to
warn the shipping guy/gal a serial number may be incorrect.

I could brute force it and increment through the "to be shipped array"
and check each item against the table. But that is, as I said brute
force, and I am having to be concerned with system speed lately.

Thanks
Bob


My suggestion:

Load the shipped table as an associative array and then do an isset() on the $array[$serial_number] in question. Only load those rows that have the shipped status set the way you need.

-david-

.



Relevant Pages

  • Tricky explode(), help please!
    ... I am trying to parse and load a tab delimited file into a mysql ... When I load this information into the database, ... explodefunction to break this array down into its parts, ...
    (comp.lang.php)
  • Re: Tricky explode(), help please!
    ... When I load this information into the database, ... explodefunction to break this array down into its parts, ... and load output file when all rows have been ...
    (comp.lang.php)
  • Re: System.Drawing.Image.FromFile leaves file open longer than necessary: bug?
    ... load on the system when it finally does it by itself. ... > dispose the stream as soon as you are done reading it. ... database. ... stream out of the same array for copying into the picturebox, ...
    (microsoft.public.dotnet.framework.clr)
  • Re: SQL Server, MS Word and C#.
    ... You should be able to load your document into an array, ... > I want to insert some word files into the database and also be able to> retreive them. ... > 1) What DataType should the fiel be in the DB. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: KirbyBase
    ... creating objects from the database records was much easier. ... Hal, I don't know if you have had a chance to take a look at the beta yet, but I basically tried to implement a uniform way to specify one-to-one links, one-to-many links, and calculated fields in the ... I suppose it would in effect be embedding an array where all the ... My first couple of attempts at adding more complexity to KirbyBase did not honor this concept. ...
    (comp.lang.ruby)