vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   can some one tell me a little about LEFT JOIN ? (https://vborg.vbsupport.ru/showthread.php?t=75566)

Joe Pimms 02-01-2005 08:36 PM

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

sabret00the 02-01-2005 09:30 PM

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.

Joe Pimms 02-01-2005 09:40 PM

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"


miz 02-01-2005 11:05 PM

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

cinq 02-01-2005 11:14 PM

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

Paul M 02-01-2005 11:36 PM

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.

Joe Pimms 02-02-2005 03:21 AM

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:

miz 02-02-2005 04:30 AM

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



Joe Pimms 02-06-2005 06:49 PM

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

Xenon 02-06-2005 07:20 PM

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


All times are GMT. The time now is 05:52 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.02180 seconds
  • Memory Usage 1,754KB
  • 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
  • (5)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)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
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete