Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 586
  • Last Modified:

MySQL Syntax for Limit Characters

How do I alter the following SQL Syntact to limit only 25 characters being returned?

SELECT distinct program FROM course_Finder ORDER BY program ASC
0
pda4me
Asked:
pda4me
1 Solution
 
steelseth12Commented:
SELECT distinct program FROM course_Finder ORDER BY program ASC LIMIT 0,25
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
you mean 25 characters of the column program?

SELECT distinct substr(program,1,25) FROM course_Finder ORDER BY substr(program,1,25) ASC
0
 
dis1931Commented:
Hello pda4me,

Try:
SELECT distinct LEFT(program,25) FROM course_Finder ORDER BY program ASC

Regards,

dis1931
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
GawaiCommented:
you can use a keyword LIMIT
0
 
pda4meAuthor Commented:
None of those seem to be doing the trick?  Here is the full code, what am I doing wrong?

mysql_select_db($database_memLook, $memLook);
$query_Program = "SELECT distinct program FROM course_Finder ORDER BY program ASC";
$Program = mysql_query($query_Program, $memLook) or die(mysql_error());
$row_Program = mysql_fetch_assoc($Program);
$totalRows_Program = mysql_num_rows($Program);
0
 
pda4meAuthor Commented:
I am using this to populate a select dropdown form element...is it possible to just limit the characters on the form element?

<select name="program" class="search">
         <option value="">-- sort by --</option>
         <?php
do {  
?>
         <option value="<?php echo $row_Program['program']?>"><?php echo $row_Program['program']?></option>
         <?php
} while ($row_Program = mysql_fetch_assoc($Program));
  $rows = mysql_num_rows($Program);
  if($rows > 0) {
      mysql_data_seek($Program, 0);
        $row_Program = mysql_fetch_assoc($Program);
  }
?>
            </select>
0
 
nizsmoDeveloperCommented:
You can limit the characters to 25 max like this (in PHP):
<select name="program" class="search">
         <option value="">-- sort by --</option>
         <?php
do {  
?>
         <option value="<?php echo $row_Program['program']; ?>"><?php echo substr($row_Program['program'],0,25); ?></option>
         <?php
} while ($row_Program = mysql_fetch_assoc($Program));
  $rows = mysql_num_rows($Program);
  if($rows > 0) {
      mysql_data_seek($Program, 0);
        $row_Program = mysql_fetch_assoc($Program);
  }
?>
            </select>
            
            

Open in new window

0
 
nizsmoDeveloperCommented:
I didn't do it for your value attribute of your options tag, since I was unsure if you want to limit the string to 25 characters there. If you do, it is exactly the same procedure.
0
 
pda4meAuthor Commented:
Thanks Nizsmo!
0
 
nizsmoDeveloperCommented:
glad to be of assistance :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now