开发者

Creating a contact list from SQL Database

I am looking to query my database based on what the user would like to search by: Ex. (Zip, City, State, Name, Etc Etc). Let's say I search by zip code, and there are 2 results in my SQL for that zip code.

I would like the results to be displayed in the following format on my webpage:

Company Name
Address
City, State Zip
Contact Us Link                     Link to Another Page

I use the following code for something similar but I display the results in a table with check-boxes.

    <?php
        while ($row = mysql_fetch_assoc($result))
        {
            echo '<tr><td>';
            echo '<input type="checkbox" name="selected[]" value="'.$row['order_number'].'"/>';
            echo '</td>';
            foreach ($开发者_高级运维row as $key => $value)
                echo '<td>'.htmlspecialchars($value).'</td>';
            echo '</tr>';
        }
    ?>

I really would like to display the results of the search in the format I explained above. I am lost on how to get the results I want. Any help is much appreciated!!

Thanks

Would it be possible to do this as well:

If the Company Name row in my SQL is blank/empty, skip over that row/entry and go to the next.


What you could do, is pull each piece of information individually from the resulting row (change the fields based on what you pull from the table):

while($row = mysql_fetch_assoc($result))
{
   echo htmlspecialchars($row['comp_name']) . '<br />';
   echo htmlspecialchars($row['Address']) . '<br />';
   echo $row['city'] . ', ' . $row['zip'] . '<br />';
   echo '<a href="mailto:' . $row['contact'] . '">Contact us</a><a href="index.php">Some link</a>';//If it's an email
}

or for table output

while($row = mysql_fetch_assoc($result))
{
   echo '<table>'
   echo '<tr><td colspan="2">' . htmlspecialchars($row['comp_name']) . '</td></tr>';
   echo '<tr><td colspan="2">' . htmlspecialchars($row['Address']) . '</td></tr>';
   echo '<tr><td colspan="2">' . $row['city'] . ', ' . $row['zip'] . '<br />';
   echo '<tr><td><a href="mailto:' . $row['contact'] . '">Contact us</a></td><td>a href="index.php">Some linke</a></td></tr>';
   echo '</table>';
}


Since you are wanting to list the information, you could use an <ul> and output each row as <li>.

<style>
ul { list-style: none; }
</style>

<?php
while ($row = mysql_fetch_array($result)){             
    echo "<ul>";
    echo "<li>".$row["companyName"]."</li><li>".$row["address"]."</li><li>".$row["city"].", ".$row["state"]." ".$row["zipcode"]."</li>";
    echo "<li><a href=\"contact.html\">Contact Us</a></li><ul>";
}
?>

Also, what is the "Link to Another page"?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜