Jump to content

Need some help with using substr in a query


jim.davidson

Recommended Posts

I got mySQL table with a field called title  I want to get a recordset of just titles of a given letter.

 

$letter = 'B';

SELECT * FROM dvds WHERE substr(title,1,1) = $letter ORDER BY title ASC;

 

I get this error

Parse error: parse error, unexpected T_STRING

 

What am I doing wrong?

Any help will be appreciated

Ok here's the code, I use this all the time the only difference is the select command.  That's why I assumed it to be something in the query that's wrong.

<?php
$letter = 'A';
$currentPage = $_SERVER["PHP_SELF"];

$maxRows_getList = 18;
$pageNum_getList = 0;
if (isset($_GET['pageNum_getList'])) {
  $pageNum_getList = $_GET['pageNum_getList'];
}
$startRow_getList = $pageNum_getList * $maxRows_getList;

mysql_select_db($my_database, $my_id);

$query_getList = "SELECT * FROM dvds, dvd_genres, dvd_ratings WHERE substr(dvds.title,1,1)=$letter AND dvds.rating=dvd_ratings.rating_id AND dvds.genres=dvd_genres.genres_id ORDER BY dvds.title ASC";


$query_limit_getList = sprintf("%s LIMIT %d, %d", $query_getList, $startRow_getList, $maxRows_getList);
$getList = mysql_query($query_limit_getList, $my_id) or die(mysql_error());
$row_getList = mysql_fetch_assoc($getList);

if (isset($_GET['totalRows_getList'])) {
  $totalRows_getList = $_GET['totalRows_getList'];
} else {
  $all_getList = mysql_query($query_getList);
  $totalRows_getList = mysql_num_rows($all_getList);
}
$totalPages_getList = ceil($totalRows_getList/$maxRows_getList)-1;

$queryString_getList = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_getList") == false && 
        stristr($param, "totalRows_getList") == false) {
      array_push($newParams, $param);
    }
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.