Build a dinamyc code with mysql_field_name query.
Posted: Mon Feb 04, 2008 12:39 pm
Hello again, i have this code
This code format my datagrid, column by column, now. the goal is writte a php code that gets new field name from the mysql database and inert this in the end... i think like this
Maybe i need a loop that increment "$name1"?... how i can do this. thanks
Code: Select all
$objGrid -> FormatColumn("id", "ID", 10, 10, 0, "10", "center", "integer");
$objGrid -> FormatColumn("alumno_name", "Nombre", 30, 30, 0, "105", "left");
$objGrid -> FormatColumn("alumno_apellido", "Apellido", 30, 30, 0, "110", "left");
$objGrid -> FormatColumn("alumno_ano", "Ano", 3, 3, 0, "30", "center");
$objGrid -> FormatColumn("alumno_sec", "Secc", 5, 5, 0, "30", "left");
$objGrid -> FormatColumn("curso01", "curso01", 5, 5, 0, "30", "left");
Code: Select all
$con = mysql_connect("localhost", "db_test", "test");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db("table_test",$con);
$sql = "SELECT * from authors";
$result = mysql_query($sql,$con);
$name1 = mysql_field_name($result, 2);
$objGrid -> FormatColumn("id", "ID", 10, 10, 0, "10", "center", "integer");
$objGrid -> FormatColumn("alumno_name", "Nombre", 30, 30, 0, "105", "left");
$objGrid -> FormatColumn("alumno_apellido", "Apellido", 30, 30, 0, "110", "left");
$objGrid -> FormatColumn("alumno_ano", "Ano", 3, 3, 0, "30", "center");
$objGrid -> FormatColumn("alumno_sec", "Secc", 5, 5, 0, "30", "left");
$objGrid -> FormatColumn("curso01", "curso01", 5, 5, 0, "30", "left");
[b]$objGrid -> FormatColumn("$name1", "$name1", 5, 5, 0, "30", "left");[/b]