472,122 Members | 1,498 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,122 software developers and data experts.

php mysql select substring

Bonjour,
j'ai une table : matable
dans laquelle j'ai un champs : codepostal

Ce champs code postal est rempli d'enregistrements qui ont des valeurs
de 5 chiffres.
Je souhaite créer un bouton qui va sélectionner les enregistrements
dont la valeur du code postal commence par les 2 premiers chiffres
(ici par le chiffre 76).

J'ai écrit le code suivant pour la sélection...et ca ne fonctionne pas
!

$query_rs_epartners = "SELECT * FROM matable WHERE
SUBSTRING(codepostal, 2)=76";

Donc dans ce cas, je souhaite afficher les enregistrements dont le
code postal commence par 76

Qu'y a il de faux ?

D'avance MERCI
Jul 19 '05 #1
9 11023
jossinet wrote:
$query_rs_epartners = "SELECT * FROM matable WHERE
SUBSTRING(codepostal, 2)=76";


I have no idea what you are asking, because you didn't use English, but
I try to answer anyway. Here is an example how substring is used:

mysql> SELECT SUBSTRING('Quadratically',5);
-> 'ratically'

It will return a string, not a number. If you have a string like '1276'
in your codepostal column and you would like to find that column in your
select, you could perhaps do something like:

select * from matable where substring(codepostal,2)='76';

Note that '76' is a string and 76 is a number.

More info about string functions:
http://www.mysql.com/doc/en/String_functions.html
Jul 19 '05 #2
jossinet wrote:
$query_rs_epartners = "SELECT * FROM matable WHERE
SUBSTRING(codepostal, 2)=76";


I have no idea what you are asking, because you didn't use English, but
I try to answer anyway. Here is an example how substring is used:

mysql> SELECT SUBSTRING('Quadratically',5);
-> 'ratically'

It will return a string, not a number. If you have a string like '1276'
in your codepostal column and you would like to find that column in your
select, you could perhaps do something like:

select * from matable where substring(codepostal,2)='76';

Note that '76' is a string and 76 is a number.

More info about string functions:
http://www.mysql.com/doc/en/String_functions.html
Jul 19 '05 #3
jossinet wrote:
$query_rs_epartners = "SELECT * FROM matable WHERE
SUBSTRING(codepostal, 2)=76";


I have no idea what you are asking, because you didn't use English, but
I try to answer anyway. Here is an example how substring is used:

mysql> SELECT SUBSTRING('Quadratically',5);
-> 'ratically'

It will return a string, not a number. If you have a string like '1276'
in your codepostal column and you would like to find that column in your
select, you could perhaps do something like:

select * from matable where substring(codepostal,2)='76';

Note that '76' is a string and 76 is a number.

More info about string functions:
http://www.mysql.com/doc/en/String_functions.html
Jul 19 '05 #4
Aggro <sp**********@yahoo.com> wrote in message news:<rv***************@read3.inet.fi>...
jossinet wrote:
$query_rs_epartners = "SELECT * FROM matable WHERE
SUBSTRING(codepostal, 2)=76";


I have no idea what you are asking, because you didn't use English, but
I try to answer anyway. Here is an example how substring is used:

mysql> SELECT SUBSTRING('Quadratically',5);
-> 'ratically'

It will return a string, not a number. If you have a string like '1276'
in your codepostal column and you would like to find that column in your
select, you could perhaps do something like:

select * from matable where substring(codepostal,2)='76';

Note that '76' is a string and 76 is a number.

More info about string functions:
http://www.mysql.com/doc/en/String_functions.html

Thank you for the answer...but it still doesn't work.
I have a table : matable
A column : codepostal

The codepostal is a number with 5 numbers (it's a zip code like 55250)
I want to select only the two first numbers of the codepostal that correspond to 76.
For instance if the codepostal is 76890, it should be selected.
If the codepostal is 47620, it should not be selected.
So, I tried to write :
select * from matable where substring(codepostal,0,2)='76';
But nothing is selected....and I have some codepostal that start with 76 !
Thank You
Jul 19 '05 #5
Aggro <sp**********@yahoo.com> wrote in message news:<rv***************@read3.inet.fi>...
jossinet wrote:
$query_rs_epartners = "SELECT * FROM matable WHERE
SUBSTRING(codepostal, 2)=76";


I have no idea what you are asking, because you didn't use English, but
I try to answer anyway. Here is an example how substring is used:

mysql> SELECT SUBSTRING('Quadratically',5);
-> 'ratically'

It will return a string, not a number. If you have a string like '1276'
in your codepostal column and you would like to find that column in your
select, you could perhaps do something like:

select * from matable where substring(codepostal,2)='76';

Note that '76' is a string and 76 is a number.

More info about string functions:
http://www.mysql.com/doc/en/String_functions.html

Thank you for the answer...but it still doesn't work.
I have a table : matable
A column : codepostal

The codepostal is a number with 5 numbers (it's a zip code like 55250)
I want to select only the two first numbers of the codepostal that correspond to 76.
For instance if the codepostal is 76890, it should be selected.
If the codepostal is 47620, it should not be selected.
So, I tried to write :
select * from matable where substring(codepostal,0,2)='76';
But nothing is selected....and I have some codepostal that start with 76 !
Thank You
Jul 19 '05 #6
Aggro <sp**********@yahoo.com> wrote in message news:<rv***************@read3.inet.fi>...
jossinet wrote:
$query_rs_epartners = "SELECT * FROM matable WHERE
SUBSTRING(codepostal, 2)=76";


I have no idea what you are asking, because you didn't use English, but
I try to answer anyway. Here is an example how substring is used:

mysql> SELECT SUBSTRING('Quadratically',5);
-> 'ratically'

It will return a string, not a number. If you have a string like '1276'
in your codepostal column and you would like to find that column in your
select, you could perhaps do something like:

select * from matable where substring(codepostal,2)='76';

Note that '76' is a string and 76 is a number.

More info about string functions:
http://www.mysql.com/doc/en/String_functions.html

Thank you for the answer...but it still doesn't work.
I have a table : matable
A column : codepostal

The codepostal is a number with 5 numbers (it's a zip code like 55250)
I want to select only the two first numbers of the codepostal that correspond to 76.
For instance if the codepostal is 76890, it should be selected.
If the codepostal is 47620, it should not be selected.
So, I tried to write :
select * from matable where substring(codepostal,0,2)='76';
But nothing is selected....and I have some codepostal that start with 76 !
Thank You
Jul 19 '05 #7
jossinet wrote:
So, I tried to write :
select * from matable where substring(codepostal,0,2)='76';
But nothing is selected....and I have some codepostal that start with 76 !


Next time you encounter a problem like this, try instead to find out
what it is that you are actually selecting. i.e.:
select substring(codepostal,0,2) as sub from matable;

As you can see, it returns empty strings, the reason for that would been
found from the manual, because string index doesn't start from 0, it
starts from 1.

So what you need is:
select * from matable where substring(codepostal,1,2)='76';
Jul 19 '05 #8
jossinet wrote:
So, I tried to write :
select * from matable where substring(codepostal,0,2)='76';
But nothing is selected....and I have some codepostal that start with 76 !


Next time you encounter a problem like this, try instead to find out
what it is that you are actually selecting. i.e.:
select substring(codepostal,0,2) as sub from matable;

As you can see, it returns empty strings, the reason for that would been
found from the manual, because string index doesn't start from 0, it
starts from 1.

So what you need is:
select * from matable where substring(codepostal,1,2)='76';
Jul 19 '05 #9
jossinet wrote:
So, I tried to write :
select * from matable where substring(codepostal,0,2)='76';
But nothing is selected....and I have some codepostal that start with 76 !


Next time you encounter a problem like this, try instead to find out
what it is that you are actually selecting. i.e.:
select substring(codepostal,0,2) as sub from matable;

As you can see, it returns empty strings, the reason for that would been
found from the manual, because string index doesn't start from 0, it
starts from 1.

So what you need is:
select * from matable where substring(codepostal,1,2)='76';
Jul 19 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Ruby Tuesday | last post: by
reply views Thread by jossinet | last post: by
reply views Thread by Mike Chirico | last post: by
3 posts views Thread by Leonardo Javier Bel?n | last post: by
4 posts views Thread by phpuser32423 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.