selectbox with multiple columns from mysql database
以下代码是zgr024的获奖代码
<?php
include '../config.php';
$sql = "SELECT * FROM megabase";
$resultaat = mysql_query($sql) or die (mysql_error());
$domains = array();
while ($row = mysql_fetch_array($resultaat))
{
if (!empty($row['domeinnaam1'])) $domains[] = $row['domeinnaam1'];
if (!empty($row['domeinnaam2'])) $domains[] = $row['domeinnaam2'];
}
?>
<select size="1" name="domeinnaam">
<?php
foreach ($domains as $domain)
{
echo "<option>$domain</option>";
}
?>
</select>
但是这个代码导致下一页的预期错误,我有以下代码。
<?php
//MySQL Database Connect
include 'config.php';
$domeinnaam=$_POST['domeinnaam'];
$data = 'SELECT * FROM megabase WHERE domeinnaam = "'.$domeinnaam.'"';
$query = mysql_query($data) or die("Couldn't execute query. ". mysql_error());
$data2 = mysql_fetch_array($query);
?>
如何更改最后一个代码以使用第一个代码:
我试过了:
<?php
//MySQL Database Connect
include 'config.php';
$domeinnaam=$_POST['domeinnaam'];
$domeinnaamquerry='domeinnaam1'.'domeinnaam2'.'domeinnaam3'.'domeinnaam4'.'domeinnaam5'.'do meinnaam6'.'domeinnaam7'.'domeinnaam8'.'domeinnaam9'.'domeinnaam10';
$data = 'SELECT * FROM megabase WHERE $domeinnaamquerry = "'.$domeinnaam.'"';
$query = mysql_query($data) or die("Couldn't execute query. ". mysql_error());
$data2 = mysql_fetch_array($query);
?>
但我收到以下错误: 无法执行查询。未知专栏&#39; $ domeinnaamquerry&#39;在&#39; where子句&#39;
Okey现在正在运作它很草率但是感谢大家的帮助,这对你有所帮助。并感谢警告。
这是代码
<?php
//MySQL Database Connect
include 'config.php';
$domeinnaam=$_POST['domeinnaam'];
$data = 'SELECT * FROM megabase WHERE domeinnaam1="'.$domeinnaam.'" OR domeinnaam2="'.$domeinnaam.'" OR domeinnaam3="'.$domeinnaam.'" OR domeinnaam4="'.$domeinnaam.'" OR domeinnaam5="'.$domeinnaam.'" OR domeinnaam6="'.$domeinnaam.'" OR domeinnaam7="'.$domeinnaam.'" OR domeinnaam8="'.$domeinnaam.'" OR domeinnaam9="'.$domeinnaam.'" OR domeinnaam10="'.$domeinnaam.'" ';
$query = mysql_query($data) or die("Couldn't execute query. ". mysql_error());
$data2 = mysql_fetch_array($query);
?>
答案 0 :(得分:1)
尝试
<?php
//MySQL Database Connect
include 'config.php';
$domeinnaam=$_POST['domeinnaam'];
$data = "SELECT * FROM megabase WHERE domeinnaam1 = '$domeinnaam' OR domeinnaam2 = '$domeinnaam' ";
$query = mysql_query($data) or die("Couldn't execute query. ". mysql_error());
$data2 = mysql_fetch_array($query);
?>
答案 1 :(得分:0)