vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 3 Articles (https://vborg.vbsupport.ru/forumdisplay.php?f=187)
-   -   SELECT FROM database (https://vborg.vbsupport.ru/showthread.php?t=52458)

flup 05-01-2003 10:00 PM

SELECT FROM database
 
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!!

flup 05-02-2003 09:01 AM

<a href="https://vborg.vbsupport.ru/showthread.php?s=&threadid=52456" target="_blank">Click here for the tutorial: Instert into database</a>

Dean C 05-02-2003 05:51 PM

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

- miSt

flup 05-02-2003 06:46 PM

Hmmmz, getch_object works good very good IMO.
But this tutorials is more for the noobs wich are going to test this outside vB ;)

jim6763nva 06-03-2006 10:23 PM

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. :confused:

Thanks,
Jim

Kirk Y 06-04-2006 12:28 AM

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.

noppid 06-04-2006 12:36 AM

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"?

rogersnm 06-04-2006 02:46 PM

lol,

did you really need to quote everything to say that?

jim6763nva 06-04-2006 02:54 PM

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

rogersnm 06-04-2006 02:56 PM

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.

Kirk Y 06-11-2006 11:09 PM

Say we use this query for an example:
PHP Code:

$sql $db->query_first(SELECT FROM table_name); 

If the DB column you wanted to get data from was called "example", you'd use this to call the data:
PHP Code:

$sql['example'

The outputted data is whatever was stored in the column you called.

vietkieu_cz 09-18-2006 05:07 PM

Quote:

Originally Posted by acidburn0520
Basically just use:

PHP Code:

$db->query_read("SELECT * FROM table_name WHERE clause = condition"); 

That's pretty much it. Use query_first to generate arrays.

And how do I show the queries on forum (thread)???
I do not know how to use it, please help me. Thank you very much :)

(Normal PHP is: ex:

$result = mysql_query($query);

while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo {$row['threadid']}".
"{$row['title']}".
"<br/>";
}


All times are GMT. The time now is 03:52 PM.

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.01396 seconds
  • Memory Usage 1,803KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (21)bbcode_php_printable
  • (3)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (12)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete