Querry MySQL Database and Return Multiple Results
Posted: Mon Sep 06, 2010 9:52 am
Hi Everyone,
Well I have a bit of a problem... I have created a search page that I would like to return results from my MySQL database. However for some reason I can not get my page to display the results. Instead I am getting an error page. Below is the code I am using:
In addition to this, should I wish for a user to be able to edit the returned results by clicking a link, how would I do that?
Well I have a bit of a problem... I have created a search page that I would like to return results from my MySQL database. However for some reason I can not get my page to display the results. Instead I am getting an error page. Below is the code I am using:
In addition to this, should I wish for a user to be able to edit the returned results by clicking a link, how would I do that?
Code: Select all
<?php
session_start();
?>
<link rel="stylesheet" type="text/css" href="css/layout.css"/>
<html>
<?php
$record = $_POST['record'];
echo "<p>Search results for: $record<br><BR>";
$host = "localhost";
$login_name = "root";
$password = "P@ssword";
//Connecting to MYSQL
MySQL_connect("$host","$login_name","$password");
//Select the database we want to use
mysql_select_db("schedules_2010") or die("Could not find database");
$result = mysql_query("SELECT *
FROM schedule_september_2010
WHERE
champ LIKE '%$record%' ")
or die(mysql_error());
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row
echo "<br><p>Your Schedule<BR></p><br>";
echo "<table border=1>\n";
echo "<tr>
<td bgcolor=#444444 align=center><p><b>Champ</p></td>
<td bgcolor=#444444 align=center><p><b>Date</p></td>
<td bgcolor=#444444 align=center><p><b>Start Time</p></td>
<td bgcolor=#444444 align=center><p><b>End Time</p></td>
<td bgcolor=#444444 align=center><p><b>Department</p></td>
<td bgcolor=#444444 align=center><p><b>First Break</p></td>
<td bgcolor=#444444 align=center><p><b>Second Break</p></td>
<td bgcolor=#444444 align=center><p><b>Login ID</p></td>
</tr>\n";
do {
printf("<tr>
<td><p>%s</p></td>
<td><p>%s</p></td>
<td><p>%s</p></td>
<td><p>%s</p></td>
<td><p>%s</p></td>
<td><p>%s</p></td>
<td><p>%s</p></td>
<td><p>%s</p></td>
</tr>\n"
, $row["champ"]
, $row["date_time"]
, $row["start_time"]
, $row["end_time"]
, $row["department"]
, $row["first_break"]
, $row["second_break"]
, $row["login_id"]
);
} while ($row = mysql_fetch_array($result));
echo "</table>\n";
} else {
echo "$champ No Records Found";
}
mysql_free_result($result);
mysql_close($con);
?>
</html>