Jump to content

[SOLVED] mysql, multiple results in one column


blueman378

Recommended Posts

hi there, i have a table called games.

 

it has things like the file link, the name ect, it also has a column called keywords, i was wondering is it possible to count each word in that column as a seperate result,

 

eg with mysql if you search keywords and your word is mouse, it searches all the games and if the word mouse is in the keyword column for that game then that result is shown,

 

cheers matt

hi there, i tried using this

<?php
include("include/session.php");
$key = $_POST['key'];
    global $database;
    $q = "SELECT * FROM " . Games . "
          WHERE keyword LIKE '$key'
          ORDER BY `gName` ASC
         ";   
    $result = $database->query($q) or die("Error: " . mysql_error());
    /* Error occurred, return given name by default */
    $num_rows = mysql_numrows($result);
    if( $num_rows == 0 ){
      return 'Game Not Found!';
    }

    while( $row = mysql_fetch_assoc($result) ) {
     echo $row[gName];
    }

?>

 

but i just get a blank page no errors or anything, and when i change the keyword to one that does not exist i get nothing

 

the url is

localhost.php?key=Space

 

when i use

<?php
include("include/session.php");
echo "<pre>";
print_r($_GET);
die("</pre>");
$key = $_POST['key'];
    global $database;
    $q = "SELECT * FROM " . Games . "
          WHERE keyword LIKE '$key'
          ORDER BY `gName` ASC
         ";   
    $result = $database->query($q) or die("Error: " . mysql_error());
    /* Error occurred, return given name by default */
    $num_rows = mysql_numrows($result);
    if( $num_rows == 0 ){
      return 'Game Not Found!';
    }

    while( $row = mysql_fetch_assoc($result) ) {
     echo $row[gName];
    }

?>

 

i get

Array
(
    [key] => Space
)

 

when i use:

<?php
include("include/session.php");

$key = $_POST['key'];
    global $database;
    $q = "SELECT * FROM " . Games . "
          WHERE keyword LIKE '$key'
          ORDER BY `gName` ASC
         ";   
    $result = $database->query($q) or die("Error: " . mysql_error());
    /* Error occurred, return given name by default */
   
die("SQL:<br>$q");

$num_rows = mysql_numrows($result);
    if( $num_rows == 0 ){
      return 'Game Not Found!';
    }

    while( $row = mysql_fetch_assoc($result) ) {
     echo $row[gName];
    }

?>

 

i get

SQL:
SELECT * FROM Games WHERE keyword LIKE '' ORDER BY `gName` ASC

i guess MySql is forgiving and assumes the "%", In my years of sql

 

keywords like '%mouse%' = contains

keywords like 'mouse% = begins with

keywords like '%mouse' = ends with

 

to me it is safer to use the % (which is actually a wildcard for Many chars)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.