添加单击到mysql数据库的搜索查询和链接

时间:2013-08-11 15:51:45

标签: php mysql mysqli

我正在使用Tutorial来创建搜索引擎。我有它做搜索。但现在我试图让它插入用户点击的链接和他们用于另一个db表的搜索查询。 我在做这件事时遇到了麻烦。

我在这里看到

include_once ('database_connection.php');//Including our DB Connection file
if(isset($_GET['keyword'])){//IF the url contains the parameter "keyword"
 $keyword =     trim($_GET['keyword']) ;//Remove any extra  space
$keyword = mysqli_real_escape_string($dbc, $keyword);//Some validation

$query = "select topictitle,topicdescription from topics where topictitle like '%$keyword%' or topicdescription like '%$keyword%'";
//The SQL Query that will search for the word typed by the user .

$result = mysqli_query($dbc,$query);//Run the Query
if($result){//If query successfull
 if(mysqli_affected_rows($dbc)!=0){//and if atleast one record is found
 while($row = mysqli_fetch_array($result,MYSQLI_ASSOC)){ //Display the record
                        $image = '';
                    switch( $row['Carrier'] ) {
                        case 'Nextel(Sprint)':
                            $image = './images/rat.png';
                            break;
                        case 'Verizon':
                            $image = './images/dog.png';
                            break;
                        case 'Sprint':
                            $image = './images/rooster.png';
                            break;
                        case 'AT&T(also Cingular)':
                            $image = './images/ox.png';
                            break;
                        case 'T-Mobile':
                            $image = './images/snake.png';
                            break;
                        case 'Tiger':
                            $image = './images/tiger';
                            break;
    }
                    echo '<table><tr><td>We Think your Number is </td><td><a href="next.php?csv='.$row['Carrier'].'">
                    <img src="'.$image.'" alt="'.$row['Carrier'].'" title="'.$row['Carrier'].'" /></a></td><td> Is that correct? <a href="">Yes</a> Or 
                    <a href="#" id="button" class="button_style">No</a></td></tr></table>
                    <div id="hidden_content">
                        <ul><!-- IF user clicks one of these links it will direct them to the page then insert there search query and the link they clicked into a database
                            <li><a href="next.php?rat"><img src="./images/rat.png" /></a></li>
                            <li><a href="next.php?dog"><img src="./images/dog.png" /></a></li>
                            <li><a href="next.php?rooster"><img src="./images/rooster.png" /></a></li>
                            <li><a href="next.php?ox"><img src="./images/ox.png" /></a></li>
                            <li><a href="next.php?snake"><img src="./images/snake.png" /></a></li>
                            <li><a href="next.php?tiger"><img src="./images/tiger.png" /></a></li>
                    </ul>
                    </div>';
 }
 }else {
 echo 'No Results for :"'.$_GET['keyword'].'"';//No Match found in the Database
 }

}
}else {
 echo 'Parameter Missing in the URL';//If URL is invalid
}

我的问题是我试图在用户点击链接时点击链接并将其插入数据库以及用户键入的查询。但我无法弄清楚如何做到这一点

0 个答案:

没有答案