简体   繁体   English

从 SQL 数据库创建联系人列表

[英]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). (邮编、城市、State、姓名等)。 Let's say I search by zip code, and there are 2 results in my SQL for that zip code.假设我通过 zip 代码搜索,我的 SQL 代码中有 2 个结果。

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.如果我的 SQL 中的公司名称行为空白/空,请跳过该行/条目和 go 到下一个。

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或表 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> .由于您想列出信息,您可以使用<ul>和 output 每行作为<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"?另外,什么是“链接到另一个页面”?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM