使用if条件将数据排序到表中 [英] Sorting Data into a table using to if conditions
问题描述
伙计,我需要帮助。 :D
我有一个数据库,表格有4个字段。
ident,chroma,hue,value
我有脚本将所有数据显示到表中。但我要做的是设置一个条件,只显示我想要的数据。
例如:
只列出项目在适合这种情况的表中:
chroma = 7
value = 9
这是我当前的代码,它只是在表格中显示数据:
>
[PHP]< ;?
include(" XXXXXXXX.php");
mysql_connect($ dbhost,$ username,$ password);
@mysql_select_db($ database)或死(无法选择数据库);
$ query =" SELECT * FROM rembrandt";
$ result = mysql_query($ query);
$ num = mysql_numrows($ result);
mysql_close();
echo"< b>< center>数据库输出< / center>< / b>< br>< br>" ;;
?>
< table border =" 1" ; CELLSPACING = QUOT; 6英寸cellpadding =" 6"
< tr>
< th>< font face =" Arial,Helvetica,sans-serif"> Pastel Identifier< / font>< / th>
< th>< font face =" Arial,Helvetica,sans-serif"> Hue< / font>< / th>
< th>< font face =" Arial, Helvetica,sans-serif"> Chroma< / font>< / th>
< th>< font face =" Arial,Helvetica,sans-serif"> Value< / font>< / th>
< / tr>
< ;?
$ i = 0;
while($ i< $ num){
$ ident = mysql_result($ result,$ i," ident");
$ hue = mysql_result($ result,$ i," hue");
$ chroma = mysql_result($ result,$ i," chroma");
$值= mysql_result($结果,$ I,QUOT;值QUOT);
?>
< tr>
< td>< font face =" Arial,Helvetica,sans-serif"><? echo$ ident; ?>< / font>< / td>
< td>< font face =" Arial,Helvetica,sans-serif"><? echo$ hue; ?>< / font>< / td>
< td>< font face =" Arial,Helvetica,sans-serif"><? echo$ chroma; ?>< / font>< / td>
< td>< font face =" Arial,Helvetica,sans-serif"><? echo$ value; ?>< / font>< / td>
< / tr>
< ;?
$ i ++;
}
echo"< / table>" ;;
?> [/ PHP]
我试过把这个IF语句放入但没有成功,因为我真的不知道放在哪里。
if($ chroma = 7&& $ value = 9){
有人可以帮助我吗。
谢谢!!!!!
dbhost,
用户名,
密码);
@mysql_select_db(
Man, I need help. :D
I have a database and the table has 4 fields.
ident, chroma, hue, value
I have the script to display ALL the data into the table. But what I am looking to do is to set a condition for displaying only data i want.
For example:
Only list the items in the table that fit this condition:
chroma=7
value=9
Here is my current code that just displays the data in a table:
[PHP]<?
include("XXXXXXXX.php");
mysql_connect($dbhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM rembrandt";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
echo "<b><center>Database Output</center></b><br><br>";
?>
<table border="1" cellspacing="6" cellpadding="6">
<tr>
<th><font face="Arial, Helvetica, sans-serif">Pastel Identifier</font></th>
<th><font face="Arial, Helvetica, sans-serif">Hue</font></th>
<th><font face="Arial, Helvetica, sans-serif">Chroma</font></th>
<th><font face="Arial, Helvetica, sans-serif">Value</font></th>
</tr>
<?
$i=0;
while ($i < $num) {
$ident=mysql_result($result,$i,"ident");
$hue=mysql_result($result,$i,"hue");
$chroma=mysql_result($result,$i,"chroma");
$value=mysql_result($result,$i,"value");
?>
<tr>
<td><font face="Arial, Helvetica, sans-serif"><? echo "$ident"; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo "$hue"; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo "$chroma"; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo "$value"; ?></font></td>
</tr>
<?
$i++;
}
echo "</table>";
?>[/PHP]
I have tried putting this IF statement in but with no success as I really don''t know where to put it.
if ( $chroma=7 && $value=9 ) {
Can someone help me here.
Thank you!!!!!
dbhost,
username,
password);
@mysql_select_db(
这篇关于使用if条件将数据排序到表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!