Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question about combining query string and a SQL statement

Status
Not open for further replies.

magicandmight

IS-IT--Management
Aug 27, 2004
77
US
I am using the following procedure to create a query string in the url.

<script type="text/javascript"><!--
function doSomethingSpectacular() {
var splitAtEqual;
var theWholeUrl = document.location;
var splitAtQMark = theWholeUrl.split("?");
if ( isArray( splitAtQMark ) ) {
splitAtEqual = splitAtQMark[1].split("=");
}
if ( isArray( splitAtEqual ) ) {
alert( splitAtEqual[0] + " equals " + splitAtEqual[1] );
}
}
//--></script>

<body onload="doSomethingSpectacular();">

With the link as: <a href="thenextpage.html?mycoolvariable=stuff">Click Me</a>



How would I pull what is after the equal sign into a variable that I can put in the SQL statement:

$query = "SELECT CoName,Anchor FROM list WHERE Gcat LIKE '%worship%' and Anchor <> '' ORDER by CoName";

where what is after the equal sign would take the place of %worship%
 
You do this server-side using what ever environment you are using. If I was using PHP I would do it like this:
Code:
<? $server_side_mycoolvariable = '';
 if (isset($_GET['mycoolvariable'])
  $server_side_mycoolvariable = $_GET['mycoolvariable'];
...
 $query = "SELECT CoName,Anchor FROM list WHERE Gcat LIKE '%[COLOR=red]$server_side_mycoolvariable[/color]%' and Anchor <> '' ORDER by CoName";
...
?>
If you are not using PHP, best to ask in the forum appropriate to your code.

Cheers,
Jeff

[tt]Jeff's Page @ Code Couch
[/tt]

What is Javascript? FAQ216-6094
 
I am using PHP. Ill try it out. One question though what is the "..." for in the code? Guessing it means the rest of my code.
 
It didnt like the line that has:
$server_side_mycoolvariable = $_GET['mycoolvariable'];

gave me an error:


Parse error: parse error, unexpected T_VARIABLE
 
Yes, it is a PHP problem, but let's just solve it quickly... Since we ventured into PHP inadvertly anyway. Please check the code you're given for possible errors of oversight:
Code:
 if (isset($_GET['mycoolvariable'])[red][b])[/b][/red]
There was a missing parenthesis there. Try to match them up.
 
Ah... that was my fault... sorry for not making it clear that I was unable to test the code snippet I posted.

And yes, '...' implied "your other code goes here" - but you figured that out :)

Hope you got it running ok!

CHeers,
Jeff

[tt]Jeff's Page @ Code Couch
[/tt]

What is Javascript? FAQ216-6094
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top