Solved

MySQL Syntax for Limit Characters

Posted on 2007-11-30
10
573 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
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 142

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
 
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

762 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now