Forums

PHP

This topic is locked

Filter Recordset by URL Parameter

Posted 27 Apr 2005 19:23:38
1
has voted
27 Apr 2005 19:23:38 Matt Bailey posted:
This is something I do everyday, but I'm trying something a bit different and I'm really struggling to get it working. Here's the scenario:

I'm checking for a URL parameter. Here's the code (based on DW's standard code):

<pre id=code><font face=courier size=2 id=code>$colname = "0";
if (isset($HTTP_GET_VARS['SubSectionID'])) {
$colname = (get_magic_quotes_gpc()) ? $HTTP_GET_VARS['SubSectionID'] :
addslashes($HTTP_GET_VARS['SubSectionID']);
}</font id=code></pre id=code>

Then I have a function (same PHP file, just a bit further down). Here's the bit of code in question:

<pre id=code><font face=courier size=2 id=code>function createUserMenu(){
... (blah, blah, blah)
$query = sprintf("SELECT * FROM adp_ProjectsContent WHERE SubSectionID = '%s' ORDER BY Position ASC", $colname);
... etc</font id=code></pre id=code>

Now I can echo $colname on the page no problem, but the SQL above doesn't seem to see it so all I get is an empty query result. If I simply put <pre id=code><font face=courier size=2 id=code>WHERE SubSectionID = 20</font id=code></pre id=code> (for example) it will work, so I know I'm nearly there, just can't quite see it myself!

Help...

___________________________________
* Sorry... how do you do that again?... *

Edited by - matm00 on 27 Apr 2005 19:24:13

Replies

Replied 28 Apr 2005 16:05:27
28 Apr 2005 16:05:27 Matt Bailey replied:
After a bit more thought I think all I'm asking is how do I pass a URL parameter, or even just a variable to a function in a separate include file?

I can take the URL parameter and put it in a variable and echo it on the page, but I can't then seem to pass that variable to the function.

Any suggestions?

___________________________________
* Sorry... how do you do that again?... *
Replied 28 Apr 2005 17:50:43
28 Apr 2005 17:50:43 Chris Charlton replied:
Try:
<pre id=code><font face=courier size=2 id=code>function createUserMenu($colName) ...</font id=code></pre id=code>

~ ~ ~ ~ ~ ~ ~
Chris Charlton <i>- DMXzone Manager</i>
<font size=1>[ Studio MX/MX2004 | PHP/ASP | SQL | XHTML/CSS | XML | Actionscript | Web Accessibility | MX Extensibility ]</font id=size1>

Reply to this topic