TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 01-31-2008, 03:03 AM   #1 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default Dozens of questions which I cannot find. v_v

Heres some questions which I cannot find online, cause it's all about crap PHP Tutorials with MySQL. Now

How would I insert two querys at once? in the same variable:
PHP Code:
$query "SELECT * FROM `table`,
          INSERT INTO `table` (id,name,blah) VALUES(, 'blah', 'blah', 'blah'); 
How would I assign tables/columns/etc to a different column, say I wanted to inherit some columns like so:
PHP Code:
// I want t1's users to be t2's users
$query " SELECT t1.users,t2.users FROM t1,t2
SET `table1` AS `t1` AND `table2` AS `t2`"

How would I edit columns in the tables?
PHP Code:
 $query "TRUNCATE `table` WHERE `blah`='$blah'"
How would I move values from columns to other columns?


That's all the questions I have for now, I might ask some more later.. HALP!
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote
Old 01-31-2008, 03:06 AM   #2 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default

If someone helps me out, they get a cookie! :D
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote
Old 01-31-2008, 03:11 AM   #3 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default

We need a MySQL Guru. -_-
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote
Old 01-31-2008, 03:22 AM   #4 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

Surely you can wait 10min..... Its 24/7 staff you seem to want.

1. You cant execute more then one query though mysql_query, here some code I wrote that can enable you to do this in a different way Multiple mysql queries


2. I dont get what you are trying to do, why not select both via aliasing?
// I want t1's users to be t2's users
$query = " SELECT t1.users AS t1_users,t2.users AS t2_users FROM t1,t2;


3. Modify an existing MySQL column - Tech-Recipes.com

A quick google serach could have answered the second two
__________________

Village Idiot is offline  
Reply With Quote
Old 01-31-2008, 03:32 AM   #5 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

Quote:
Originally Posted by Orc View Post
How would I assign tables/columns/etc to a different column, say I wanted to inherit some columns like so:
PHP Code:
// I want t1's users to be t2's users
$query " SELECT t1.users,t2.users FROM t1,t2
SET `table1` AS `t1` AND `table2` AS `t2`"

From your code, it looks like you might be wanting to use something like the following:
SQL Code:
SELECT
    t1.users,
    t2.users
FROM
    table1 AS t1,
    table2 AS t2
;

Please be patient when asking questions; even though some of us are on the forums very often, we're not here to drop everything and respond immediately to new posts. Even if that were the case, it does indeed take a few minutes to draft a post.
Salathe is offline  
Reply With Quote
The Following User Says Thank You to Salathe For This Useful Post:
Orc (01-31-2008)
Old 01-31-2008, 04:09 AM   #6 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default

Quote:
Originally Posted by Salathe View Post
From your code, it looks like you might be wanting to use something like the following:
SQL Code:
SELECT
    t1.users,
    t2.users
FROM
    table1 AS t1,
    table2 AS t2
;

Please be patient when asking questions; even though some of us are on the forums very often, we're not here to drop everything and respond immediately to new posts. Even if that were the case, it does indeed take a few minutes to draft a post.
Okay, but thanks for answering one of my questions. :D
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote
Old 01-31-2008, 04:59 AM   #7 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default

I think I figured out that Inner join can be used to combine data from other tables to make one table :D
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote
Old 01-31-2008, 10:58 AM   #8 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default

I'm wondering if I have to use queries for listing rows in a table, and updating, deleting, or inserting into tables. -_- I said I'm a newbie at MySQL. :/
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote
Old 01-31-2008, 01:10 PM   #9 (permalink)
The Contributor
 
buggabill's Avatar
 
Join Date: Jan 2008
Location: Maine, USA
Posts: 92
Thanks: 2
buggabill is on a distinguished road
Default

I believe...if I am wrong, someone correct me, please..to insert data from a SELECT query into another table do something like the following:

SQL Code:
INSERT INTO
    generals (name, rank, serialnum)
SELECT
    name, rank, serialnum
FROM
    allsoldiers
WHERE
    rank="General"
The field names do not have to match, but the data type should.

By editing columns in a table, to what are you referring? Do you wish to change the data type or just the data in a specific column/field?
__________________
-- Bill
"Why is it drug addicts and computer aficionados are both called users?" -Clifford Stoll
buggabill is offline  
Reply With Quote
Old 01-31-2008, 01:12 PM   #10 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default

Quote:
Originally Posted by buggabill View Post
I believe...if I am wrong, someone correct me, please..to insert data from a SELECT query into another table do something like the following:

SQL Code:
INSERT INTO
    generals (name, rank, serialnum)
SELECT
    name, rank, serialnum
FROM
    allsoldiers
WHERE
    rank="General"
The field names do not have to match, but the data type should.

By editing columns in a table, to what are you referring? Do you wish to change the data type or just the data in a specific column/field?
I was trying to list some news entries, then show a checkbox to delete it or edit it. :/
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote
Old 01-31-2008, 02:42 PM   #11 (permalink)
The Contributor
 
buggabill's Avatar
 
Join Date: Jan 2008
Location: Maine, USA
Posts: 92
Thanks: 2
buggabill is on a distinguished road
Default

Sorry for all the questions, but I have one more. Were you planning on adding or removing a column for each news story? Am I misunderstanding you? Are you actually trying to add or delete rows?

TRUNCATE will clean the table out and leave the structure intact. I don't think that is what you want to do...

To delete a row, here is a small example(assuming you had the id of the story):

SQL Code:
DELETE FROM
    newsstories
WHERE
    id=idofstory

Changing data in a column requires you to do an UPDATE query.

example:
SQL Code:
UPDATE
    stories
SET
    body=bodyofstory
WHERE
    id=idofstory
__________________
-- Bill
"Why is it drug addicts and computer aficionados are both called users?" -Clifford Stoll
buggabill is offline  
Reply With Quote
Old 01-31-2008, 07:50 PM   #12 (permalink)
The Acquainted
 
wGEric's Avatar
 
Join Date: Nov 2007
Posts: 166
Thanks: 0
wGEric is on a distinguished road
Default

Quote:
Originally Posted by Orc View Post
I think I figured out that Inner join can be used to combine data from other tables to make one table :D
Yes, also LEFT JOIN and RIGHT JOIN. You can also do SELECT queries within other queries (as pointed out by buggabill). There's also UNIONs to do two queries at once.
Code:
SELECT name FROM cia WHERE population > (SELECT population FROM cia WHERE name='United States');
SELECT * FROM t1 UNION SELECT * FROM t2 UNION SELECT * FROM t3;
__________________
Eric
wGEric is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 09:18 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design