//lets get the auto name set
$accepted = 0;
$sql = mysql_query("SELECT * FROM ".TBL_FACTIONS." WHERE f_name='no_name'");
$numrows = mysql_num_rows($sql);
//default name 1
if($numrows == 0){ $auto_name = 'no_name'; $accepted = 1;}
//default name 2
if ($accepted == 0){ $sql = mysql_query("SELECT * FROM ".TBL_FACTIONS."
WHERE f_name='no_name[02]'"); $numrows = mysql_num_rows($sql);
if($numrows == 0){$auto_name = 'no_name[02]'; $accepted = 1;} }
//default name 3
if ($accepted == 0){ $sql = mysql_query("SELECT * FROM ".TBL_FACTIONS."
WHERE f_name='no_name[03]'"); $numrows = mysql_num_rows($sql);
if($numrows == 0){$auto_name = 'no_name[03]'; $accepted = 1;} }
//default name 4
if ($accepted == 0){ $sql = mysql_query("SELECT * FROM ".TBL_FACTIONS."
WHERE f_name='no_name[04]'"); $numrows = mysql_num_rows($sql);
if($numrows == 0){$auto_name = 'no_name[04]'; $accepted = 1;} }
//default name 5
if ($accepted == 0){ $sql = mysql_query("SELECT * FROM ".TBL_FACTIONS."
WHERE f_name='no_name[05]'"); $numrows = mysql_num_rows($sql);
if($numrows == 0){$auto_name = 'no_name[05]'; $accepted = 1;} }
//default name 6
if ($accepted == 0){ $sql = mysql_query("SELECT * FROM ".TBL_FACTIONS."
WHERE f_name='no_name[06]'"); $numrows = mysql_num_rows($sql);
if($numrows == 0){$auto_name = 'no_name[06]'; $accepted = 1;} }
//-->update faction table
mysql_query("INSERT INTO ".TBL_FACTIONS." (f_id, f_name, f_status,
f_boss, f_uboss, f_rhm, f_lhm, f_r1, f_r2, f_nat,
f_funds, f_fmj, f_score,f_footer)
VALUES ('','$auto_name','0','$username','','','','','','gb','0','0','0','')");
This checks my MySQL database to create an automatic name for a created row in the table. It works fine like this, but i think there has to be an easier, more efficient, way of achieving the same output?
Also, how do I add a constant loop through so that it always creates a no_name[XX] insertion?