Retrieve Certain values

Discussion in 'PHP' started by zalFG, Feb 12, 2010.

  1. #1
    help needed....

    i have 17 values in one row of a table, but i only wanted to retrieve 15 value from that row(FieldValue) the last two values was not needed.

    sorry for my bad english...

    and thank in advance..

    [​IMG]

    <?php
    
       $con=mysql_connect("localhost","root","");
          if(!$con)
        	{
    	   	 die('Could not connect:'.mysql_error());
             }
    
    mysql_select_db("kiperak",$con);
    
    
    
    $result = mysql_query("SELECT Fieldvalue FROM kid_rsform_submission_values WHERE SubmissionId IN (SELECT SubmissionId FROM kid_rsform_submission_values WHERE FieldValue = '850830126317')");
    
    
    while($row= mysql_fetch_array($result))
    
    {
       -->" this code will show all the values in the row(FieldValue)"  echo $row[0];
    
          }
     mysql_close($con);
    
     ?>
    Code (markup):
     
    Last edited: Feb 12, 2010
    zalFG, Feb 12, 2010 IP
  2. Bohra

    Bohra Prominent Member

    Messages:
    12,573
    Likes Received:
    537
    Best Answers:
    0
    Trophy Points:
    310
    #2
    Add a LIMIT 0,15 in your mysql query
     
    Bohra, Feb 12, 2010 IP
  3. ProtegeSales

    ProtegeSales Guest

    Messages:
    88
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    No, that won't work Bohra. I think you may be confused on what ZalFG is asking.

    There is a database a table a Row and a Field Value.
    The value is what he/she wants 15 out of. Only the first 15 characters of a 17 character value.
    They need to use substr();

    From PHP.net
    If length is given and is positive, the string returned will contain at most length characters beginning from start (depending on the length of string ).

    If length is given and is negative, then that many characters will be omitted from the end of string (after the start position has been calculated when a start is negative). If start denotes a position beyond this truncation, an empty string will be returned.

    If length is given and is 0, FALSE or NULL an empty string will be returned.

    Example #2 Using a negative length
    <?php
    $rest = substr("abcdef", 0, -1);  // returns "abcde"
    ?>
    PHP:
    Also, you can access the string like an array with square brackets.

    $string = 'abcdef';
    echo $string[0];                 // a
    echo $string[3];                 // d
    PHP:
     
    ProtegeSales, Feb 13, 2010 IP
  4. koko5

    koko5 Active Member

    Messages:
    394
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    70
    #4
    Hi, just
    SELECT LEFT(Field_Name,15) ...
    Code (markup):
    Regards
     
    koko5, Feb 14, 2010 IP