Urgent : Fetch data from a filed whose first character is number not alphabet??

Discussion in 'PHP' started by pradipkeya, Aug 5, 2008.

  1. #1
    Hi I want to fetch data from a table whose first charater must be numebr not the character.

    The table structure is here


    CREATE TABLE `jos_seyret_authors` (
    `id` int(11) NOT NULL auto_increment,
    `authorname` varchar(100) NOT NULL,
    PRIMARY KEY (`id`)
    ) ENGINE=MyISAM AUTO_INCREMENT=15 DEFAULT CHARSET=latin1 AUTO_INCREMENT=15 ;

    --
    -- Dumping data for table `jos_seyret_authors`
    --

    INSERT INTO `jos_seyret_authors` VALUES (14, 'Bow Bow');
    INSERT INTO `jos_seyret_authors` VALUES (5, 'Kenshin');
    INSERT INTO `jos_seyret_authors` VALUES (6, '50 Cent');
    INSERT INTO `jos_seyret_authors` VALUES (7, 'Usher');
    INSERT INTO `jos_seyret_authors` VALUES (8, 'T-Vice');
    INSERT INTO `jos_seyret_authors` VALUES (9, '2Pac');
    INSERT INTO `jos_seyret_authors` VALUES (10, 'Sweet Micky');
    INSERT INTO `jos_seyret_authors` VALUES (11, 'Ne-Yo');
    INSERT INTO `jos_seyret_authors` VALUES (12, 'The Dream');

    I want to fetch this values from my sql
    50 Cent
    2Pac

    Like this many valuse will be there.

    Thanks in advance for your help,
    Pradip
     
    pradipkeya, Aug 5, 2008 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    MySQL doesn't have a numeric validator.

    But, I think something like this would work.

    SELECT * FROM jos_seyret_authors WHERE CONVERT(LEFT(TRIM(authorname),1), SIGNED INTEGER) IS NOT NULL
     
    jestep, Aug 5, 2008 IP
  3. Le4rner

    Le4rner Active Member

    Messages:
    80
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    93
    #3
    
    
    $artist_array = array();
    $quer = "Select * from tablenameHere";
     $result = mysql_query($quer);
      While($rows = mysql_fetch_assoc($result)){
        if(is_int(substr($rows['authorname'], 0, 1))){
            $artist_array[] = array(
                                           'artist' => $rows['authorname'],
                                           'id'      => $rows['id']
                                          );
        }
      }
    
    print_r($artist_array);
    
    PHP:
    Try that
     
    Le4rner, Aug 5, 2008 IP