Hello Monks,

I have a placeholder problem (which is most likey something silly) where the "?" is being assigned a literal string instead of the column name. A code extract is below (@reults is a list of caseids):

use strict; use Template; use CGI; use CGI::Session ( '-ip_match' ); use DBI; use Data::Dumper; use Sphinx::Search; require "lib/class.pm"; my $cgi = new CGI; my $dbh = new_dbh(); my $sph = sphinx_conn(); my $query = $cgi->param('search_index'); my $index = "cases"; my $field = $cgi->param('field'); my $col = "case_header"; my $header; .... foreach my $x(@results){ my $sth = $dbh->prepare("SELECT ?,status,DATE_FORMAT(added_date, \ +"%d/%m/%Y\") from cases where caseid = ?"); $sth->execute($col,$x); while (my @row = $sth->fetchrow_array()) { my $docs = \@row; my $bar = \%options; my $excerpts = $sph->BuildExcerpts($docs,$index, $query, $bar) +; my @deref_excerpts = @$excerpts; unshift (@deref_excerpts,$x); push (@send_to_template,\@deref_excerpts); } }
The result is "case_header" for all results in the case_header column instead of the actual results. The other columns display the correct result. If I use $col in the SQL query instead of the firs "?" I get the expected results. Can anyone spot what I have done!?


In reply to SQL Placeholder oddity by packetstormer

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.