Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > vBulletin 3 Articles

Reply
 
Thread Tools
SELECT FROM database
flup's Avatar
flup
Join Date: Jan 2002
Posts: 872

 

Maastricht, NL
Show Printable Version Email this Page Subscription
flup flup is offline 05-01-2003, 10:00 PM

Ok, next step is to get information FROM a database, and let it display on your webpage.
__________________________________________________

We are still using the same table as in the previous artikel (tabel)
I will give you the code, and then explain it all to you.
PHP Code:
<?php

mysql_connect
("host","user","password");
mysql_select_db("databasenaam");

$select "SELECT * FROM tabel";
$query mysql_query($select)or die(mysql_error());
?>
In this part we have called ALL (*) information from table tabel, in this script it won't display anything.

The part above, the connection to the database, has been explained in the previous aricle
PHP Code:
$select "SELECT * FROM tabel";
$query mysql_query($select)or die(mysql_error()); 
Select all (*) from the database, or give me the mysql error.
Very easy IMO

Now let's go to the next step!! Show the results on a webpage.
PHP Code:
<?php

mysql_connect
("host","user","password");
mysql_select_db("databasenaam");

$select "SELECT * FROM tabel";
$query mysql_query($select)or die(mysql_error());

while(
$list mysql_fetch_object($query)){

echo 
"$list->naam
"
;
echo 
"$list->email
"
;
echo 
"$list->titel
"
;
echo 
"$list->info";

?>
Ok, now we've displayed all information of table tabel, on a page.
I assume you don't really know what is going on, so i'll explain the part to you
PHP Code:
while($list mysql_fetch_object($query)){

$list is replace-able with al things you wantactually it says
$list show everything from the table

echo "$list->naam
"
;
echo 
"$list->email
"
;
echo 
"$list->titel
"
;
echo 
"$list->info"
The echo code you will know i guess, this is just a simple code to write something on a webpage, everything you want to echo, has to be in the double quote ("). Things here displayed are:
naam, email, titel, info

And like you see, it will display all info, the layout of this is quite simple, but you can edit it all the way you want (per example add it into a table)
When you've openen an echo code, don't use double quote in the double quotes, but use singel quotes instead.



To go one more step deeper into mySQL i want to explain the WHERE function in a mySQL query:
PHP Code:
<?php

mysql_connect
("host","user","password");
mysql_select_db("databasenaam");

$select "SELECT * FROM tabel WHERE naam='flup'";
$query mysql_query($select)or die(mysql_error());

while(
$list mysql_fetch_object($query)){

echo 
"$list->naam
"
;
echo 
"$list->email
"
;
echo 
"$list->titel
"
;
echo 
"$list->info";

?
'>
Like you see i've only edited a little part of the query, and that is:
WHERE naam='flup'

Or: Selected everything in the table 'table' where 'naam' is equal to flup

You also could replace: naam='flup' to email='your@email.com' or titel='administrator'

Good luck!!
Reply With Quote
  #2  
Old 05-02-2003, 09:01 AM
flup's Avatar
flup flup is offline
 
Join Date: Jan 2002
Location: Maastricht, NL
Posts: 872
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

<a href="https://vborg.vbsupport.ru/showthread.php?s=&threadid=52456" target="_blank">Click here for the tutorial: Instert into database</a>
Reply With Quote
  #3  
Old 05-02-2003, 05:51 PM
Dean C's Avatar
Dean C Dean C is offline
 
Join Date: Jan 2002
Location: England
Posts: 9,071
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Wow you use fetch_object - i never use classes,methods or objects apart from the built in $db_site object in vbulletin

- miSt
Reply With Quote
  #4  
Old 05-02-2003, 06:46 PM
flup's Avatar
flup flup is offline
 
Join Date: Jan 2002
Location: Maastricht, NL
Posts: 872
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hmmmz, getch_object works good very good IMO.
But this tutorials is more for the noobs wich are going to test this outside vB
Reply With Quote
  #5  
Old 06-03-2006, 10:23 PM
jim6763nva's Avatar
jim6763nva jim6763nva is offline
 
Join Date: Oct 2005
Location: Virginia
Posts: 204
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

It would be nice to see a tutorial on how to do SELECTS, INSERTS, UPDATES, and DELETES using the native vbulletin $db_site methods and functions. I'd like to write a custom module for vba CMPS too but I'm not sure where to start or how to go about it.

Thanks,
Jim
Reply With Quote
  #6  
Old 06-04-2006, 12:28 AM
Kirk Y's Avatar
Kirk Y Kirk Y is offline
 
Join Date: Apr 2005
Location: Tallahassee, Florida
Posts: 2,604
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Basically just use:

PHP Code:
$db->query_read("SELECT * FROM table_name WHERE clause = condition"); 
PHP Code:
$db->query("DELETE FROM table_name WHERE clause = condition"); 
PHP Code:
$db->query("UPDATE table_name SET column = 'value' WHERE clause = condition"); 
PHP Code:
$db->query("INSERT INTO table_name (column, column, column) VALUES (bla, bla, bla)"); 
That's pretty much it. Use query_first to generate arrays.
Reply With Quote
  #7  
Old 06-04-2006, 12:36 AM
noppid noppid is offline
 
Join Date: Mar 2003
Location: Florida
Posts: 1,875
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by flup
Ok, next step is to get information FROM a database, and let it display on your webpage.
__________________________________________________

We are still using the same table as in the previous artikel (tabel)
I will give you the code, and then explain it all to you.
PHP Code:
<?php

mysql_connect
("host","user","password");
mysql_select_db("databasenaam");

$select "SELECT * FROM tabel";
$query mysql_query($select)or die(mysql_error());
?>
In this part we have called ALL (*) information from table tabel, in this script it won't display anything.

The part above, the connection to the database, has been explained in the previous aricle
PHP Code:
$select "SELECT * FROM tabel";
$query mysql_query($select)or die(mysql_error()); 
Select all (*) from the database, or give me the mysql error.
Very easy IMO

Now let's go to the next step!! Show the results on a webpage.
PHP Code:
<?php

mysql_connect
("host","user","password");
mysql_select_db("databasenaam");

$select "SELECT * FROM tabel";
$query mysql_query($select)or die(mysql_error());

while(
$list mysql_fetch_object($query)){

echo 
"$list->naam
"
;
echo 
"$list->email
"
;
echo 
"$list->titel
"
;
echo 
"$list->info";

?>
Ok, now we've displayed all information of table tabel, on a page.
I assume you don't really know what is going on, so i'll explain the part to you
PHP Code:
while($list mysql_fetch_object($query)){

$list is replace-able with al things you wantactually it says
$list show everything from the table

echo "$list->naam
"
;
echo 
"$list->email
"
;
echo 
"$list->titel
"
;
echo 
"$list->info"
The echo code you will know i guess, this is just a simple code to write something on a webpage, everything you want to echo, has to be in the double quote ("). Things here displayed are:
naam, email, titel, info

And like you see, it will display all info, the layout of this is quite simple, but you can edit it all the way you want (per example add it into a table)
When you've openen an echo code, don't use double quote in the double quotes, but use singel quotes instead.



To go one more step deeper into mySQL i want to explain the WHERE function in a mySQL query:
PHP Code:
<?php

mysql_connect
("host","user","password");
mysql_select_db("databasenaam");

$select "SELECT * FROM tabel WHERE naam='flup'";
$query mysql_query($select)or die(mysql_error());

while(
$list mysql_fetch_object($query)){

echo 
"$list->naam
"
;
echo 
"$list->email
"
;
echo 
"$list->titel
"
;
echo 
"$list->info";

?
'>
Like you see i've only edited a little part of the query, and that is:
WHERE naam='flup'

Or: Selected everything in the table 'table' where 'naam' is equal to flup

You also could replace: naam='flup' to email='your@email.com' or titel='administrator'

Good luck!!

Did you really call your table "tabel"?
Reply With Quote
  #8  
Old 06-04-2006, 02:46 PM
rogersnm rogersnm is offline
 
Join Date: Apr 2006
Location: Cyberspace, UK
Posts: 729
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

lol,

did you really need to quote everything to say that?
Reply With Quote
  #9  
Old 06-04-2006, 02:54 PM
jim6763nva's Avatar
jim6763nva jim6763nva is offline
 
Join Date: Oct 2005
Location: Virginia
Posts: 204
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by acidburn0520
Basically just use:

PHP Code:
$db->query_read("SELECT * FROM table_name WHERE clause = condition"); 
PHP Code:
$db->query("DELETE FROM table_name WHERE clause = condition"); 
PHP Code:
$db->query("UPDATE table_name SET column = 'value' WHERE clause = condition"); 
PHP Code:
$db->query("INSERT INTO table_name (column, column, column) VALUES (bla, bla, bla)"); 
That's pretty much it. Use query_first to generate arrays.
Thanks! I've played around with this a little.. but now I can't seem to display the results. I'm trying to use some custom templates. Are there examples on how to do this? It would be nice if there was a way to debug variables or to see what variables were currently loaded by the system too. I've tried to study code from other mods and they use system arrays and variables that I don't have a clue what they are for or if I should be using them in my code.

Any and all help on this will be deeply appreciated, :banana:
Thanks again!

Jim
Reply With Quote
  #10  
Old 06-04-2006, 02:56 PM
rogersnm rogersnm is offline
 
Join Date: Apr 2006
Location: Cyberspace, UK
Posts: 729
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

just been messing around to...

where is the forum info stored in the db and what external code would i have to use to get them?
ie.
$forum['threadcount']
$forum['replycount']
$vbulletin->userstats['numbermembers']

Regards,
Nick.
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 11:00 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.08383 seconds
  • Memory Usage 2,342KB
  • Queries Executed 23 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (18)bbcode_php
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_article
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (9)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete