This is a discussion on PHP String concatination with html select combo box within the PHP Language forums, part of the PHP Programming Forums category; Hello, I have problem in PHP String concatination with html select combo box. There are 3 files addressbook.sql : concat1....
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hello,
I have problem in PHP String concatination with html select combo box. There are 3 files addressbook.sql : concat1.php concat2.php In concat1.php , if we select User Name in combo box & give input as 3 in text box. It display following output subhash kanade,3 sk@yahoo.com But, it is not display in that way. So, please see that code & tell me correction. addressbook.sql -- Table structure for table `addressbook` -- CREATE TABLE `addressbook` ( `id` int(11) NOT NULL auto_increment, `name` varchar(50) NOT NULL, `email` varchar(50) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ; -- -- Dumping data for table `addressbook` -- INSERT INTO `addressbook` (`id`, `name`, `email`) VALUES (1, 'pramod kumar', 'pk@hotmail.com'), (2, 'vinod wagh', 'vinod@rediff.com'), (3, 'subhash kanade', 'sk@yahoo.com'), (4, 'ketan patil', 'kp@hotmail.com'); concat1.php <?php mysql_connect("localhost","root")or die("Database Failed"); mysql_select_db("pradeep")or die("Failed to Connect Database"); $arr=array("concat(concat(name,','),id)","email"); $str="select ".$arr[0].", ".$arr[1]." from addressbook"; $res=mysql_query($str) or die("resultset error"); echo "<table><tr><th>User</th><th>Email</th></tr>"; while($row=mysql_fetch_array($res)){ echo "<tr><td>".$row[0]."</td><td>".$row[1]."</td></tr>"; } echo "</table>"; echo "<center>Search</center>"; echo "<form name=frm action=concat2.php method=get>"; echo "<input type=text name=txtField> <select name=selField><option value='".$arr[0]."'>User Name</option><option value='".$arr[1]."'>E- Mail</option></select>"; echo "<input type=submit>"; echo "</form>"; ?> concat2.php <? $arr1=array("concat(concat(name,','),id)","email") ; $str="select ".$arr1[0].",".$arr1[1]." from addressbook where ". $_REQUEST['selField']." like '%".$_REQUEST['txtField']."%'"; echo "<hr>Query : ".$str; ?> Thanks in advance |