dongwen7730 2014-01-23 21:11
浏览 80
已采纳

PHP试图从以某个字母开头的数组中获取字符串,给我一切

I'm trying to get strings from a my_sqli query that only start with a certain letter, however it always outputs the whole array. Here's my code, I'm trying to get the first value, see if it starts with the correct letter, then echo it if it does, then go on to the next.

$strSQL = "SELECT title FROM blogtable ORDER BY title ASC";
$titleResult = mysqli_query($con, $strSQL);

while($rowTitle = mysqli_fetch_array($titleResult))
{
    $strTitle = $rowTitle['title'];
    $subTitle = substr($strTitle,0,2);
    $subNum = ord($subTitle);//This gets me the value of the first letter
    if($subNum = $topLetter)//$topLetter = 65, which is capital A 
    {
        echo $strTitle;
        echo "<br>";
    }
}

So the problem here is that, say if I have 3 things, and only 2 start with A, it will output all 3, but I just want the 2 that start with A.

  • 写回答

1条回答 默认 最新

  • doumei8258 2014-01-23 21:13
    关注

    Change your if statement.

    if($subNum == $topLetter)
    

    Explanation: Operator == test for equality and operator = is assignment operator.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python