Retrieving from a database
Posted: Wed Mar 12, 2003 5:44 am
Please help. I am trying to retrieve and display certain fields from a row in a MySQL databse using php.
I do it the following way:
This works, but what I need to do is be able to put each field retrieved into a table with headings I have created. Is there no way that I can chage each field retrieved into a variable so that I can echo them where I want them?
I'm new to programming. Please help!!
Regards
I do it the following way:
Code: Select all
$query ="select emp_id, surname, name, tel_no from user_data where user_data.emp_id = '$emp_id1'";
}
//User information
$result = mysql_query($query) or
die (mysql_error());
if (mysql_num_rows($result) == 0)
{
include ("../helpdesk/newuser/form.php");
} else
{
$number_cols = mysql_num_fields($result);
echo "<table border = 1>\n";
echo "<tr align=center>\n";
for ($i=0; $i<$number_cols; $i++)
{
echo "<th>" . mysql_field_name($result, $i). "</th>\n";
}
echo "</tr>\n";
while ($row = mysql_fetch_row($result))
{
echo "<tr align=left>\n";
for ($i=0; $i<$number_cols; $i++)
{
echo "<td>";
if (!isset($row[$i]))
{include("../newuser/form.php");}
else
{echo $row[$i];}
}
echo "</tr>\n";
}
echo "</table>";I'm new to programming. Please help!!
Regards