So basically I want to check a MySQL database
table to see if a certain number or string is present in a certain column (using PHP).
The reason for this is that each “member” added to my table is given a unique, random, 9-digit number between 100000000 and 999999999. However, I need to make sure that the PHP code doesn’t generate an ID that has already been given to some other member in the past. If it finds that the generated ID already exists, it will re-generate the number until it gets one that has not been previously used.
Now I’ve done some research and I’ve found questions similar to this, but none quite seem to answer this specific problem using PHP. Some have said to use INSTR (see second solution: MySQL query String contains), but I’m not quite sure how I could implement that into what I’m trying to do (it returns all rows (supposedly) where ‘string’ occurs in a column, but that doesn’t help. If it were how many times it occurs, then we would be on the right track). If this isn’t possible or very difficult to do, then I could also just read all the data in my specific column (see: How get all values in a column using PHP?) and then perform a regular PHP function somehow to search for my generated ID…and if it returns false then we don’t have to re-generate.
So the question is: How can I perform a function of sorts which returns true or false in regards as to whether or not ‘string’ (or number) is present in a certain MySQL table column (using PHP)? I’m also working with MySQLi, Procedural syntax…and I’m a relative beginner when it comes to MySQL and PHP.
Thanks in advance!