PDA

View Full Version : SELECT FROM database


flup
02 May 2003, 11:00
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.


Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------


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


Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------


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.


Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------


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


Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------


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:


Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------


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
02 May 2003, 11:01
Click here for the tutorial: Instert into database (http://www.vbulletin.org/forum/showthread.php?s=&threadid=52456)

Dean C
02 May 2003, 19:51
Wow you use fetch_object - i never use classes,methods or objects apart from the built in $db_site object in vbulletin :)

- miSt

flup
02 May 2003, 20:46
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
04 Jun 2006, 00:23
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
04 Jun 2006, 02:28
Basically just use:



Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------





Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------





Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------





Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------



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

noppid
04 Jun 2006, 02:36
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.


Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------


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


Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------


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.


Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------


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


Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------


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:


Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------


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
04 Jun 2006, 16:46
lol,

did you really need to quote everything to say that?

jim6763nva
04 Jun 2006, 16:54
Basically just use:



Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------





Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------





Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------





Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------



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
04 Jun 2006, 16:56
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
12 Jun 2006, 01:09
Say we use this query for an example:


Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------



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


Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------



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

vietkieu_cz
18 Sep 2006, 19:07
Basically just use:



Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------



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/>";
}