tejas
tejas

Reputation: 27

How to get particular columns from database

I want only 4 columns from database in below I have to get only 4 column from database for displaying in textfield please give suggestion for that. The table is shown below thank you

enter image description here

    $sql_getnm = "SELECT * FROM util WHERE util_head IN ('wc_email', 'wc_contact_us', 'wc_mobile', 'wc_google_map');";
                $result_getnm = $connect->query($sql_getnm); 
                while($row_getnm = $result_getnm->fetch_array()) 

          $util_value_email_data=?
          $util_value_mobile_data=?;
          $util_value_map_data=?;
          $util_value_data=?;               

html form

 <form  id="submitForm" method="post"  role="form" name="hl_form" method="post"  enctype="multipart/form-data">
          <div class="box-body">
                   <div class="form-group">
                      <label for="mobile_number">Email*</label>
                      <input class="form-control" id="util_value_email" name="util_value_email" value="<?Php echo $util_value_email_data;  ?>" maxlength="250"  placeholder="Enter Email Address" type="text">
                   </div>
                   <div class="form-group">
                      <label for="mobile_number">Mobile*</label>
                      <input class="form-control" id="util_value_mobile" name="util_value_mobile" value="<?Php echo $util_value_mobile_data; ?>" maxlength="250"  placeholder="Enter Mobile Number" type="text">
                   </div>
                   <div class="form-group">
                      <label for="mobile_number">Map*</label>
                      <input class="form-control" id="util_value_map" name="util_value_map" value="<?Php echo $util_value_map_data;  ?>" maxlength="250"  placeholder="Enter Map Address" type="text">
                   </div>
                   <div class="form-group">
                        <label for="description" class="required">Description*</label>
                        <textarea class="form-control" style="resize: none;" id="util_value"  name="util_value" rows="3" placeholder="Enter Description"><?Php  echo $util_value_data; ?></textarea>
                   </div>
                    <div class="box-footer">
                    <button type="submit" name="submit" class="btn btn-primary">Submit</button>
                  </div>
        </form>

Upvotes: 1

Views: 80

Answers (2)

Yogendrasinh
Yogendrasinh

Reputation: 895

Below is the code from which you can get all the four data that you want.

$sql_getnm = "SELECT * FROM util WHERE util_head IN ('wc_email', 'wc_contact_us', 'wc_mobile', 'wc_google_map');";
$result_getnm = $connect->query($sql_getnm);

while($row_getnm = $result_getnm->fetch_array()) {
    if($row_getnm['util_head'] == 'wc_email'){
        $util_value_email_data = $row_getnm['util_value'];
    }
    if($row_getnm['util_head'] == 'wc_contact_us'){
        $util_value_contact_data = $row_getnm['util_value'];
    }
    if($row_getnm['util_head'] == 'wc_mobile'){
        $util_value_mobile_data = $row_getnm['util_value'];
    }
    if($row_getnm['util_head'] == 'wc_google_map'){
        $util_value_map_data = $row_getnm['util_value'];
    }
}

Upvotes: 1

Shanteshwar Inde
Shanteshwar Inde

Reputation: 1466

You need to replace * with columns name with comma separation.

$sql_getnm = "SELECT Columname1,Columname2,Columname3,Columname4 FROM util WHERE util_head IN ('wc_email', 'wc_contact_us', 'wc_mobile', 'wc_google_map');";
$result_getnm = $connect->query($sql_getnm); 
while($row = mysql_fetch_array($result_getnm, MYSQL_ASSOC) 

          $util_value_email_data= $row['Columname1'];
          $util_value_mobile_data= $row['Columname2'];
          $util_value_map_data= $row['Columname3'];
          $util_value_data= $row['Columname4'];

Upvotes: 1

Related Questions