Hi there,
I'm really new at PHP,so i'm not sure if this is a simple problem. I've searched the forums for this particular problem,but hasn't been successful. What i wanted to do was have a form consisting of a drop down list displaying a list of names. After a name is selected from the drop down list and the form submitted,it will query the database and show the results of the query in a table.
I've tested the code,and it worked with a single word. But if there are more than one word,the result will only display the first word before the space (eg: if the word "Dendrophyssa russelli" is selected, only "Dendrophyssa" is returned). How do i resolve that problem? A funny thing is that,in the drop down menu (which also queries the database and returns the names),it displays the names with spaces fine, but if i want to display in tabular format, it doesn't work. Any advice or tips would be appreciated. Thanks so much!
Here is my code for the drop down list:
<?
$hostname_logon = "localhost";
$database_logon = "fish";
$username_logon = "root";
//open database connection
$connections = mysql_connect($hostname_logon, $username_logon) or die ( "Unabale to connect to the database" );
//select database
mysql_select_db($database_logon) or die ( "Unable to select database!" );
$query="SELECT abcID,uname FROM abc ORDER BY uname ASC";
$result = mysql_query ($query);
echo "<select name=select value='' ><option>Please select</option>";
// printing the list box select command
while($nt=mysql_fetch_array($result)){//Array or records stored in $nt
echo "<option value=$nt[uname]>$nt[uname]</option>";
/* Option values are added by looping through the array */
}
echo "</select>";// Closing of list box
?>
This is the results page:
<?php
$subcat3=$_POST['select'];
$query="SELECT * FROM $subcat3";
$numresults = mysql_query ($query) or die ( "<center>Couldn't execute query<center>" );
$row= mysql_fetch_array ($numresults);
echo "<center><h1>Search results for: " . $subcat3 ." </center></h1>";
echo " <table width=774 align=center height=69 border=1 bordercolor=#000000>
<tr bordercolor=1 bgcolor=#000099>
<td width=148><div align=center class=style7><strong><span class=style1>Taxcode</span></strong></div></td>
<td width=148<div align=center class=style7><strong><span class=style1>Weight(gm)</span></strong></div></td>
<td width=148><div align=center class=style7><strong><span class=style1>Sex</span></strong></div></td>
<td width=148><div align=center class=style7><strong><span class=style1>Maturity</span></strong></div></td>
<td width=148><div align=center class=style7><strong><span class=style1>Gear</span></strong></div></td>
</tr>";
while ($row_linkcat= mysql_fetch_array ($numresults)){
echo "<tr bordercolor=1>";
echo "<td>". $row_linkcat[ 'abcID' ] ."</td>";
echo "<td>". $row_linkcat[ 'uname' ] ."</td>";
echo "<td>". $row_linkcat[ 'scientificname' ] ."</td>";
echo "<td>". $row_linkcat[ 'environment' ] ."</td>";
echo "<td>". $row_linkcat[ 'climate' ] ."</td>";
echo "</tr>";}
echo "</table>";
?>