Jump to content

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

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.