我正在尝试搜索并从数据库获取数据,但作为 PHP 和 MySQL 的新手,无法完成此任务。
<?php
$connection = mysql_connect("localhost", "root", ""); // Establishing Connection with Server
$db = mysql_select_db("vdl", $connection); // Selecting Database
//MySQL Query to read data
$query = mysql_query("select * from digital_library", $connection);
while ($row = mysql_fetch_array($query)) {
echo '<ul>';
echo "<li><b><a href=\"read.php?id={$row['company_id']}\">{$row['company_name']}</a></b></li>";
echo "<br />";
echo '</ul>';
}
?>
这些是我将从数据库中获取的字段。尝试进行简单搜索,但无法获取完整数据。
<?php
if (isset($_GET['id'])) {
$id = $_GET['id'];
$query1 = mysql_query("select * from digital_library where company_id=$id", $connection);
while ($row1 = mysql_fetch_array($query1)) {
?>
<span>Company Name: </span> <?php echo $row1['company_name']; ?><br><br>
<span>Since: </span> <?php echo $row1['since']; ?><br><br>
<span>Strength: </span> <?php echo $row1['strength']; ?><br><br>
<span>Head Quarters: </span> <?php echo $row1['head_quarter']; ?><br><br>
<span>Location (City): </span> <?php echo $row1['locations']; ?><br><br>
<span>Develpment Centers: </span> <?php echo $row1['development_centers']; ?><br><br>
<span>Customers: </span> <?php echo $row1['customers']; ?><br><br>
<span>MNC: </span> <?php echo $row1['mnc']; ?><br><br>
<span>CMMI: </span> <?php echo $row1['cmmi']; ?><br><br>
<span>Domains: </span> <?php echo $row1['domains']; ?><br><br>
<span>Industries: </span> <?php echo $row1['industries']; ?><br><br>
<span>Domain Competitors: </span> <?php echo $row1['domain_competitor']; ?><br><br>
<span>Products: </span> <?php echo $row1['products']; ?><br><br>
<span>Services: </span> <?php echo $row1['services']; ?><br><br>
<span>Uniqueness: </span> <?php echo $row1['uniqueness']; ?><br><br>
<span>Company URL: </span>
<a target='_blank' href="<?php echo $row1['url']; ?>">
<?php echo $row1['url']; ?>
</a><br><br>
<!--<span>Comapny Logo:</span> <?php echo $row1['logo']; ?><br><br>-->
<span>Onsight: </span> <?php echo $row1['onsight']; ?><br><br>
<span>Benefits: </span> <?php echo $row1['benefits']; ?><br><br>
<span>Awards: </span> <?php echo $row1['awards']; ?><br><br>
<?php } ?>
最佳答案
$query1 = mysql_query("select * from digital_library where company_name like '%$comany_name%', $connection);
关于PHP 和 MySQL 搜索从数据库获取完整数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50290339/