SELECT data WHERE id = url的一部分

时间:2015-05-07 21:54:30

标签: php mysqli

我制作了这段代码来获得" 12345"并在bithumor.co/posts/12345的mysql查询中选择它,以便查询可以SELECT数据WHERE id = 12345

实施例: 目前网址:bithumor.co/posts/12345 SELECT:数据,其中id = 12345

以下是代码:

<cfset qryColumnList = "CaseNo,Model,Name" />
<cfset qryResultSet = QueryNew(qryColumnList) />

<cfoutput query="getUsedCars">
                <cfset QueryAddRow(qryResultSet, 1) />
                <cfset querySetCell(qryResultSet, "CaseNo", caseno EQ "&nbsp;" ? "" : caseno) />
                <cfset querySetCell(qryResultSet, "Model", model EQ "&nbsp;" ? "" : model) />
                <cfset querySetCell(qryResultSet, "Name", name EQ "&nbsp;" ? "" : name) />                      
</cfoutput>

<cfscript>
                xlsxopencases = SpreadsheetNew("opencases",true);
                SpreadsheetAddRow(xlsxopencases,qryColumnList);
                SpreadsheetAddRows(xlsxopencases,qryResultSet);
                strFileName=GetDirectoryFromPath(GetCurrentTemplatePath()) & "OpenCasesReport.xlsx";
                SpreadsheetFormatRow(xlsxopencases, {bold="true"}, 1);
                SpreadsheetFormatRows(xlsxopencases, {dataformat="text"}, "1-#qryResultSet.recordcount + 1#");
                SpreadsheetFormatColumn(xlsxopencases, {dataformat="dd/MM/yy HH:mm:SS"},18);
</cfscript>

<cfspreadsheet action="write"
                                                   filename="#strFileName#"
                                                   name="xlsxopencases"
                                                   sheet="1"
                                                   sheetname="OpenCasesReport"
                                                   overwrite="true" />

<cfheader name="Content-Disposition" value="attachment; filename=OpenCasesReport.xlsx">
<cfcontent file="#strFileName#" type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" />

<cffile action="delete" file="#strFileName#" />
</cfif>

我做错了什么以及如何解决?

2 个答案:

答案 0 :(得分:0)

- 你错过了一个&#34;}&#34;关闭&#34;如果&#34;言。

- 你可以放弃&#34;如果&#34;声明: 而不是:

if ($result->num_rows > 0) 
{
    // output data of each row
    while($row = $result->fetch_assoc()) 
    {
        echo "<br><div class='entire_post'><center><img class='pro_pic' src=http://cdn.bithumor.co/pro_pics/" . $row['pro_pic']. "></center><title>" . $row['post_title']. " </title><center><font face='HelveticaNeue-Light' font size='5'>" . $row['username']. "</font> </center><center><img class='upload' src=http://cdn.bithumor.co/uploads/" . $row["content_url"]. " width='100%'></center> " . $row["id"]. "<br></div>";
     }
 }

只需使用:

while($row = $result->fetch_assoc())
{
    echo "<br><div class='entire_post'><center><img class='pro_pic' src=http://cdn.bithumor.co/pro_pics/" . $row['pro_pic']. "></center><title>" . $row['post_title']. " </title><center><font face='HelveticaNeue-Light' font size='5'>" . $row['username']. "</font> </center><center><img class='upload' src=http://cdn.bithumor.co/uploads/" . $row["content_url"]. " width='100%'></center> " . $row["id"]. "<br></div>";
 }

声明:&#34; $ result-&gt; fetch_assoc()&#34;如果$ result没有行,则返回null,并且您不会进入while循环。

答案 1 :(得分:0)

完全不可能以这种方式。通过这个,我的意思是:

http://bithumor.co/posts/12345

将无法正常执行。如果是:

http://bithumor.co/posts/?12345

这可以收集或阅读。因为这类似于index.php?12345

我建议使用网址重写。通过这种方式,您可以将URL重写为URL参数。这样,网址:

http://bithumor.co/posts/12345

可以导致

http://bithumor.co/index.php?posts=12345

然后您可以在脚本中调用变量$_GET['posts']