|
Posted by kennthompson on 02/27/07 22:24
On Feb 27, 12:45 pm, "J.O. Aho" <u...@example.net> wrote:
> kennthomp...@gmail.com wrote:
> > No. That won't work either. I need to add one more thing. To make the
> > stable version work I had to identify the old table name as global. I
> > think this looks simpler than it really is. I thought a simple
> > variable name could be passed as a table name, but there must be some
> > mysql code that allows it.
>
> Can you post the whole code you actually are using?
>
> for a code like
>
> function functionname($tablename) {
> $query="SELECT * FROM ".$tablename;
> $result=mysql_query($query);
> while($row=mysql_fetch_array($result)) {
> /* do what you do */
> }
>
> }
>
> will work fine, as long as the variable you use as an argument for the
> function does have a value and that there is a such table in your database.
>
> $thistable="a_table";
> functionname($thistable);
>
> --
>
> //Aho
function fms_get_table($tableName, $label, $name, $var)
{
if (is_array($var))
{
$var = $var[$name];
}
fms_open_table_row();
fms_open_table_col();
echo "$label:";
fms_close_table_col();
fms_close_table_row();
echo "<SELECT size=1 name=project>\n";
$result2 = fms_mysql_query("SELECT * FROM '{$tableName}'");
if ($result2)
{
$row2 = mysql_fetch_array($result2);
if (strlen($row2["projectName"]) > 0)
{
echo "<OPTION VALUE=" . $row2["keyid"] . ">" .
$row2["projectName"] . "\n";
}
}
else
{
echo "<option> \n";
}
$result2 = fms_mysql_query("select * from '{$tableName}' order by
keyid asc");
for ($i = 0; $i < mysql_num_rows($result2); $i++)
{
$row2 = mysql_fetch_array($result2);
if (strlen($row2["projectName"]) > 0)
{
echo "<OPTION VALUE=" . $row2["keyid"] . ">" .
$row2["projectName"] . "\n";
}
}
echo "</SELECT>\n";
fms_close_table_col();
fms_close_table_row();
}
/* Calling script: an edit form */
$query = "select * from $tableFields where keyid = '$keyid'";
$result = mysql_query($query);
if ($result)
{
$row = mysql_fetch_array($result);
}
fms_break(1);
fms_open_center();
fms_open_form("edit", "updateField.php", "post");
fms_open_table(0, "#eeeeee", "", 2, 2);
fms_hidden("keyid", $row);
fms_get_table($tableTarget, "Project", "project", $row);
fms_get_value("Label", "label", 60, $row);
fms_get_value("Field", "field", 60, $row);
fms_get_value("Type", "type", 60, $row);
fms_get_value("Parameters", "parameters", 60, $row);
fms_get_value("Attributes", "attributes", 60, $row);
fms_get_value("Extra", "extra", 60, $row);
fms_get_value("FMS", "fms", 60, $row);
fms_get_value("Cols", "cols", 10, $row);
fms_get_value("Rows", "rows", 10, $row);
fms_close_table();
fms_break(1);
fms_submit("UPDATE");
fms_submit("DELETE");
fms_submit("DUPLICATE");
fms_close_form();
fms_close_center();
/* mysql connection */
$host = "localhost";
$user = "";
$password = "";
$database = "";
$tableTarget = "php_generator_targets";
$tableFields = "php_generator_data_fields";
$link = mysql_pconnect( $host, $user, $password );
if(!$link)
{
echo "Did not connect.";
}
else
{
mysql_select_db($database);
if(mysql_errno())
{
echo mysql_errno() . ":" . mysql_error();
exit;
}
}
/* Main */
A shell gets the mysql connection, and manipulates the display. The
edit form tried to extract information from another table. It works
fine if I write a piece of code for each call, but I want the same
function to work for a number of database tables. But when I tried
passing the table name -- to my surprise it did not work. I've tried
numerous variations without success.
Too, thanks for your time. Maybe you can solve my problem. I'm trying
to write a php code generator, sort of a php on rails where the script
asks a few simple questions, and from that information an entire site
is created. This is not a commercial venture -- just something to save
me a lot of time.
Navigation:
[Reply to this message]
|