Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

Using PHP variable inside MySQL recordset

Participant ,
Mar 06, 2009 Mar 06, 2009

Copy link to clipboard

Copied

Can someone let me know if this is possible? I'm trying to use a variable inside a recordset. The code below is what I have at present but it white screens me when I try open it the page in the browser. $qualificationchoice is the variable (line 3)


mysql_select_db($database_con_rsca, $con_rsca);
$query_rs_Instructorsearch = sprintf("SELECT * FROM rsca_users WHERE rsca_public_region = %s AND rsca_public_"$qualificationchoice" = %s", GetSQLValueString($colname_rs_Instructorsearch, "text"),GetSQLValueString($colname2_rs_Instructorsearch, "int"));
$rs_Instructorsearch = mysql_query($query_rs_Instructorsearch, $con_rsca) or die(mysql_error());
$row_rs_Instructorsearch = mysql_fetch_assoc($rs_Instructorsearch);
$totalRows_rs_Instructorsearch = mysql_num_rows($rs_Instructorsearch);
TOPICS
Server side applications

Views

586
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 06, 2009 Mar 06, 2009

Copy link to clipboard

Copied

maybe try {$qualificationchoice}

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 06, 2009 Mar 06, 2009

Copy link to clipboard

Copied

davecheet wrote:
> The code below is what I have at present but it white
> screens me when I try open it the page in the browser.

Getting a white screen means that you don't have display_errors turned
on in your development environment. If you did, you would see that the
problem is a syntax error, caused by your use of quotes. Remove the
quotes from around $qualificationchoice.

--
David Powers
Adobe Community Expert, Dreamweaver
http://foundationphp.com

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 06, 2009 Mar 06, 2009

Copy link to clipboard

Copied

Thanks 10191 - the { } tip worked brilliantly!!


Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 06, 2009 Mar 06, 2009

Copy link to clipboard

Copied

Any chance you can help me with phase 2.
I'm trying to get determine $qualificationchoice by the setting of a form menu $_POST['qualification']

I know I'm close but it just won't quite work

Here's what I have right now:

*************************
if (isset($_POST['qualification'])) {
$colname2_rs_Instructorsearch = (get_magic_quotes_gpc()) ? $_POST['qualification'] : addslashes($_POST['qualification']);
}
//code to set qualification choice
if($_POST['qualification']==1) {$qualificationchoice="CWA";}
elseif ($_POST['qualification']==2) {$qualificationchoice="SPA";}
elseif ($_POST['qualification']==3) {$qualificationchoice="WGL";}
elseif ($_POST['qualification']==4) {$qualificationchoice="ML";}
elseif ($_POST['qualification']==5) {$qualificationchoice="MLW";}
elseif ($_POST['qualification']==6) {$qualificationchoice="MIA";}
elseif ($_POST['qualification']==7) {$qualificationchoice="MIC";}
elseif ($_POST['qualification']==8) {$qualificationchoice="guide";}
// code to set qualification choice ends

$colname_rs_Instructorsearch = "-1";
if (isset($_POST['region'])) {
$colname_rs_Instructorsearch = (get_magic_quotes_gpc()) ? $_POST['region'] : addslashes($_POST['region']);
}
mysql_select_db($database_con_rsca, $con_rsca);
$query_rs_Instructorsearch = sprintf("SELECT * FROM rsca_users WHERE rsca_public_region = %s AND rsca_public_{$qualificationchoice} = 1 AND rsca_public_listme =1 AND expired =0", GetSQLValueString($colname_rs_Instructorsearch, "text"));
$rs_Instructorsearch = mysql_query($query_rs_Instructorsearch, $con_rsca) or die(mysql_error());
$row_rs_Instructorsearch = mysql_fetch_assoc($rs_Instructorsearch);
$totalRows_rs_Instructorsearch = mysql_num_rows($rs_Instructorsearch);
?>

*************************************

Any suggestion would be great

Thanks


Dave

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 07, 2009 Mar 07, 2009

Copy link to clipboard

Copied

LATEST
Okay,

sorry folks, Ignore my last message. I seem to have been a bit stupid here. Thanks to the { } revelation i've now realised I can do exactly what I want in a more direct way - by incorporating the input form the drop down menu directly into the recordset like this:

FROM rsca_users WHERE rsca_public_region = %s AND rsca_public_{$_POST['qualification']}

Which I'm sure will work but I when I open the page now I get
An error message "Unknown column 'rsca_public_' in 'where clause'."

I guess the page is try ing to create the recordset and not finding a value for $_POST['qualification'] as it hasn't been submitted yet.

I tested that theory by adding a line that assigns $_POST['qualification'] a value at the top of the page and the page opens but the drop down menu doesn't seem to change $_POST['qualification'] after that.

I could really do with a little pointer here as I'm not sure where to look for the solution.

Cheers


Dave

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines