getting search results to appear as if in a table

A

Anonymous

Guest
Hi..

I have done a search database and I have got the results to come back correctly........ I would like to know how I get these results to appear as if in a table.....at the moment they are just appearing as lines of text......

here is my code:

<html>
<style type="text/css">

</style>

<body bgcolor="FF9422">
<a href="javascript:history.go(-1);">Go back to Search</a>
<p><font color="#FFFFFF"><b>The Intermediarys that are in Your Area Are Listed
Below...</b></font></p>
<p> </p>
<p>
<?php

mysql_connect (localhost, whatever, whatever);

mysql_select_db (intermediary);

if ($townorcounty == "")
{$townorcounty = '%';}

if ($county == "")
{$county = '%';}

$result = mysql_query ("SELECT * FROM members
WHERE (town LIKE '$townorcounty%'
OR county LIKE '$townorcounty%')
");

if ($row = mysql_fetch_array($result)) {

do {
print $row["name"];
print (" ");
print $row["town"];
print (" ");
print $row["county"];
print (" ");
print $row["tel"];
print (" ");
print $row["fax"];
print ("<p>");
} while($row = mysql_fetch_array($result));

} else {print "Sorry, no records were found!";}

?>
</p>
</body>
</html>
 
I don't know exactly what you mean, do you want you're result to be displayed in a table?? That would indeed be good for you're page layout. and the user wouldn't have to see the actual table:
html-example wich I use *VERY* often:
Code:
<table border=0>
<tr><td> cell-contents </td><td> another cell </td></tr>
</table>
Wich is simple html-code
border=0 will hide the borders of the table and thus hide that the information is in a table.
remember that you're creating html-code with php.....

karma_killer said:
if ($row = mysql_fetch_array($result)) {

do {
print $row["name"];
print (" ");
print $row["town"];
print (" ");
print $row["county"];
print (" ");
print $row["tel"];
print (" ");
print $row["fax"];
print ("<p>");
} while($row = mysql_fetch_array($result));

} else {print "Sorry, no records were found!";}
this piece of code works, but is not entirely up to coding standards (always a good idea to program that way, because others will be able to read you're code better.
I would have done it like this:
Code:
if (!mysql_num_rows($result)) {
     print('No search results');
}
else {
while ($row = mysql_fetch_array($result) do {
  print $row["name"];
  print (" ");
  print $row["town"];
  print (" ");
  print $row["county"];
  print (" ");
  print $row["tel"];
  print (" ");
  print $row["fax"];
  print ("<p>");
  }
}
as I said, you're code works also.

Greetz Daan
 
yes I do mean what you say............

where in my code would I actually put the bit that you have added?? the table bit

Also thanks for your example of how my code should look
 
depends a bit on how you want it to be displayed, if you want one row per result you can do something like this:
Code:
if (!mysql_num_rows($result)) {
     print('No search results');
}
else {
print('<table border=0>');
while ($row = mysql_fetch_array($result) do {
  print('<tr><td>');
  print $row["name"];
  print ("</td><td> ");
  print $row["town"];
  print ("</td><td> ");
  print $row["county"];
  print ("</td><td> ");
  print $row["tel"];
  print ("</td><td> ");
  print $row["fax"];
  print ("</td></tr>");
  }
print('</table>');
}
but you may want a result to be spread over more lines, wich will give a better result on machines working on a lower resolution.

You can find a html-tag-list here:
http://www.home.zonnet.nl/robschluter/htmltaglist/
 
thankyou very much for your help............maybe one day I will be able to do the same for other..... :).....then again...lol
 
your code does not seem to work it is coming back with a parse error

Parse error: parse error, unexpected T_DO in /wwwroot/up/Test/searchform.php on line 37
 
woops, forgot a little thing:
Code:
...
while ($row = mysql_fetch_array($result)) do { 
...

note the extra ")" behind the expression
 
this error ????

Parse error: parse error, unexpected T_PRINT, expecting T_WHILE in /wwwroot/up/Test/searchform.php on line 50

here is the code:

<html>
<style type="text/css">

</style>

<body bgcolor="FF9422">
<a href="javascript:history.go(-1);">Go back to Search</a>
<p><font color="#FFFFFF"><b>The Intermediarys that are in Your Area Are Listed
Below...</b></font></p>
<p> </p>
<p>
<?php

mysql_connect (localhost, tony, tony);

mysql_select_db (intermediary);

if ($townorcounty == "")
{$townorcounty = '%';}

if ($county == "")
{$county = '%';}

$result = mysql_query ("SELECT * FROM members
WHERE (town LIKE '$townorcounty%'
OR county LIKE '$townorcounty%')
");

if (!mysql_num_rows($result)) {
print('No search results');
}
else {
print('<table border=0>');
while ($row = mysql_fetch_array($result)) do {
print('<tr><td>');
print $row["name"];
print ("</td><td> ");
print $row["town"];
print ("</td><td> ");
print $row["county"];
print ("</td><td> ");
print $row["tel"];
print ("</td><td> ");
print $row["fax"];
print ("</td></tr>");
}
print('</table>');
}
?>
</p>
</body>
</html>
 
I'm going back to bed, because obviously, i'm still sleeping :cry: 8O :?
(it's 13:16 here)

Code:
while ($row = mysql_fetch_array($result)) {

man, do I feel stupid :?

one more thing, if you use the "code" and "quote" buttons you can make the same boxes as I do in posts, reads a lot easy-er

/me going out for some very-much-needed fresh air

Greetz
 
thanks.......that works fine...........I should have spotted those myself.....you may go to bed now........lol :)
 
Back
Top