Display MySql query results in table

Posted on 2009-05-22
Medium Priority
Last Modified: 2013-12-12
I have a query results page 1.php which returns records line by line. How can I make it display in a table? Below is the code for 1.php. Scripts for the search page Radius.html also enclosed.

Appreciate any help.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
.style1 {color: #0033FF}
.style14 {font-family: "book Antiqua"; font-size: 24pt;}
.style15 {font-family: "segoe Print"; font-size: small;}
.style2 {      color: #00FF00;
      font-family: "script MT Bold";
      font-size: larger;
.style5 {font-family: "book Antiqua"}
.style22 {      color: #00FF00;
      font-family: "script MT Bold";
      font-size: 36px;
.style20 {font-family: "book Antiqua";
      font-size: 36pt;
      color: #0033FF;
.style21 {font-size: 24pt}
.style3 {      font-family: "book Antiqua", "script MT Bold";
      font-size: 24pt;
      color: #0033FF;



   DEMO for using the zipcode PHP class. By: Micah Carrick
   Questions?  Comments?  Suggestions?  email@micahcarrick.com

require_once('zipcode.php');      // zip code class

// Open up a connection to the database.  The sql required to create the MySQL
// tables and populate them with the data is in the /sql subfolder.  You can
// upload those sql files using phpMyAdmin or a MySQL prompt.  You will have to
// modify the below information to your database information.  
mysql_connect('localhost','user','pwd') or die(mysql_error());
mysql_select_db('mydb') or die(mysql_error());

// Below is an example of how to calculate the distance between two zip codes.

$Radius = $_REQUEST['Radius'];
$Destination = $_REQUEST['Destination'];

$z = new zipcode_class;

$zips = $z->get_zips_in_range($Destination, $Radius, _ZIPS_SORT_BY_DISTANCE_ASC, true);
$zipcodes = array_keys($zips); // this fetches all the zip codes in the $zips variable
$zip1 = implode(",",$zipcodes);  

//echo $zip1;  
mysql_connect('localhost','user','pwd') or die(mysql_error());
mysql_select_db('db') or die(mysql_error());
        //$sql = "select * from DEALER where ZIP = '$key'";  
        $sql = "select * from Suppliers2, Boxes where Suppliers2.Zip in (".$zip1.") AND MATCH (Boxes.Description) AGAINST ('$searchterm') AND Boxes.SID = Suppliers2.SID";  
        $result = mysql_query($sql) or die (mysql_error());  
          $num_rows = mysql_num_rows($result);  
echo "<p><b>Number of suppliers found within the specified radius of your destination: </b>".$num_rows."</p>";
          if($num_rows == 0) {  
               echo "Sorry. No records found. Please expand your radius or refine your creteria. If problem persists, please contact us.";  
          else {  

        while($myrow = mysql_fetch_array($result))  
                  $suppliername = $myrow['Supplier_Name'];
            $supplierproductcode = $myrow['Supplier_Product_Code'];
                  $description = $myrow['Description'];
                  $city = $myrow['City'];  
            $state = $myrow['State'];  
            $address = $myrow['Address'];  
                  $tollfree = $myrow['Tollfree'];
                  $phone = $myrow['Phone'];
                  $fax = $myrow['Fax'];
                  $email = $myrow['Email'];
                  $website = $myrow['Website'];
            $zipcode = $myrow['Zip'];  

            $miles = $zips[$zipcode]; // return the value for key with the zip code in it.
                  echo "<b>Supplier_Name: </b>", $suppliername;
            echo "<br>";
                  echo "<b>Supplier_Product_Code: </b>", $supplierproductcode;    
            echo "<br>";
                  echo "<b>Description: </b>", $description;
            echo "<br>";
            echo "<b>Tollfree: </b>", $tollfree;  
            echo "<br>";  
            echo "<b>Phone: </b>", $phone;  
            echo "<br>";  
            echo "<b>Fax: </b>", $fax;  
            echo "<br>";  
            echo "<b>E-mail: </b>", $email;
                  echo "<br>";
            echo "<b>Website: </b>", $website;  
            echo "<br>";  
            echo "<b>Address: </b>", $address;  
            echo "<br>";                     
            echo "<b>Distance: </b>$miles miles from your destination zip code $Destination";  // changed $value to $miles
            echo "<br><br>";  


This is the search page Radius.html
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>


  <div id="mainContent">
    <form id="form2" name="form2" method="post" action="1.php">
      <p>Please enter some key words of the products you look for (at least 4 characters)</p>
      <p><br />
        <input name="searchterm" type="&quot;text&quot;" size="60"/>
          <select name="Radius" id="Radius">
            <option value="50">50</option>
            <option value="100" selected="selected">100</option>
            <option value="150">150</option>
            <option value="200">200</option>
            <option value="250">250</option>
            <option value="300">300</option>
            <option value="500">500</option>  
            <option value="700">700</option>                      
        miles from
  <label>Destination Zip
  <input name="Destination" type="text" id="Destination" maxlength="7" />
      <p> <br />
          <input type="submit" name="submit" value="Search"/>
          <input type="reset" name="Reset button" id="Reset button" value="Reset" />
Question by:DomerBill
LVL 14

Accepted Solution

Aamir Saeed earned 2000 total points
ID: 24453989

Author Comment

ID: 24478455
please delete this question and solutions from the knowledge base. i just realized the codes i provided contain some private information that i shall never show to the public. please remove them all immediately.

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

587 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question