Hi:
So I need to call 2 tables from 2 different databases...and I just cant get it to work.. i always get this error:
Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in /home/pdem/pdem.mattwatson.info/Display.php on line 86
on the line that has:
$num=mysql_numrows($result);
...My question I guess is whether or not I am doing my query and stuff correctly... Here is some code.
I have read the documentation, and lots of examples...i find a lot of people dont use:
@mysql_select_db("pdem?database1",$projectDatabase) or die("Unable to select database");
...but it seems important to me..maybe you just do something else instead. i dont know 😛
Anyways here is the first part of my code (im sure everything needed is here)
Thanks,
Paul
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<meta name="author" content="Toadums" />
<title>REI Consultants Timesheet Query</title>
</head>
<body bgcolor="#DDE2CC"> <!-- set colour to r:221 g:226 b:204 (rgb codes)-->
<img src="logo.jpg" /> <!-- link to the logo in same directory-->
<br />
<br />
<br />
<?php
#save log in information for server
$username="**";
$password="**";
$database="**";
$timesheetDatabase = mysql_connect("mysql.mattwatson.info",$username,$password);
if(!$timesheetDatabase){
die ("Unable to connect to server");
}
@mysql_select_db($database,$timesheetDatabase) or die("Unable to select database"); //<< DO I NEED THIS LINE??
$projectDatabase = mysql_connect("mysql.mattwatson.info",$username,$password);
if(!$projectDatabase){
die ("Unable to connect to server");
}
@mysql_select_db("pdem?database1",$projectDatabase) or die("Unable to select database");//<< DO I NEED THIS LINE??
?>
<form name ="form2" action="<?php echo($_SERVER['PHP_SELF']); ?>" method="post">
<table border="1" cellspacing="10" cellpadding="2">
<tr>
<th><font face="Arial, Helvetica, sans-serif">Date</font></th>
<th><font face="Arial, Helvetica, sans-serif">Name</font></th>
<th><font face="Arial, Helvetica, sans-serif">Hours</font></th>
<th><font face="Arial, Helvetica, sans-serif">Phase</font></th>
<th><font face="Arial, Helvetica, sans-serif">Project ID</font></th>
<th><font face="Arial, Helvetica, sans-serif">Description</font></th>
<th><font face="Arial, Helvetica, sans-serif">Project Name</font></th>
<th><font face="Arial, Helvetica, sans-serif">Client</font></th>
<th><font face="Arial, Helvetica, sans-serif">Invoiced</font></th>
<th><font face="Arial, Helvetica, sans-serif">Type</font></th>
</tr>
<?
$num = 0;
$startRow = 0;
$endRow = 30;
if(isset($_POST['submit']) && $_POST['Name']!=""){
$queryName = $_POST['Name'];
$query="SELECT * FROM tblTimesheet WHERE Name= '$queryName' ORDER BY `tblTimesheet`.`Date` ASC LIMIT $startRow , $endRow ";
$result=mysql_query($query,$timesheetDatabase);
}else{
$query="SELECT * FROM tblTimesheet ORDER BY `tblTimesheet`.`Date` ASC LIMIT $startRow , $endRow ";
$result=mysql_query($query,$timesheetDatabase);
}
$num=mysql_numrows($result); //<< WHERE I GET THAT ERROR
$i=0;
while ($i < $num) {
$Date=mysql_result($result,$i,"Date");
$Hours=mysql_result($result,$i,"Hours");
$Name=mysql_result($result,$i,"Name");
$Phase=mysql_result($result,$i,"Phase");
$Invoiced=mysql_result($result,$i,"Invoiced");
$ProjectID=mysql_result($result,$i,"ProjectID");
$Description=mysql_result($result,$i,"Description");
$Type=mysql_result($result,$i,"Type");
$nameQuery = "SELECT ProjectName FROM tblProjects WHERE ProjectID = '$ProjectID'";
$clientQuery = "SELECT Client FROM tblProjects WHERE ProjectID = '$ProjectID'";
$Pname = mysql_query($nameQuery,$projectDatabase);
$NameRow = mysql_fetch_row($Pname);
$Pclient = mysql_query($clientQuery,$projectDatabase);
$ClientRow = mysql_fetch_row($Pclient);
Hopefully that makes sense...If I am doing anything wrong, let me know 😛