i have a column in mysql called origin which is type integer(not ascending or descending). All rows have an origin assigned to them can't be duplicated... e.g. two rows with the same origin(integer).


when inserting a new row. Just say row 1 has origin 15 and i'm inserting a new row with the same origin(15) how do i go to the next available integer to prevent a duplicate origin?

before you insert, do a query for the origin number that you are about to insert. If the query comes up empty, you can insert the number.

before you insert, do a query for the origin number that you are about to insert. If the query comes up empty, you can insert the number.

i've done the part if it comes up empty..

if it is doesn't come up empty how do i insert an available origin number(not used by any in the table)?

Maybe i'm not understanding the issue?
I don't know where the "available origins" come from.
My thought was, that you HAD one and wanted to make sure it wasn't already there.
You do a "select" where origin = $myNewTestOrigin. If it's empty, then your test origin can be put into a second "insert" query and insert it..
It's two queries.
Am I missing the point? ( no pun intended)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.