Trip59
12-28-04, 03:20 AM
Hey all, I need some help. After looking through a couple hundred articles on the web, as well as the php and mysql sites, I am rather confused. What I need is simple, I need a script that does two things,
writes four fields to a table from a form, call them fieldA, fieldB, fieldC, fieldD
queries and returns the result to four variables that I can put into a page where I need them.
The following is what I got from php.net, it works fine (others I tried gave me unknown T_VARIABLE on line... errors).
The problem is, I need the results returned in a way that I can place them into html where they are needed, not just into a table.
<?php
// Connecting, selecting database
$link = mysql_connect('mysql_host', 'mysql_user', 'mysql_password')
or die('Could not connect: ' . mysql_error());
echo 'Connected successfully';
mysql_select_db('my_database') or die('Could not select database');
// Performing SQL query
$query = 'SELECT * FROM my_table';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
// Printing results in HTML
echo "<table>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "\t<tr>\n";
foreach ($line as $col_value) {
echo "\t\t<td>$col_value</td>\n";
}
echo "\t</tr>\n";
}
echo "</table>\n";
// Free resultset
mysql_free_result($result);
// Closing connection
mysql_close($link);
?>
I really appreciate the help, this is driving me nuts.
writes four fields to a table from a form, call them fieldA, fieldB, fieldC, fieldD
queries and returns the result to four variables that I can put into a page where I need them.
The following is what I got from php.net, it works fine (others I tried gave me unknown T_VARIABLE on line... errors).
The problem is, I need the results returned in a way that I can place them into html where they are needed, not just into a table.
<?php
// Connecting, selecting database
$link = mysql_connect('mysql_host', 'mysql_user', 'mysql_password')
or die('Could not connect: ' . mysql_error());
echo 'Connected successfully';
mysql_select_db('my_database') or die('Could not select database');
// Performing SQL query
$query = 'SELECT * FROM my_table';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
// Printing results in HTML
echo "<table>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "\t<tr>\n";
foreach ($line as $col_value) {
echo "\t\t<td>$col_value</td>\n";
}
echo "\t</tr>\n";
}
echo "</table>\n";
// Free resultset
mysql_free_result($result);
// Closing connection
mysql_close($link);
?>
I really appreciate the help, this is driving me nuts.