Php select statement and item too long

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Dilbert137
Forum Commoner
Posts: 57
Joined: Sat Jun 02, 2007 5:02 am
Location: Mauritius

Php select statement and item too long

Post by Dilbert137 »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Dear All,

Can someone help me. I'm developing a website. The issue is that when collecting data from the database to a select statement one of the item name is too long. Is there a way to wrap this item name so that it does not take a large space in the page.

Here is my codes:

Code: Select all

<select name="sel_cat">
	<option value=""></option>
		<?php
			$data = mysql_query("select Libelle_CatProd from categorie order by Libelle_CatProd") or die(mysql_error());
			while($result = mysql_fetch_array($data))
				{
					$prodCat=$result[0];
				?>
					<option value="<?php echo $prodCat ?>"><?php echo $prodCat ?></option>
				<?php
				}
				?>
</select>
Best Regards
Dilbert137


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
mentor
Forum Contributor
Posts: 100
Joined: Sun Mar 11, 2007 11:10 am
Location: Pakistan

Post by mentor »

You can use substr() to cut the string to your required length.
Dilbert137
Forum Commoner
Posts: 57
Joined: Sat Jun 02, 2007 5:02 am
Location: Mauritius

Post by Dilbert137 »

Thanks a lot. It's working now. With select no other choice than substr().

Best Regards
Dilbert137
mentor
Forum Contributor
Posts: 100
Joined: Sun Mar 11, 2007 11:10 am
Location: Pakistan

Post by mentor »

If you want to cut the string in mysql, then use MySQL's SUBSTRING() function.
Dilbert137
Forum Commoner
Posts: 57
Joined: Sat Jun 02, 2007 5:02 am
Location: Mauritius

Post by Dilbert137 »

Thanks a lot Mentor. It's the function I need.
Post Reply