Jump to content

string replace of variable in database


dnk37482

Recommended Posts

I have a fields in my database that have spaces in them like "New York"

 

I want them to be able to be called by

 

states.php?id=newyork // with no space

 

Here is what I have so far...it's not working at all though:

 

<?php

            $name4 = str_replace(" ","", $_REQUEST['id']);

            $query='SELECT * FROM states WHERE

state="'.$name4.'"';

            $result= mysql_query($query);

            $myrow=@mysql_fetch_array($result);

            if($myrow)

            {

                $state=$myrow['state'];

 

            }

            ?>

 

I thank you all in advance for any help I can get..

Link to comment
Share on other sites

<?php
$sql = "SELECT * FROM states
        WHERE state LIKE '% %';";
?>

 

this code doesn't seem to work, but thanks for your help.  I am going to try and be more specific.  I am trying to replace strings of a variable already in the database, is that even possible?  like changing "New York" to "NewYork"

 

so that I can pull states.php?id=newyork

 

instead of states.php?id=new york

Link to comment
Share on other sites

Is this what you're looking for?

 

SELECT REPLACE(state, ' ', '') AS state
FROM states;

 

isnt this just the same thing as a string replace though, I cant call this from states.php?id=newyork

 

I would still have to call states.php?id=new york

 

Or am I wrong?

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.