473,698 Members | 2,602 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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

Apr 17 '06 #1
2 2917
rj***********@g mail.com 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-

Apr 17 '06 #2

rj***********@g mail.com wrote:
I want to check if any of the items in a PHP array exist in a MySQL
table.


$query = "SELECT COUNT(*) FROM my_table WHERE serialno IN (".implode(' ,
', $serials).")";

Apr 17 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2189
by: Boris ©avc | last post by:
I have a page and a sponsor. Every time a user click on a banner from our sponsor their webpage is opened. I'd like to reward these users, but how to check who clicked on a banner. I can't do anything on sponsor's webpage? Thanks for helping, Boris ©avc
2
3386
by: Vic Spainhower | last post by:
Hello, I am new to php and MySQL and I'm attempting to run a select query on a MySQL database which is working fine except prior to displaying the table with the results from the select query it displays 1 line for each row in the database containing only the word Array. This is then followed by the correct results in the constructed table. I am not storing the string "Array" in my table. Following is the PHP code for constructing the...
8
2381
by: Ryan Sullivan | last post by:
I am using a PHP calendar with MySQL backend. For some reason, when you click on an event in the calendar (which brings up a pop-up window), there is a scrambled mess before the description. I have deleted the tables and recreated them, but this has not solved the problem. Could someone take a quick look at my site and help me out? It's at: http://dcavello.phenominet.com/calendar Thanks! Ryan --
6
18762
by: Ian Davies | last post by:
Hello all I have the following PHP script to place records from my MySql db into a table. However I now wish users to beable to select the multiple records from the table and on clicking a button the selected records are stored to another table in my db. I have started by including a check box in the first column but dont know the code necessary to check all the row in the table and copy the records of those boxes thats ticked Can anyone...
5
1471
by: Chris H | last post by:
Okay, I am trying to us a varialble with a list of number values as my data for an array, yet when I do this it doesnt return any values from the array, i was able to temporarily fix the proble by just doing s normal array setup in my function, but the problem is I want the ability to have teh array values to be changed easily in a varibale style config/include file... Here is the code i am working with... ...
2
1736
by: cpptutor2000 | last post by:
Could some PHP guru please help me? I have very standard PHP - MySQL application that reads in some data from a table and for each row, puts a check box at the start of the row. Now the check boxes are variable in number, depending only on the number of current records in the database table. My question is: how do I count the number of check boxes rendered at any one time. I tried having a global variable and incrementing it each time a...
12
1876
by: Martien van Wanrooij | last post by:
I have been using for a while a class to create photo albums. Shortly, an array of photo's is declared, initially they are shown as thumbnails, by clicking on a thumbnail a larger photo is shown and there are links to the thumbnail list but also to the previous and next photo as the function remembers which position the photo has got in the array. Now I tried to do the same thing by retrieving photos from a mysql database (which is much...
2
1545
by: deepika1 | last post by:
hi , i wrote a code for to delete the particular rows in a table using check boxes.But in that i select the particular rows and click on the delete button these rows didn't delete.plz check it what's the problem in that code. <?php $host="localhost"; // Host name $username="root"; // Mysql username $password=" "; // Mysql password
2
14494
by: mouac01 | last post by:
Let's say I have this MySQL table. Year Region Amount 2007 West 100 2007 East 200 2007 North 300 2007 South 400 2008 West 500 2008 East 600 2008 North 700
0
8680
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8609
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9169
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8899
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5861
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4371
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2335
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.