-1

How to get one specific row of all column fields from a mySQL database in PHP?

How would I do this, code wise? If you do respond, could you dumb it down for someone with very little experience?

Or could someone give me the code? Sorry if that is frowned upon,but I tried writing my own, but my lack of understanding and general incompetence foiled me. I even tried posting my code here, but it didn't help, and I like to get at least some work done on this project. I would repost my code again, but I dont want to duplicate posts.

Adrian Cid Almaguer
  • 7,815
  • 13
  • 41
  • 63
Ro Siv
  • 161
  • 2
  • 3
  • 16
  • Please clarify your specific problem or add additional details to highlight exectly what you need. As it's currently written, it's hard to tell exactly what you are asking. See the **[How to ask page](http://stackoverflow.com/help/how-to-ask)** for clarifing this question – Amit Verma Mar 07 '15 at 13:33

1 Answers1

1

You can use mysql_fetch_field to get column information from a result and return as an object.

<?php
$conn = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$conn) {
    die('Could not connect: ' . mysql_error());
}
mysql_select_db('database');
$result = mysql_query('select * from table');
if (!$result) {
    die('Query failed: ' . mysql_error());
}
/* get column metadata */
$i = 0;
while ($i < mysql_num_fields($result)) {
    echo "Information for column $i:<br />\n";
    $meta = mysql_fetch_field($result, $i);
    if (!$meta) {
        echo "No information available<br />\n";
    }
    echo "<pre>
blob:         $meta->blob
max_length:   $meta->max_length
multiple_key: $meta->multiple_key
name:         $meta->name
not_null:     $meta->not_null
numeric:      $meta->numeric
primary_key:  $meta->primary_key
table:        $meta->table
type:         $meta->type
unique_key:   $meta->unique_key
unsigned:     $meta->unsigned
zerofill:     $meta->zerofill
</pre>";
    $i++;
}
mysql_free_result($result);
?>

Read mone in:

http://php.net/manual/en/function.mysql-fetch-field.php

Or you can use:

$result = mysql_query("SELECT names FROM Customers");
$storeArray = Array();
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
    $storeArray[] =  $row['names'];  
}
// now $storeArray will have all the names.

Read more in:

https://stackoverflow.com/a/5229533/3653989

http://php.net/manual/en/function.mysql-fetch-array.php

Community
  • 1
  • 1
Adrian Cid Almaguer
  • 7,815
  • 13
  • 41
  • 63