Jump to content


Photo

Noob - Formatting search results in a table


  • Please log in to reply
3 replies to this topic

#1 kc9cdq

kc9cdq
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 31 May 2006 - 03:57 PM

Hi everyone:

I'm just getting starting in PHP and MySQL and I'm stuck on something. I have a database search result page that is returning the proper results, but I'm having trouble figuring out how to format the results to make them more readable. Here's what I have so far:

<?php
require 'calinc.php';
$searchstr = $_POST['initials'];
function displayadds($result)
{

print "<center><h1>Your Results</h1></center>";
print "\n<TABLE>\n<tr>\n" .
"\n\t<th><b>School Name</b></th>" .
"\n\t<th><b>Location</b></th>" .
"\n\t<th><b>Date</b></th>" .
"\n\t<th><b>Time</b></th>" .
"\n\t<th><b>Number Working</b></th>" .
"\n\t<th><b>Notes</b></th>" .
"\n</tr>";

while ($row = @ mysql_fetch_row($result))
{
print "\n<tr>";
foreach($row as $data)
print "\n\t<td> {$data} </td>";
print "\n</tr>";
}
print "\n</table>\n";
}
$query = "SELECT SCHOOL, LOCATION, DATE, TIME, NOWORK, NOTES
FROM calendar
WHERE SB1 LIKE '%$searchstr%' or SB2 LIKE '%$searchstr%' or SB3 LIKE '%$searchstr%' or SB4 LIKE '%$searchstr%' or SB5 LIKE '%$searchstr%' or SB6 LIKE '%$searchstr%' or SB7 LIKE '%$searchstr%' or SB8 LIKE '%$searchstr%' or SB9 LIKE '%$searchstr%' or SB10 LIKE '%$searchstr%'";

if (!($connection = @ mysql_connect($hostname, $username, $password)))
die("Unable to Connect");

if (!(mysql_select_db($databaseName, $connection)))
showerror();

if (!($result = @ mysql_query ($query, $connection)))
showerror();

displayadds($result);
?>


Any input you have would be greatly appreciated. I'm looking to add table borders and increase the cell padding and spacing etc. Thanks!!

#2 rathfon

rathfon
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 31 May 2006 - 05:13 PM

<?php
require 'calinc.php';
$searchstr = $_POST['initials'];
function displayadds($result)
{

print "<center><h1>Your Results</h1></center>";
print "\n<TABLE>\n<tr>\n" .
"\n\t<th><b>School Name</b></th>" .
"\n\t<th><b>Location</b></th>" .
"\n\t<th><b>Date</b></th>" .
"\n\t<th><b>Time</b></th>" .
"\n\t<th><b>Number Working</b></th>" .
"\n\t<th><b>Notes</b></th>" .
"\n</tr>";

while ($row = @ mysql_fetch_row($result))
{
print "\n<tr>";
foreach($row as $data)
print "\n\t<td> {$data} </td>";
print "\n</tr>";
}
print "\n</table>\n";
}
$query = "SELECT SCHOOL, LOCATION, DATE, TIME, NOWORK, NOTES
FROM calendar 
WHERE SB1 LIKE '%$searchstr%' or SB2 LIKE '%$searchstr%' or SB3 LIKE '%$searchstr%' or SB4 LIKE '%$searchstr%' or SB5 LIKE '%$searchstr%' or SB6 LIKE '%$searchstr%' or SB7 LIKE '%$searchstr%' or SB8 LIKE '%$searchstr%' or SB9 LIKE '%$searchstr%' or SB10 LIKE '%$searchstr%'";

if (!($connection = @ mysql_connect($hostname, $username, $password)))
die("Unable to Connect");

if (!(mysql_select_db($databaseName, $connection)))
showerror();

if (!($result = @ mysql_query ($query, $connection)))
showerror();

displayadds($result);
?>

First of all, you can use HTML in PHP files it is used the same way, so all those 'prints' are unnecessary. As far as I can tell, without running it, I see that you are slapping the results into a few tablerows. If you could take a picture of the results you get, and specify what you don't like about it, that'd be great and I could help you a lot easier if I knew what you wanted. If you don't have a host for files just upload here [a href=\"http://www.rathfun.com\" target=\"_blank\"]rathfun[/a].

#3 kc9cdq

kc9cdq
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 31 May 2006 - 09:42 PM

[!--quoteo(post=378771:date=May 31 2006, 01:13 PM:name=rathfon)--][div class=\'quotetop\']QUOTE(rathfon @ May 31 2006, 01:13 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
<?php
require 'calinc.php';
$searchstr = $_POST['initials'];
function displayadds($result)
{

print "<center><h1>Your Results</h1></center>";
print "\n<TABLE>\n<tr>\n" .
"\n\t<th><b>School Name</b></th>" .
"\n\t<th><b>Location</b></th>" .
"\n\t<th><b>Date</b></th>" .
"\n\t<th><b>Time</b></th>" .
"\n\t<th><b>Number Working</b></th>" .
"\n\t<th><b>Notes</b></th>" .
"\n</tr>";

while ($row = @ mysql_fetch_row($result))
{
print "\n<tr>";
foreach($row as $data)
print "\n\t<td> {$data} </td>";
print "\n</tr>";
}
print "\n</table>\n";
}
$query = "SELECT SCHOOL, LOCATION, DATE, TIME, NOWORK, NOTES
FROM calendar 
WHERE SB1 LIKE '%$searchstr%' or SB2 LIKE '%$searchstr%' or SB3 LIKE '%$searchstr%' or SB4 LIKE '%$searchstr%' or SB5 LIKE '%$searchstr%' or SB6 LIKE '%$searchstr%' or SB7 LIKE '%$searchstr%' or SB8 LIKE '%$searchstr%' or SB9 LIKE '%$searchstr%' or SB10 LIKE '%$searchstr%'";

if (!($connection = @ mysql_connect($hostname, $username, $password)))
die("Unable to Connect");

if (!(mysql_select_db($databaseName, $connection)))
showerror();

if (!($result = @ mysql_query ($query, $connection)))
showerror();

displayadds($result);
?>

First of all, you can use HTML in PHP files it is used the same way, so all those 'prints' are unnecessary. As far as I can tell, without running it, I see that you are slapping the results into a few tablerows. If you could take a picture of the results you get, and specify what you don't like about it, that'd be great and I could help you a lot easier if I knew what you wanted. If you don't have a host for files just upload here [a href=\"http://www.rathfun.com\" target=\"_blank\"]rathfun[/a].
[/quote]

Thanks for the reply. I'm not sure how to attach a file here, but you can view the results here: [a href=\"http://www.grayteamers.com/results.php.htm\" target=\"_blank\"]http://www.grayteamers.com/results.php.htm[/a] I would like to have cell borders (essentially a grid around each cell) and add some cell padding. It doesn't have to be fancy, I just want it to be a little more readable than it is now. I would also love to see an example of the code without the print commands if that makes life easier. Thanks!!!


#4 kc9cdq

kc9cdq
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 01 June 2006 - 03:30 PM

Thanks to everyone for looking, but I think I've figured out what I needed.... for now

-Keith





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users