Login Register






Small SQL data retrieval script. filter_list
Author
Message
Small SQL data retrieval script. #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.

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]
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

Reply

RE: Small SQL data retrieval script. #2
Thanks for the share, but how would I use it?

Reply

RE: Small SQL data retrieval script. #3
(01-30-2013, 01:54 PM)Kinanizer Wrote: Thanks for the share, but how would I use it?

Set it up correctly, with your SQL details in config.php.
Then, on a page, include config.php which includes functions.php so you'll have the function.

PHP Code:
$id = getinfo("users", "name", $name, "id");

"users" = the table name
"name" = select a column that matches the next variable with this. so since $name is "admin", this says match column where the name is admin
$name = "admin"
"id" = getting the row, "id"
[Image: 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

Reply

RE: Small SQL data retrieval script. #4
It'd help if you gave out a full explanation of what this actually does. But nice post.
[Image: F4Z9Dqw.png]

Reply

RE: Small SQL data retrieval script. #5
(02-04-2013, 12:29 AM)BreShiE Wrote: It'd help if you gave out a full explanation of what this actually does. But nice post.


"Small SQL Data Retrieval Script"

"It's easier because you only need to use a function for getting column data from the database."
[Image: 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

Reply