Jump to content

Simple query help


kroymac
Go to solution Solved by kroymac,

Recommended Posts

Lets say my database table looks like this:

 

map_name                 map_link

 

dm/anubis                  http://www.mysite.com/files/anubis.pk3

dm/tomb                    http://www.mysite.com/files/tomb.pk3

dm/bunker                 http://www.mysite.com/files/bunker.pk3

 

and the php script will be called maplink.php

 

I need it so when the address is entered like this:

http://www.mysite.com/maplink.php?map=dm/anubis

 

it will echo back the map_link like this:

http://www.mysite.com/files/anubis.pk3

 

and so on for any map name added to the end of the address

 

I don't want it to be an active link but just displayed

 

I'm sure this is a simple query script but I am new to this.

Link to comment
Share on other sites

The following should help guide you for getting the "map" variable from the URL:

http://php.net/manual/en/reserved.variables.get.php

 

Once you feel comfortable with GET variables, you could then use the information to perform the MySQL query. Here's some information on executing a query with MySQLi:

http://www.php.net/manual/en/mysqli.query.php

 

Or you could use PDO:

http://php.net/manual/en/pdo.query.php

Link to comment
Share on other sites

assume the connection has been made

This is what I've been trying to make work but it returns nothing

 

    $db = mysql_connect($db_host, $db_user, $db_pass) OR DIE ("Unable to connect to database! Please try again later.");
    mysql_select_db($db_database);
    
    $sql = mysql_query("SELECT * FROM gamemaps WHERE map_name = '".$map."'");
    $row = mysql_fetch_array($sql);    
    
    $map = $_GET['map_link'];
    
    echo $map;

Link to comment
Share on other sites

    $db = mysql_connect($db_host, $db_user, $db_pass) OR DIE ("Unable to connect to database! Please try again later.");
    mysql_select_db($db_database);
    
    $map = $_GET['map'];  
    
    $sql = mysql_query("SELECT map_name FROM gamemaps WHERE map_link = '".$map."'");
    $row = mysql_fetch_array($sql);
    
    echo $map;

 

 

now when I enter the address:  http://www.mysite.com/maplink.php?map=dm/anubis

 

it just returns:  dm/anubis 

and I want it to return:  http://www.mysite.com/files/anubis.pk3

 

sorry, I am totally new to this and it's a bit confusing.

yes i just want it to return the database value

Edited by kroymac
Link to comment
Share on other sites

  • Solution

this finally worked

 

    $map = $_GET['map'];

    $sql = mysql_query("SELECT map_link FROM gamemaps WHERE map_image = '".$map."'");
    $row = mysql_fetch_array($sql);

    echo $row['maps_link'];

 

thanks for your help and patience

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.