Jump to content

[SOLVED] randon unique field name


jkkenzie

Recommended Posts

I would like to generate a unique name or text that does not match a particular field values: say i have a field called ProjectName:

and in the field list i have project1, project2 and project3, i would like to create something like project4 or anything else like xxgtdf  BUT should not match the others.

 

thanks

Joe

Link to comment
Share on other sites

In other words a unique identifier. Are you going to use it as a primary key for a table? If so, using INTEGER column with AUTO_INCREMENT is better choice.

If you need a column to contain unique values, create a UNIQUE index on it. Then whenever you try to insert a duplicate value, you;ll get a mysql error. So you can do

 

$success = FALSE;
while(!$success) {
$string = generateRandomString();  //you'll have to come up with code for this function
$query = "INSERT INTO table (ProjectName) VALUES ('$string')";
if(mysql_query($query)) $success = TRUE;
}

Link to comment
Share on other sites

No you dont understand.

A group of records will have one or the same name or id SAY:

 

id|Project | name  | details|

1 | x        | Kenya  | graph  |

2  | x      | uganda|  graph  |

3 | y      | Kenya  | graph2  |

4  | y      | uganda|  graph2  |

 

You realise the project has unique identifying field x or y: Unique in the sense that it identifies a GROUP of records.

 

I hope i am clear this time round.

 

thanks for your help.

 

Link to comment
Share on other sites

you are trying to use it as a foriegn key, so it is mandatory that it should have a master table may be "projects" where it is a primary key and hence unique too..so in addition to your table, you should have one more table called projects which would have following fields:

 

Table : projects

Fields

 

project_id - INT (auto-increment)

project_name - varchar

 

Then your table will be something like this

id|Project | name  | details|

1 | 1        | Kenya  | graph  |

2  | 1      | uganda|  graph  |

3 | 2      | Kenya  | graph2  |

4  | 2      | uganda|  graph2  |

Link to comment
Share on other sites

Actually my project doesnt aloow for that table to be made, it is supposed to be a one time data.

I wish i could store my results in a cache memory to be used by my graph when i move to the next page, but my calculations are alot.

 

I move through 4 pages carrying selected fields values in variables (POST) then on the forth page i use those data to calaculate two other values(which i put them to fields in my tblcalc) this two other values are created when my while statement loops and stores in $A and $C which i save in my tblcalc as i loop .

the project does not need the user creating a project name or project table, the data is fixed it is stored once. in a table tbldata, from which the user selects what needs to plotted on a graph.

here am trying to store in my temporary table tblcalc which data in it is deleted maybe after ten minutes, THAT IS WHY I NEEDED THE UNIQUE FIELD WHICH WOULD IDENTIFY THOSE SELECTED VALUES BY USER FOR ATLEAST 10 MINUTES THEN IT COULD BE DELETED.

 

thanks.

Joseph

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.