Jump to content

Simple query help


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
https://forums.phpfreaks.com/topic/281626-simple-query-help/
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
https://forums.phpfreaks.com/topic/281626-simple-query-help/#findComment-1447147
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
https://forums.phpfreaks.com/topic/281626-simple-query-help/#findComment-1447208
Share on other sites

First, what is the name of the GET variable in the real URL? Your code suggests that it's "map_link". However, your original post (below) suggests that it's "map".

 

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

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

Link to comment
https://forums.phpfreaks.com/topic/281626-simple-query-help/#findComment-1447294
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

Link to comment
https://forums.phpfreaks.com/topic/281626-simple-query-help/#findComment-1447313
Share on other sites

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.