[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.0

connect 2 different databases

Asked by wakk0 in PHP and Databases

i have the code below to connect to 2 different dbs...they are on the same server with the same username and password

if this is true then i would like to connect to the 2nd db to update the record:
if ($row['pc'] >= "30000000" || $row['pc'] <="39999999") {

it currently does everything on the first db, but nothing on the second one.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
    $dbuser = 'xxx';
	$dbpass = 'xxx';
	$dbhost = 'localhost';
	$dbname = 'journaldemo';
    $dbname2 = '1timebarcode'; 
    
	$con = mysql_connect($dbhost,$dbuser,$dbpass);
	mysql_select_db($dbname, $con);
	
	 
	$con2 = mysql_connect($dbhost,$dbuser,$dbpass);
	mysql_select_db($dbname2, $con2); 
	$sql = "(SELECT 	t.transid, t.tdate, t.location, t.pc, SUM(tv.tamount) AS tamount, l.code, l.ttype, 'POINTS' AS tid
			  FROM		transactions t INNER JOIN tvalues tv ON tv.transid2 = t.transid
						INNER JOIN lookups l ON l.ttype = tv.ttype
						LEFT OUTER JOIN washes w ON w.transid = t.transid
			  WHERE		(t.tdate BETWEEN '2009-03-28' AND '2009-10-27')
						AND (t.pc BETWEEN '20000000' AND '79999999')
						AND l.code IN ('E', 'G', 'M', 'O', 'F', 'H', 'N', 'Q', 'P')
						AND l.ttype NOT IN('4002', '4408')
						AND w.transid IS NULL
			  GROUP BY 	t.transid)
			  UNION
			  (SELECT 	t.transid, t.tdate, t.location, t.pc, SUM(tv.tamount) AS tamount, l.code, l.ttype, 'WASHES' AS tid
			   FROM		transactions t INNER JOIN tvalues tv ON tv.transid2 = t.transid
						INNER JOIN lookups l ON l.ttype = tv.ttype
						LEFT OUTER JOIN washes w ON w.transid = t.transid
			   WHERE 	(t.tdate BETWEEN '2009-03-28' AND '2009-10-27')
						AND (t.pc BETWEEN '20000000' AND '79999999')
						AND l.ttype IN ('4060','10110', '10400', '11000', '11001', '11010', '11011', '11013', '18000', '18001', '11016')
						AND w.transid IS NULL
			   GROUP BY t.transid)";
	
	$result = mysql_query($sql);
	
	while($row = mysql_fetch_array($result)) { 
//need to connect to 2nd db to do update if this is true 
		if ($row['pc'] >= "30000000" || $row['pc'] <="39999999") {
			
			$sql = "UPDATE barcodes SET active = 0            
					WHERE 	human = '".$row['pc']."'"; 
			if (!mysql_query($sql, $con2)) die(mysql_error());
	
		}
		elseif ($row['tid'] == "WASHES") {
			$sql = "INSERT INTO punch (pc, punchval) 
					VALUES ('".$row['pc']."', 1) 
					ON DUPLICATE KEY UPDATE punchval = punchval + 1";
			
			if (!mysql_query($sql, $con)) die(mysql_error());
			
			$sql = "UPDATE 	punch SET punchval = CASE WHEN punchval > 10 THEN punchval - 11            
												 ELSE punchval + (-11) END	
					WHERE 	pc = '".$row['pc']."'
							AND EXISTS (SELECT 	*
										FROM 	tvalues JOIN lookups ON lookups.ttype = tvalues.ttype 
										WHERE 	tvalues.transid2 = '".$row['transid']."' AND lookups.ttype IN ('4980','4981'))";
			
			if (!mysql_query($sql, $con)) die(mysql_error());
[+][-]11/03/09 12:56 PM, ID: 25733519Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/03/09 05:30 PM, ID: 25735657Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/03/09 05:40 PM, ID: 25735690Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/04/09 05:45 AM, ID: 25739190Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/04/09 06:38 AM, ID: 25739679Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/04/09 07:14 AM, ID: 25740115Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/04/09 08:55 AM, ID: 25741322Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zone: PHP and Databases
Sign Up Now!
Solution Provided By: gr8gonzo
Participating Experts: 2
Solution Grade: A
 
[+][-]11/04/09 09:02 AM, ID: 25741418Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/09/09 09:07 AM, ID: 25777801Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/09/09 09:13 AM, ID: 25777856Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/10/09 12:37 AM, ID: 25783425Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091021-EE-VQP-81 - Hierarchy / EE_QW_3_20080625