I was bored and made this little function. It only really works for getting info from one row of a table that you specify the id or whatever from the $_GET['uname'] part. (I was testing it on a users table). You specifiy the table name and the field you want, db_q('tablename', 'fieldname'); when you use the function
i'm sorta newb, blah
code:
<?php
// db function
function db_q($table, $field){
// get variable
$get_name = $_GET['uname'];
// db query
$db_query = mysql_query("SELECT * FROM $table WHERE id = $get_name");
// db fetch array
while($query_row = mysql_fetch_array($db_query)){
// query result
$query_result = $query_row[$field];
}
// return result
return $query_result;
}
// using the function
// echo html table part
echo('<table border="1">
<tr>
<td>
');
// run function
$display_result = db_q('users', 'username');
// echo result from function returned
echo('' . $display_result . '');
// echo html table bit
echo('
</td>
<td>
');
// run function with another table field used
$display_result = db_q('users', 'website');
// echo this field's result
echo('' . $display_result . '');
// echo end of html table
echo('
</td>
</tr>
</table>
');
?>