Code: Select all
function frelatededit($related){
global $r_opt;
$lenght = strlen($related);
$prefex = substr($related, 0, 2);
$relatedd_id = substr($related, 2, $lenght-2);
if (($prefex == "d_") or ($prefex == "p_")) {
$dbtable = "table1";
} elseif ($prefex == "g_") {
$dbtable = "table2";
} elseif ($prefex == "o_") {
$dbtable = "table3";
}
if ($prefex == "o_") {
$queryd = "SELECT * FROM `".$dbtable."` WHERE id=".$relatedd_id."";
$resultd = mysql_query($queryd);
$row = mysql_fetch_array($resultd);
$r_opt = "<option value="o_".$row['id']."">".$row['value']."</option>";
} else {
$queryd = "SELECT * FROM '".$dbtable."' WHERE `id`='".$relatedd_id."'";
$resultd = mysql_query($queryd);
$row = mysql_fetch_array($resultd);
$r_opt = "<option value="".$prefex.$row['id']."">".$row['name']."</option>";
}
return $r_opt;
}Inside the function, php would count how many characters there are, split the prefex ( eg "o_" without the quotes) and the id ( eg "37" without the quotes )
Then depending on the prefex, choose a database table name and use that table name in the query in the next section.
In the query, it basically should fetch the data from the table chosen in the previous section, where the table id equals the splitted-from-prefex id.
Now in theory, it should output something nice like
Code: Select all
<option value="o_37">whatever-name-is-assigned-to-id-37</option>Code: Select all
whatever-name-is-assigned-to-id-37