1,105,644 Community Members

comparing value from 2 diff databases

Member Avatar
gopi17
Junior Poster
104 posts since Sep 2008
Reputation Points: 8 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
0
 

heyy guys....i manage to connect to diff database in a single form...but how do i compare the value...
for eg. now i would to compare invoice_no for the both of them

$host="localhost"; 		// Host name
    $username=""; 			// Mysql username
    $password=""; 			// Mysql password
    $db_name="test"; 		// Database name
    $tbl_name="test3"; 		// Table name
    $db_name1="test1"; 		// Database name
    $tbl_name1="test2";		// Table name
	
    // Connect to server and select database.
    $dbh1=mysql_connect("$host", "$username", "$password")or die("cannot connect");
    $dbh2=mysql_connect("$host", "$username", "$password",true)or die("cannot connect");
	
	mysql_select_db("$db_name", $dbh1)or die(mysql_error());
	mysql_select_db("$db_name1", $dbh2)or die(mysql_error());
     
    $invoiceno=$_POST['invoiceno'];						
    $_SESSION['invoice_no']=$invoiceno;						

	
    $sql="SELECT * FROM $tbl_name WHERE invoice_no = '$invoiceno'";			
       $result=mysql_query($sql,$dbh1);							
    $row=mysql_fetch_array($result) or die(mysql_error());					
    echo "$row";  
if($row>0)														
	{
		echo "Invoice No. found";
	}
    else																	//invoice no. not found, prompts user again
	{
		echo "ngek ngek";
	}

could someone guide me please

Member Avatar
veedeoo
Veteran Poster
1,017 posts since Oct 2011
Reputation Points: 316 [?]
Q&As Helped to Solve: 167 [?]
Skill Endorsements: 17 [?]
 
0
 

Hi,

These codes

$sql="SELECT * FROM $tbl_name WHERE invoice_no = '$invoiceno'";
$result=mysql_query($sql,$dbh1);
$row=mysql_fetch_array($result) or die(mysql_error());
echo "$row";

Shouldn't be a lot easier to find if rows is greater than zero?

Something like this

$sql="SELECT * FROM $tbl_name WHERE invoice_no = '$invoiceno'";
$result=mysql_query($sql,$dbh1);
$row= mysql_num_rows($result) or die(mysql_error());
echo "$row"; 

## check on the result
if($row>0){

## do your thing here

}

Do the same on the second database..

Member Avatar
gopi17
Junior Poster
104 posts since Sep 2008
Reputation Points: 8 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
0
 

thank you for the reply....hmm, i understand....one more question...lets say both the database has invoice number...how to i compare them....using a single sql line...is it possible?

Member Avatar
gopi17
Junior Poster
104 posts since Sep 2008
Reputation Points: 8 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
0
 

owh...its okay..i manage to do it...:D

$invoiceno=$_POST['invoiceno'];							// invoice no. sent from form
    $_SESSION['invoice_no']=$invoiceno;						
 $sql="SELECT * FROM $tbl_name WHERE invoice_no ='$invoiceno'";			
    $result = mysql_query($sql,$dbh1);
	$row = mysql_fetch_array($result);
	$sql1="SELECT * FROM $tbl_name1 WHERE invoice_no = '$invoiceno'";
	$result1 = mysql_query($sql1,$dbh2);										
    $row1 = mysql_fetch_array($result1);
	
	$invoice_no=$row['invoice_no'];
	$document_no=$row['document_no'];
	$container_no=$row['container_no'];
	$invoice_no1=$row1['invoice_no'];
	$document_no1=$row1['document_no'];
	$container_no1=$row1['container_no'];

thank you again

Question Answered as of 2 Years Ago by veedeoo
Member Avatar
veedeoo
Veteran Poster
1,017 posts since Oct 2011
Reputation Points: 316 [?]
Q&As Helped to Solve: 167 [?]
Skill Endorsements: 17 [?]
 
0
 

cool.. :)

You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article