Welcome to Geeklog, Anonymous Wednesday, November 27 2024 @ 10:44 pm EST
Geeklog Forums
PHP Block Database Report
I'm looking to create a special report within a static page that would query specific information from a database. Has anyone done this previously and have any sample code?
Any information that you may be able to provide would be greatly appreciated, thanks!
Any information that you may be able to provide would be greatly appreciated, thanks!
6
5
Quote
564
Anonymous
Normal PHP Code:
$db = "database_name";
$link = mysql_connect("localhost",USERNAME,PASSWORD)or die("Connect Error: ".mysql_error());
mysql_select_db($db , $link)
or die("Select DB Error: ".mysql_error());
That is the code to connect to a database. Put in your "database_name", username and password.
Now use SQL queries to get info from the database. Refer to PHP/MYSQL Manuals for more info.
Text Formatted Code
$db = "database_name";
$link = mysql_connect("localhost",USERNAME,PASSWORD)or die("Connect Error: ".mysql_error());
mysql_select_db($db , $link)
or die("Select DB Error: ".mysql_error());
That is the code to connect to a database. Put in your "database_name", username and password.
Now use SQL queries to get info from the database. Refer to PHP/MYSQL Manuals for more info.
5
6
Quote
Status: Banned
machinari
Forum User
Full Member
Registered: 03/22/04
Posts: 1512
there are many phpblocks hanging around that will serve you as perfect guidelines. check the downloads section here and I think the faq has some links to where you can get stuff for geeklog like blocks, etc. Most of the geeklog code itself has tons of database query stuff that will guide your efforts.
DON'T use your db username and password in the phpblock. there is no need to connect to the db or disconnect or anything like that. if you are using the phpblock within the confines of your geeklog pages, that is all taken care of for you.
so all you need is a quick and easy to read tutorial on how to use the "SELECT" query for mySQL.
once you've selected your data, loop thru your result set and display/echo the data using basic HTML. done
DON'T use your db username and password in the phpblock. there is no need to connect to the db or disconnect or anything like that. if you are using the phpblock within the confines of your geeklog pages, that is all taken care of for you.
so all you need is a quick and easy to read tutorial on how to use the "SELECT" query for mySQL.
once you've selected your data, loop thru your result set and display/echo the data using basic HTML. done
10
5
Quote
Status: offline
jbpaul17
Forum User
Chatty
Registered: 05/14/04
Posts: 49
Location:New York City
So, if I shouldn't use the db username and password in phpblock, could someone give me (or point me to samples) of how to connect to the GL database, how to pull data out, and how to display it. I'm familiar with SQL, so I'll be fine concocting the statements to pull the data out... I just need some sample code to get me going... you know, something along the lines of "Hello world!"...
5
6
Quote
Status: Banned
machinari
Forum User
Full Member
Registered: 03/22/04
Posts: 1512
using geeklog syntax/db functions
function phpblock_yourfunction()
{
global $_TABLES;
$result = DB_query("SELECT yourfield FROM {$_TABLES['yourtable']} WHERE yourotherfield='yourdata' LIMIT 10");
while ($A = DB_fetchArray($result)){
$retval .= '<p>' . $A['yourfield'] . '</p>';
}
return $retval;
}
perhaps the mysql manual would tell you what you want to know...
Text Formatted Code
function phpblock_yourfunction()
{
global $_TABLES;
$result = DB_query("SELECT yourfield FROM {$_TABLES['yourtable']} WHERE yourotherfield='yourdata' LIMIT 10");
while ($A = DB_fetchArray($result)){
$retval .= '<p>' . $A['yourfield'] . '</p>';
}
return $retval;
}
perhaps the mysql manual would tell you what you want to know...
5
3
Quote
All times are EST. The time is now 10:44 pm.
- Normal Topic
- Sticky Topic
- Locked Topic
- New Post
- Sticky Topic W/ New Post
- Locked Topic W/ New Post
- View Anonymous Posts
- Able to post
- Filtered HTML Allowed
- Censored Content