?
Solved

MySQL Syntax for Limit Characters

Posted on 2007-11-30
10
Medium Priority
?
581 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 2000 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

801 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