Jump to content

mysql query/fetch problem with $_GET['']


bujashaka

Recommended Posts

Hello!

 

I've been into mysql and encountered a problem, not serious one but it is bugging me.

 

I can do dynamic page linking as follows, in short hand....

 

echo "<a href=\"foo.php?page=" . $vastaus['id'] ."\">" . $vastaus['menu_name'] . "</a><br />";   // URL LINK

 

function showcontent() {   /// FUNCTION TO DISPLAY CONTENT FROM SERVER.
        global $yhteys;
        $sql = "SELECT * ";
        $sql .= "FROM subjects ";
        $sql .= "WHERE id=" . $_GET['page'];
        $kysely= mysql_query($sql, $yhteys);
        $content = mysql_fetch_assoc($kysely) or die(mysql_error());
            
        echo strip_tags($content['content'], "<br><dt><dl>");

Problem is... I can make this work with the ID, how ever, i want the URL bar saying it like this -> index.php?page=Info.

 

This way it looks smarter (tells more to a user) and not just numbers as IDs.

 

If i try to do the query like this...

 

$sql = "SELECT * ";
        $sql .= "FROM subjects ";
        $sql .= "WHERE menu_name=" . $_GET['page'];

It says unknown column "Info, Services". etc etc.

It can only regonize the first column in each row. ( aka the id=number)

I've tryed num_rows, fetch_array and fetch_assoc. I can't find a way to accomplish it.

 

 

PLEASE i know this is simple, need help.

Thanks in advance!

Edited by Zane
Link to comment
Share on other sites

you have to surround it in quotes if it's text

    $sql .= "WHERE menu_name='" . $_GET['page']."'";

 

Hello!

 

I've been into mysql and encountered a problem, not serious one but it is bugging me.

 

I can do dynamic page linking as follows, in short hand....

 

echo "<a href=\"foo.php?page=" . $vastaus['id'] ."\">" . $vastaus['menu_name'] . "</a><br />";   // URL LINK

 

function showcontent() {   /// FUNCTION TO DISPLAY CONTENT FROM SERVER.
        global $yhteys;
        $sql = "SELECT * ";
        $sql .= "FROM subjects ";
        $sql .= "WHERE id=" . $_GET['page'];
        $kysely= mysql_query($sql, $yhteys);
        $content = mysql_fetch_assoc($kysely) or die(mysql_error());
            
        echo strip_tags($content['content'], "<br><dt><dl>");

 

Problem is... I can make this work with the ID, how ever, i want the URL bar saying it like this -> index.php?page=Info.

 

This way it looks smarter (tells more to a user) and not just numbers as IDs.

 

If i try to do the query like this...

 

$sql = "SELECT * ";
        $sql .= "FROM subjects ";
        $sql .= "WHERE menu_name=" . $_GET['page'];

 

It says unknown column "Info, Services". etc etc.

It can only regonize the first column in each row. ( aka the id=number)

I've tryed num_rows, fetch_array and fetch_assoc. I can't find a way to accomplish it.

 

 

PLEASE i know this is simple, need help.

Thanks in advance!

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.