Solved

MySQL Syntax for Limit Characters

Posted on 2007-11-30
10
580 Views
Last Modified: 2008-02-01
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
Comment
Question by:pda4me
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 20

Expert Comment

by:steelseth12
ID: 20382422
SELECT distinct program FROM course_Finder ORDER BY program ASC LIMIT 0,25
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 20382429
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
 
LVL 10

Expert Comment

by:dis1931
ID: 20382434
Hello pda4me,

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

Regards,

dis1931
0
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
LVL 20

Expert Comment

by:Gawai
ID: 20382477
you can use a keyword LIMIT
0
 

Author Comment

by:pda4me
ID: 20382608
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
 

Author Comment

by:pda4me
ID: 20382632
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
 
LVL 21

Accepted Solution

by:
nizsmo earned 500 total points
ID: 20385892
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
 
LVL 21

Expert Comment

by:nizsmo
ID: 20385898
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
 

Author Comment

by:pda4me
ID: 20386562
Thanks Nizsmo!
0
 
LVL 21

Expert Comment

by:nizsmo
ID: 20386953
glad to be of assistance :)
0

Featured Post

Get Actionable Data from Your Monitoring Solution

Your communication platform is only as good as the relevance of the information you send. Ensure your alerts get to the right people every time with actionable responses. Create escalation rules that ensure everyone follows the process and nothing is left to chance.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to implement server side field validation and display customized error messages to the client.
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question