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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.