Jump to content

another mysql question


ohdang888

Recommended Posts

hey,

my code is below.

 

it would be located in a url called "game.php?title=GAMETITLE"

 

<?php

$game = @$_GET['title'] ;

mysql_connect("localhost", "----, "------") or die(mysql_error());
mysql_select_db("games") or die(mysql_error());

$result = mysql_query("SELECT title FROM game WHERE game='$game'")
or die(mysql_error());  

   echo $result;
?>

 

 

but if the next thing i want to do is query the name of the author of that specific game....

1. would it grab it the author info from the same row as the game if my code is...

 

 

<?php

$game = @$_GET['title'] ;

mysql_connect("localhost", "---", "---" or die(mysql_error());
mysql_select_db("games") or die(mysql_error());

$result = mysql_query("SELECT author FROM game WHERE game='$game'")
or die(mysql_error());  

   echo $result;
?>

 

??????????????????????????????????

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/83794-another-mysql-question/
Share on other sites

<?php

$game = @$_GET['title'] ;

mysql_connect("localhost", "----", "------") or die(mysql_error());
mysql_select_db("games") or die(mysql_error());

if ( !$result = mysql_query("SELECT `title`, `author` FROM `game` WHERE `game`='$game' LIMIT 0,1") ) {
    die('MySQL Error: ' . mysql_error());
}
list($title, $author) = mysql_fetch_assoc($result);

echo $title . '<br>';
echo $author;

?>

 

PhREEEk

Then let's put the query into a variable and echo it to see what we're actually asking MySQL...

 

<?php

$game = @$_GET['title'] ;

mysql_connect("localhost", "----", "------") or die(mysql_error());
mysql_select_db("games") or die(mysql_error());

$sql = "SELECT `title`, `author`
        FROM `game`
        WHERE `game`='$game'
        LIMIT 0,1
       ";
if ( !$result = mysql_query($sql) ) {
    die('MySQL Error: ' . mysql_error());
}
die('SQL:<br>' . $sql);
list($title, $author) = mysql_fetch_assoc($result);

echo $title . '<br>';
echo $author;

?>

 

PhREEEk

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.