Let me explain, i'm adding a comments system to my news system(and other parts of my site)
I've looked at these tutorials and none of them seemed to do it the way i'm wanting to.
I also couldn't find anything on running two sql queries.
I have the one that gets the run news table from the database, and the other one I want to run inside will get/post from the comments table.
I was wondering two things here, can I run the comments one inside of the news? Also, is it possible to take the news id from the news tabe and transfer it into a form field and put that into the comments?
thanks
two queries
Started by pirateXcore, Aug 16 2006 04:57 AM
6 replies to this topic
#1
Posted 16 August 2006 - 04:57 AM
#2
Posted 16 August 2006 - 09:23 AM
With MySQL everything is possible
Two mysql queries is simply adding another query after hte other, where you like
(i had to think of *something*
)
Yes you can run the comments one inside of the news (whatever that means, but you can run a mysql query anywhere as long as its php)
Sure you can take the news ID and put it in a field. Not too hard, you just echo the variable extracted from MySQL somewhere into a form.
Two mysql queries is simply adding another query after hte other, where you like
mysql_query("INSERT INTO pornstars VALUES('', 'Brianna', 'Banks')");
mysql_query("DROP TABLE 'djs'");
(i had to think of *something*
Yes you can run the comments one inside of the news (whatever that means, but you can run a mysql query anywhere as long as its php)
Sure you can take the news ID and put it in a field. Not too hard, you just echo the variable extracted from MySQL somewhere into a form.
#3
Posted 16 August 2006 - 08:29 PM
I am sure that Wybe's method works, but what about simply writing UNION
ex:
just wondering...would that work as well?
ex:
mysql_query("INSERT INTO TableName (column1, column2, column3) VALUES('', 'Test', 'Testing') UNION DROP TABLE TableName2");
just wondering...would that work as well?
Edited by Tirus, 16 August 2006 - 08:31 PM.
#4
Posted 18 August 2006 - 06:14 AM
I'm sure you didn't make the union thing up (I'm not a mysql expert myself) so I guess it would
#5
Posted 18 August 2006 - 12:18 PM
I don't know what all tgs is having problems with, but from my understanding of mysql and the UNION statement, no, Tirus's code won't work.
Of course, in a different version, it might work. I could have also missed something, but to the best of my knowledge, that shouldn't work.
dev.mysql.com said:
UNION is used when you want to access a collection of identical MyISAM tables as one. This works only with MERGE tables. See Section 14.3, “The MERGE Storage Engine”.
In MySQL 4.1, you must have SELECT, UPDATE, and DELETE privileges for the tables you map to a MERGE table. (Note: Originally, all tables used had to be in the same database as the MERGE table itself. This restriction has been lifted as of MySQL 4.1.1.
In MySQL 4.1, you must have SELECT, UPDATE, and DELETE privileges for the tables you map to a MERGE table. (Note: Originally, all tables used had to be in the same database as the MERGE table itself. This restriction has been lifted as of MySQL 4.1.1.
#6
Posted 18 August 2006 - 10:49 PM
yeah...my bad, it wouldn't work. I thought it would after I had read this, thinking it could be applied to other actions.
but now that I read it again, I see it says return information...
Quote
The UNION statement is another way to return information from multiple tables with a single query. The UNION statement allows you to perform queries against several tables and return the results in a consolidated set, as in the following example.
SELECT column1, column2, column3 FROM table1 UNION SELECT column1, column2, column3 FROM table2;
This will return a result set with three columns containing data from both queries. By default, the UNION statement will omit duplicates between the tables unless the UNION ALL keyword is used. UNION is helpful when the returned columns from the different tables don’t have columns or data that can be compared and joined, or when it prevents running multiple queries and appending the results in your application code.
SELECT column1, column2, column3 FROM table1 UNION SELECT column1, column2, column3 FROM table2;
This will return a result set with three columns containing data from both queries. By default, the UNION statement will omit duplicates between the tables unless the UNION ALL keyword is used. UNION is helpful when the returned columns from the different tables don’t have columns or data that can be compared and joined, or when it prevents running multiple queries and appending the results in your application code.
but now that I read it again, I see it says return information...
Edited by Tirus, 18 August 2006 - 10:50 PM.
#7
Posted 19 August 2006 - 07:50 PM
Okay, so I got most of this working, I need to update my news to add total comments (easy), and I need to show the comments.
I'm running into problems with WHERE, when selecting from the database.
I'll show the code and then explain better:
Okay, news id is taken from my comments table, and the id is the news id taken from the news table.
Now, I have three queries running, one of them displays the current news item. The next one is for comment submission, and the final one is to display the comments.
I can't figure out how to compare the two and only display the ones that match.
Solved! I had wrong ordering of stuff.
I have all this but one.
Final question regarding this problem.
Is there a way to clear the form, cause if you refresh the page either right click or the refresh button it reposts what you put.
Thanks
I'm running into problems with WHERE, when selecting from the database.
I'll show the code and then explain better:
WHERE news_id='$id'"of course that's not the fully code!
Okay, news id is taken from my comments table, and the id is the news id taken from the news table.
Now, I have three queries running, one of them displays the current news item. The next one is for comment submission, and the final one is to display the comments.
I can't figure out how to compare the two and only display the ones that match.
Solved! I had wrong ordering of stuff.
I have all this but one.
Final question regarding this problem.
Is there a way to clear the form, cause if you refresh the page either right click or the refresh button it reposts what you put.
Thanks
Edited by tgs, 19 August 2006 - 11:20 PM.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users
