function frelatededit($related){
$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;
}
Basically, what I am trying to do here is pass a variable to the function called $related, and a sample value of $related would be "o_37" without the quotes.
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
<option value=\"o_37\">whatever-name-is-assigned-to-id-37</option>
but instead, its showing me only
whatever-name-is-assigned-to-id-37
I spent about an hour going through the code, but I cant seem to find the mistake 🙁...may be I am just too fraustrated. If you see whats wrong with the code, please post here 🙂