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
https://forums.phpfreaks.com/topic/130571-solved-randon-unique-field-name/
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;
}

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.

 

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  |

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

Archived

This topic is now archived and is closed to further replies.

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