Uniq ID via PHP Script
Posted: Mon Aug 18, 2014 10:18 pm
Following the hints given in
http://forums.nubuilder.cloud/viewtopic.p ... qid#p12662
I wanted to create a generic form where I can specify the table name to be modified via PHP script.
1. Criteria form looks like this
I am trying to use the name of the table as a Hash Variable.
When I "Run PHP Code" nothing happens. No error message either.
Can you help me to figure out what I am doing wrong here please?
http://forums.nubuilder.cloud/viewtopic.p ... qid#p12662
I wanted to create a generic form where I can specify the table name to be modified via PHP script.
1. Criteria form looks like this
2. PHP CodeCode: addunique
Description: select the table to be modified for uniqid
Table: addunique
Primary Key: addunique_tablename
SQL: select * from addunique
3. PHP CodeCode : AlterUniqID
Description : Alter a table to add uniqid field
Group : admin
Criteria Form : addunique
Allow Non Secure Access : Yes
Code: Select all
echo 'Starting to alter the table';
nuRunQuery('ALTER TABLE #addunique_tablename# ADD #addunique_tablename#_id VARCHAR(25) NOT NULL FIRST, ADD id INT NOT NULL AUTO_INCREMENT PRIMARY KEY AFTER account_id'); //-- this auto populates id with numbers then
$t = nuRunQuery('SELECT * FROM #addunique_tablename#');
while($r = db_fetch_object($t)){
$id = nuID();
nuRunQuery("UPDATE #addunique_tablename# SET #addunique_tablename#_id = '$id' WHERE id = '$r->id'"); //-- update account_id to a unique string (better in so many ways than using numbers)
}
nuRunQuery("ALTER TABLE #addunique_tablename# DROP id");
nuRunQuery("ALTER TABLE #addunique_tablename# ADD PRIMARY KEY(#addunique_tablename#_id)");
print 'Done!';
When I "Run PHP Code" nothing happens. No error message either.
Can you help me to figure out what I am doing wrong here please?