简体   繁体   中英

PHP mySQL get all the headers of the table and values

I have connected to a table of the database and found a row by using the unique column header 'name';

I want a function now that allows me to get the value for each of the headers. Then an echo for each eg. $post->header1; $post->header2; post->header3;

etc...

How do we do this

EDIT

THIS returns one field. It seams overly expensive to do this for each one. Can we not grab them all in an array or something like that... and how?

function get($table,$name,$field){
    $the_page = mysql_query("SELECT * FROM $table WHERE name = '$name'"); while($row = mysql_fetch_array($the_page)) { return $row[$field]; }
};

Fetch the mySQL array as a variable and then return the result inside a variable with the table name as the column in question.

$find = mysql_query("SELECT * FROM $table WHERE name = '$post'"); 
    $find = mysql_fetch_array($find);

<?php echo $find['title'];?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM