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

Link to comment
Share on other sites

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);
    }
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.