#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    11
    Rep Power
    0

    Learning: MYSQL Query to get value in while loop


    Hello all,

    This is my first topic on this board. Hope will get good help from experts.

    I am trying to get value for answer form field and things are working fine but the value is displaying in every answer form field.

    For instance I have 3 answers for the question and one of the answer have audio ( mp3 file url ) so this audio ( value ) is showing in all answer's audio field. Where I want to only the answer who has the audio of course.

    Please see my code below and attached image for database.

    Important: I don't have answer ID so can't pass the ID

    PHP Code:
    <?php
    $query 
    "SELECT audio, type, pid FROM ^posts WHERE parentid={$myurl} AND type='A' AND audio IS NOT NULL";

    $result mysql_query($query);

    while(
    $audio_check mysql_fetch_assoc($result)):

        echo 
    '<TR><TD CLASS="qa-form-tall-label"><LABLE for="featured" >Audio Answer</LABLE></TD></TR>';
        echo 
    '<TR><TD CLASS-"qa-form-tall-data"><INPUT ID="audio_answer" CLASS="qa-form-tall-text" TYPE="text" NAME="audio_answer" VALUE="'.$audio_check['audio'].'" PLACEHOLDER="audio-file.mp3" /></TD></TR>';
                    
    endwhile;            

    ?>
    Not allowed to add an image:
    h-t-t-p-[collon]//s3.postimg[dot]org/rkcsr8hpv/table[dot]jpg

    Thanks a lot..
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,400
    Rep Power
    594
    First if you are just learning stop! Do not use the deprecated MySQL extensions. Switch to PDO.

    Second, if you are getting results from your query where there is no audio then your query is suspect. Perhaps the audio column in your database is not null but instead contains whitespace. Echo $audio_check to see if it contains what you expect.
    PHP Code:
    echo "<pre>";
    print_r($audio_check);
    echo 
    "</pre"\>"; 
    Last edited by gw1500se; April 1st, 2013 at 04:04 PM.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2005
    Location
    Vancouver, WA, USA
    Posts
    397
    Rep Power
    189
    gw1500se,

    Double check your typing:

    PHP Code:
    echo "</pre"\>"; 
    PHP Code:
    echo "</pre>"
    And I absolutely agree about PDO.
    Thomas Tremain
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    11
    Rep Power
    0
    Hey guyz. great working now..

    Issue was not passing the parrentid.. Thanks a lot..

    Mod can mark as resolve topic..

IMN logo majestic logo threadwatch logo seochat tools logo