Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

getting search results to appear as if in a table

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

getting search results to appear as if in a table

Postby karma_killer » Tue Aug 06, 2002 1:19 am

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">
<!--
body { font-family: Arial, Helvetica, sans-serif; font-size: 14px; font-weight: normal; color: #000033}
font { font-family: Arial, Helvetica, sans-serif; font-size: 14px; font-weight: normal; color: #000033}
-->
</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>&nbsp;</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>
karma_killer
New php-forum User
New php-forum User
 
Posts: 7
Joined: Tue Aug 06, 2002 12:04 am

Re: getting search results to appear as if in a table

Postby DoppyNL » Tue Aug 06, 2002 1:55 am

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: Select all
<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 wrote: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: Select all
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
DoppyNL
 

Postby karma_killer » Tue Aug 06, 2002 2:08 am

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
karma_killer
New php-forum User
New php-forum User
 
Posts: 7
Joined: Tue Aug 06, 2002 12:04 am

Re: getting search results to appear as if in a table

Postby DoppyNL » Tue Aug 06, 2002 2:19 am

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: Select all
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/
DoppyNL
 

Postby karma_killer » Tue Aug 06, 2002 2:23 am

thankyou very much for your help............maybe one day I will be able to do the same for other..... :).....then again...lol
karma_killer
New php-forum User
New php-forum User
 
Posts: 7
Joined: Tue Aug 06, 2002 12:04 am

Postby karma_killer » Tue Aug 06, 2002 2:38 am

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
karma_killer
New php-forum User
New php-forum User
 
Posts: 7
Joined: Tue Aug 06, 2002 12:04 am

Postby DoppyNL » Tue Aug 06, 2002 2:40 am

woops, forgot a little thing:
Code: Select all
...
while ($row = mysql_fetch_array($result)) do {
...


note the extra ")" behind the expression
DoppyNL
 

Postby karma_killer » Tue Aug 06, 2002 3:07 am

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">
<!--
body { font-family: Arial, Helvetica, sans-serif; font-size: 14px; font-weight: normal; color: #000033}
font { font-family: Arial, Helvetica, sans-serif; font-size: 14px; font-weight: normal; color: #000033}
-->
</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>&nbsp;</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>
karma_killer
New php-forum User
New php-forum User
 
Posts: 7
Joined: Tue Aug 06, 2002 12:04 am

Postby DoppyNL » Tue Aug 06, 2002 3:15 am

I'm going back to bed, because obviously, i'm still sleeping :cry: 8O :?
(it's 13:16 here)

Code: Select all
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
DoppyNL
 

Postby karma_killer » Tue Aug 06, 2002 3:21 am

thanks.......that works fine...........I should have spotted those myself.....you may go to bed now........lol :)
karma_killer
New php-forum User
New php-forum User
 
Posts: 7
Joined: Tue Aug 06, 2002 12:04 am


Return to PHP coding => General

Who is online

Users browsing this forum: Google Feedfetcher and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron