0

This is my search php code, it's working fine, but I want to return the link of the game. In this code I'm able to see the game name when I hit search, but I want to see my gamelist depending on what I'm searching for. What do I have to do to display the game instead of returning only its name? thanks

table `jogos`
--

CREATE TABLE IF NOT EXISTS `jogos` (
  `idGames` int(11) NOT NULL AUTO_INCREMENT,
  `strNome` varchar(100) DEFAULT NULL,
  `strSeo` varchar(100) DEFAULT NULL,
  `intCategoria` int(11) DEFAULT NULL,
  `strImage` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`idGames`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;



INSERT INTO `jogos` (`idGames`, `strNome`, `strSeo`, `intCategoria`, `strImage`) VALUES
(4, 'Quake', 'Quake', 1, 'Folder.jpg');

-- 

<?php
 if     (isset($_GET['query'])){
$query = $_GET['query']; 



$min_length = 3;


if(strlen($query) >= $min_length){ 

    $query = htmlspecialchars($query); 


    $query = mysql_real_escape_string($query);


    $raw_results = mysql_query("SELECT * FROM jogos
        WHERE (`strNome` LIKE '%".$query."%')") or die(mysql_error());



    if(mysql_num_rows($raw_results) > 0){ // if one or more rows are returned do following

        while($results = mysql_fetch_array($raw_results)){


            echo "<p>".$results['strGame']."</p>";


        }

    }
    else{ // if there is no matching rows do following
        echo "No results";
    }

    }
    else{ // if query length is less than minimum
    echo "Minimum length is ".$min_length;
    }
}
?>

</body>
</html>
<?php
mysql_free_result($GameData);
?>
  • 1
    can you show your tables? – mehdi nejati May 24 '13 at 02:35
  • table `jogos` -- CREATE TABLE IF NOT EXISTS `jogos` ( `idGames` int(11) NOT NULL AUTO_INCREMENT, `strNome` varchar(100) DEFAULT NULL, `strSeo` varchar(100) DEFAULT NULL, `intCategoria` int(11) DEFAULT NULL, `strImage` varchar(50) DEFAULT NULL, PRIMARY KEY (`idGames`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ; -- -- Dumping data for table `jogos` -- INSERT INTO `jogos` (`idGames`, `strNome`, `strSeo`, `intCategoria`, `strImage`) VALUES (4, 'Quake', 'Quake', 1, 'Folder.jpg'); -- – Compras Londrina May 24 '13 at 02:45
  • What's the link to the game look like? – AbsoluteƵERØ May 24 '13 at 02:46
  • link_categoria.php?cat=2 – Compras Londrina May 24 '13 at 02:48

1 Answers1

0

You could achieve this by adding an image tag to the output with the src set to $results['strImage'], as below

while($results = mysql_fetch_array($raw_results)){
    echo '<p><img src="'.$results['strImage'].'" />'.$results['strNome'].'</p>';
}

Note: It's recommended not to use the mysql_ functions since they are deprecated, see Why shouldn't I use mysql_* functions in PHP?

Zoe
  • 27,060
  • 21
  • 118
  • 148
Pudge601
  • 2,048
  • 1
  • 12
  • 11
  • I personally use PDO for most of my database access in PHP, but if you're used to using mysql_ functions, you may find mysqli easier to migrate to. – Pudge601 May 24 '13 at 12:42