Small SQL data retrieval script. 01-30-2013, 04:39 AM
#1
I know this script may seem useless to some of you, but hey, it helps meout and I thought I'd post it. It's easier because you only need to use a function for getting column data from the database. Plus, if you ever need to edit something there's only 1 place to edit it.
For example, getting a users ID:
In config.php:
In functions.php;
PHP Code:
$result = getinfo("table", "columntocheck", "dataforcolumntocheck", "getrow");
For example, getting a users ID:
PHP Code:
$result = getinfo("users", "name", $name, "id");
In config.php:
PHP Code:
<?php
$dbconnect = new mysqli("host", "username", "password", "database");
include 'functions.php';
?>
In functions.php;
PHP Code:
<?php
function getinfo($from, $where, $input, $getrow)
{
if ($result = $GLOBALS['dbconnect']->query("SELECT * FROM $from WHERE $where='$input'"))
{
while ($row = $result->fetch_assoc())
{
$endresult = $row["$getrow"];
}
if ($endresult != "")
{
return $endresult;
}
else
{
return "$where does not exist!";
}
$endresult->free();
$result->free();
}
}
?>
![[Image: BAvhP6h.png]](http://i.imgur.com/BAvhP6h.png)
Code:
[5:42:25 PM] i0xillusi0n: Breshie don't bust a nut over chloe now
[5:42:31 PM] Entity: fapfapfapfapfapfapfapfapfapfap
[5:42:33 PM] Jigglypuff | SL: EWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW