Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 02-01-2005, 08:36 PM
Joe Pimms Joe Pimms is offline
 
Join Date: Jan 2005
Location: Canada
Posts: 95
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default can some one tell me a little about LEFT JOIN ?

can any one tell me a little about these in a data base query vb uses please ?

INNER JOIN ?

LEFT JOIN ?

TABLE_PREFIX ?

and if there are any others please do tell
Reply With Quote
  #2  
Old 02-01-2005, 09:30 PM
sabret00the's Avatar
sabret00the sabret00the is offline
 
Join Date: Jan 2003
Location: London
Posts: 5,268
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

table prefix was just done in another thread

INNER JOIN's and LEFT JOIN's are a method used to combine two or more tables.
Reply With Quote
  #3  
Old 02-01-2005, 09:40 PM
Joe Pimms Joe Pimms is offline
 
Join Date: Jan 2005
Location: Canada
Posts: 95
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

i have made a database table but i would like a little help with a query
this is my table can u use this:

PHP Code:
CREATE TABLE `serial` (
  `
serialidint(10NOT NULL auto_increment,
  `
serialnamevarchar(255NOT NULL default '0',
  `
useridint(10unsigned NOT NULL default '0',
  `
datelineint(10unsigned NOT NULL default '0',
  `
postidint(10unsigned NOT NULL default '0',
  `
serialnumbertext NOT NULL,
  
PRIMARY KEY  (`serialid`),
  
KEY `userid` (`userid`),
  
KEY `postid` (`postid`)
TYPE=MyISAM
here is what i have here as i did it my self would this work ?

PHP Code:
$query "SELECT serial.serialid, serial.postid, serial.dateline, serial.userid, IF(user.userid<>0, user.username) AS username
        FROM " 
TABLE_PREFIX "serial AS serial
        LEFT JOIN " 
TABLE_PREFIX "user AS user ON (serial.userid=user.userid)
        order by serial.dateline desc limit 
$limitlower$perpage"
Reply With Quote
  #4  
Old 02-01-2005, 11:05 PM
miz miz is offline
 
Join Date: Mar 2003
Posts: 416
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

you know , best way to know if something working
is to test it
so test your code
and if its not working
post here the error so we can help you out....
Reply With Quote
  #5  
Old 02-01-2005, 11:14 PM
cinq's Avatar
cinq cinq is offline
 
Join Date: Oct 2002
Posts: 1,398
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Joe Pimms
PHP Code:
IF(user.userid<>0user.username) AS username 
What does this portion mean ?
The part in the IF case.
Reply With Quote
  #6  
Old 02-01-2005, 11:36 PM
Paul M's Avatar
Paul M Paul M is offline
 
Join Date: Sep 2004
Location: Nottingham, UK
Posts: 23,748
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Wow, that's a rare use of IF.

Basically it means that the SELECT will only pull the username from the db if the userid is not equal to zero, otherwise it will return NULL (the missing third parameter, which defaults to NULL).

Can you say 'NULL AS username' in a SELECT statement and it assign the value of NULL to username ? - I'm not sure - it might generate an error. I'm certainly not sure why you would want to do this, it seems kinda pointless.
Reply With Quote
  #7  
Old 02-02-2005, 03:21 AM
Joe Pimms Joe Pimms is offline
 
Join Date: Jan 2005
Location: Canada
Posts: 95
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

what im trying to do is be able to view all info in the database table called serial and the other items hold different things...

1.. the serialid
2.. the serialname this is the part that will hold the name of the text or post name
3.. the userid this is the part that holds the user name that makes the posts
4.. the dateline this is the date that the post was made
5.. the serialnumber this is the full post that was made all the text in the post and all

what im wanting to do is also make a add forum and a submit with it as well for a new forum and also have an other php script that will display the post contents as well but the only problem im having is the database not to sure on how to make all the right commands and all so please help me with any ideas or any thing else

thanks so much :smoke:
Reply With Quote
  #8  
Old 02-02-2005, 04:30 AM
miz miz is offline
 
Join Date: Mar 2003
Posts: 416
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

PHP Code:

// lets say we got serialid
$serialid "56";

$bla $DB_site->query_first("SELECT
serial.* AS serial, user.userid,user.username AS U-name
FROM " 
TABLE_PREFIX "serial
LEFT JOIN " 
TABLE_PREFIX "user ON(user.userid = serial.userid)
WHERE serial.serialid='
$serialid'
"
);

//spit out the values so we can see all

print_r($bla
lets say we want to show last 10 serials

PHP Code:



$bla 
$DB_site->quer("SELECT
serial.* AS serial, user.userid,user.username AS U-name
FROM " 
TABLE_PREFIX "serial
LEFT JOIN " 
TABLE_PREFIX "user ON(user.userid = serial.userid)
WHERE serial.serialid='
$serialid'
GROUP BY serial.serialid
ORDER BY serial.serialid DESC LIMIT 10
"
);

while (
$bla2 $DB_site->fetch_array($bla))
{

// ill show how to spit only serial id - you will do the rest alone

$showserialidbit .= "<tr><td>$bla2[serialid];</td></tr>";
}

//spit out the values so we can see all

echo "<table>
<tr><td> serialid </td></tr>
$showserialidbit
</table>"

Reply With Quote
  #9  
Old 02-06-2005, 06:49 PM
Joe Pimms Joe Pimms is offline
 
Join Date: Jan 2005
Location: Canada
Posts: 95
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

now if i was to make a forum to add items how would i do that do i use for the database INSTERT or UPDATE ?

also what tables would i need to use in order to enter the info in? cause im adding in a name of the item and then adding the user who posted the item and also the items contents as well ?

can u be able to give me an idea on how to do this plz ?

thanks
Reply With Quote
  #10  
Old 02-06-2005, 07:20 PM
Xenon's Avatar
Xenon Xenon is offline
 
Join Date: Oct 2001
Location: Bavaria
Posts: 12,878
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

you cannot use JOIN in insert/update queries, just in select queries
Reply With Quote
Reply


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 09:44 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.07035 seconds
  • Memory Usage 2,277KB
  • Queries Executed 11 (?)
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
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (5)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)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
  • (10)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