本文介绍了如何使用mysql_query()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 下面是用于从表中搜索用户输入值并打印它的php代码。 header.php // html代码 < 表格 > < select name = 选择 > < 选项 value = empty > 无< / option > < 选项 value = 小说 > 小说< / option > < 选项 value = 期刊 > 期刊< / option > < 选项 value = acadamic > acadamic < / option > < /选择 > < form action = method = POST > < 输入 type = text value = 在此处输入关键字... 名称 = q size = 10 id = searchfield title = searchfield o nFocus = clearText(this) onBlur = clearText(this) / > < 输入 type = submit 名称 = 搜索 value = alt = 搜索 id = searchbutton title = 搜索 / > < / form > < / form > // php code <? php if (isset($ _ GET [' q '])&&a熔点; $ _GET [' q']!= ) { if($ _ GET [' select'] == fiction){ $ result = $ _ GET [' q']; // 存储用户输入的值 // echo $ a; $ sqlcommand = SELECT title,author FROM .USRBOOKS。 WHERE fiction ='$ result' ; }否则if($ _ GET [' select'] == journals){ $ result = $ _ GET [' q']; $ sqlcommand = SELECT title,author FROM .USRBOOKS。 WHERE fiction ='$ result'; } else if($ _ GET ['' select'] == acadamic){ $ result = $ _ GET [' q']; $ sqlcommand = SELECT title,author FROM .USRBOOKS。 WHERE fiction ='$ result'; } $ query = mysql_query($ sqlcommand)或 die($ sqlcommand); echo hello world; $ count = mysql_num_rows($ query); if ($ count> 0) { global $ searchoutput ; $ searchoutput = $ count results ; echo ' < META http-equiv =refreshcontent =0; URL =' .INDEX_URL。' result.php> '; // 尝试在新的php文件中打印结果 } } else { $ searchoutput = 0 result; echo ' < META http-equiv =refreshcontent =0; URL =' .INDEX_URL。' resultn.php> ; } ?> 当我试图搜索该值时,它正在打印选择查询。 如果我输入值xyz(假设它存在于虚构列的数据库表中) 而不是将资源存储到$ query(通过使用$ mysql_query)它打印低于值 SELECT title,author FROM books WHERE fiction = 'xyz' 请任何人解决我的问题解决方案 _GET [' q'])&& _GET [' q']!= ) { if( _GET [' select'] == 小说){ below is the php code for searching user entered value from table and printing it.header.php //html code<form> <select name="select"><option value="empty">none</option><option value="fiction">fiction</option><option value="journals">journals</option><option value="acadamic">acadamic</option></select> <form action="" method="POST"> <input type="text" value="Enter a keyword here..." name="q" size="10" id="searchfield" title="searchfield" onFocus="clearText(this)" onBlur="clearText(this)" /> <input type="submit" name="Search" value="" alt="Search" id="searchbutton" title="Search" /> </form></form>// php code<?phpif (isset($_GET['q']) && $_GET['q'] != ""){if($_GET['select'] == "fiction"){ $result=$_GET['q'];// storing user entered value //echo $a; $sqlcommand= "SELECT title,author FROM ".USRBOOKS." WHERE fiction = '$result'";}else if($_GET['select'] == "journals"){$result=$_GET['q']; $sqlcommand= "SELECT title,author FROM ".USRBOOKS." WHERE fiction = '$result'";}else if($_GET['select'] == "acadamic"){$result=$_GET['q']; $sqlcommand= "SELECT title,author FROM ".USRBOOKS." WHERE fiction = '$result'";}$query = mysql_query($sqlcommand) or die($sqlcommand);echo "hello world";$count = mysql_num_rows($query);if ($count>0){global $searchoutput;$searchoutput = " $count results ";echo '<META http-equiv="refresh" content="0;URL='.INDEX_URL.'result.php">';// trying to print result in new php file}}else { $searchoutput="0 result";echo '<META http-equiv="refresh" content="0;URL='.INDEX_URL.'resultn.php">';}?>when ever I am trying to search the value, its is printing select query.if I entered value xyz (assume it is present in data base table in fiction column)instead of storing resource into $query (by using $mysql_query) it is printing below valueSELECT title,author FROM books WHERE fiction = 'xyz'please anyone solve my problem 解决方案 _GET['q']) &&_GET['q'] != ""){if(_GET['select'] == "fiction"){ 这篇关于如何使用mysql_query()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-16 02:59