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
  #12  
Old 06-11-2006, 11:09 PM
Kirk Y's Avatar
Kirk Y Kirk Y is offline
 
Join Date: Apr 2005
Location: Tallahassee, Florida
Posts: 2,604
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #13  
Old 09-18-2006, 05:07 PM
vietkieu_cz vietkieu_cz is offline
 
Join Date: Dec 2005
Posts: 120
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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/>";
}
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 08:03 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04297 seconds
  • Memory Usage 2,235KB
  • Queries Executed 19 (?)
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
  • (8)bbcode_php
  • (1)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
  • (3)post_thanks_box
  • (3)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (3)post_thanks_postbit_info
  • (2)postbit
  • (3)postbit_onlinestatus
  • (3)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_postinfo_query
  • fetch_postinfo
  • 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