prokurist
1.07.2009 - 17:30
ïðèâåò ÿ ñîçäàë çàïðîñ â mysql íî îí íåðàáîòàåò ïîìîãèòå ðàçîáðàòüñÿ. åñòü îäèí ôàèë search.php åùå íå çíàþ êàê ðåàëèçîâàòü: íóæíî ÷òî áû äàííûå âûâîäèëèñü íà îòäåëüíóþ ñòðàíèöó ââèäå òàáëèöè.
HTML |
<form name="form" action="search.php" method="get"> <input type="text" name="q" /> <input type="submit" name="Submit" value="Search" /> </form> |
PHP |
<?php
if(isset($_POST['submit'])){ if(isset($_GET['go'])){ if(preg_match("/^[ a-zA-Z]+/", $_POST['SearchWord'])){ $name=$_POST['name']; //connect to the database $db=mysql_connect ("host", "user", "pwd") or die ('I cannot connect to the database because: ' . mysql_error()); //-select the database to use $mydb=mysql_select_db("noer"); //-query the database table $sql = "select `SearchWord` from synonyms WHERE `SearchWord` LIKE '%" .$SearchWord . "%' . union . select `SearchWord` from synonyms2 WHERE `SearchWord` LIKE '%" .$SearchWord . "%"; //-run the query against the mysql query function $result=mysql_query($sql); //-create while loop and loop through result set while($row=mysql_fetch_array($result)){ $SearchWord=$row['Antonymer'];
//-display the result of the array echo "<ul>\n"; echo "<li>" . "<a href=\"search.php?id=$ID\">" .$SearchWord . "</a></li>\n"; echo "</ul>"; } } else{ echo "<p>Please enter a search query</p>"; } } } |
Ñïóñòÿ 1 ÷àñ, 42 ìèíóòû, 31 ñåêóíäà (1.07.2009 - 18:13) PandoraBox2007 íàïèñàë(à):
PHP |
<?php
if(isset($_POST['submit'])) { if( isset($_GET['go']) ) { if(preg_match("/^[ a-zA-Z]+/", $_POST['SearchWord'])) { $name = $_POST['name']; $SearchWord = htmlspecialchars($_POST['SearchWord']); //connect to the database $db = mysql_connect ("host", "user", "pwd") or die ('I cannot connect to the database because: ' . mysql_error()); //-select the database to use $mydb = mysql_select_db("noer"); //-query the database table $sql = "(SELECT `SearchWord` FROM synonyms WHERE `SearchWord` LIKE '%$SearchWord%') "; $sql .= "UNION (SELECT `SearchWord` FROM synonyms2 WHERE `SearchWord` LIKE '%$SearchWord%')";
//-run the query against the mysql query function $result = mysql_query($sql) or echo "<br /><b>MySQL query error:</b> " . mysql_error(); //-create while loop and loop through result set while($row = mysql_fetch_array($result)) { $SearchWord = $row['Antonymer']; //-display the result of the array if ($SearchWord) echo "<ul>\n<li>" . "<a href=\"search.php?id=$ID\">". $SearchWord ."</a></li>\n</ul>"; } } else { echo "<p>Please enter a search query</p>"; } } } |