1

Possible Duplicate:
mysql_fetch_array() expects parameter 1 to be resource, boolean given in select

Okay, so I have my page "List Customers" which then links to "List Jobs" adding on ?custID= into the URL, then on List jobs I have used $_GET["custID"] so my query uses the custID from the URL. that works fine, lists out my jobs for said customer using their ID.

My problem comes up now, I need the links on this page to give my third page the techID as well. But the techID is in jobDetails, so my query cannot give them the techID as it is querying my job section.

This is my "ListJobs.php" page, which upon choosing a customer in the page before it, loads this page with the url ListJobs.php?custID=001 (001 being an example, it will give the number depending on your choice of customer).

<?php 
// Get data from the database depending on the value of the id in the URL
mysql_select_db($database_con_sim5, $con_sim5);
$query_Recordset1 = "SELECT * FROM job WHERE custID=" . $_GET["custID"] ;
$Rs1 = mysql_query($query_Recordset1);
// Loop the recordset $rs
while($row = mysql_fetch_array($Rs1)) {
  $strName1 = $row['jobID'] . " " . $row['jobDesc'] . " " . $row['computerName'];
  $strLink = "<a href = 'jobDetails.php?jobID=".$row['jobID']."'>".$strName1."</a>";
  // Write the data of the person
  echo "<li>" . $strLink . " </li>";
}
// Close the database connection
mysql_close();
?>

Then on pressing one of the links, link to jobDetails.php?jobID= with the job number. I am able to show all the details in Job Detail with this, but I also need my Tech Name to appear, Tech Name is not in Job Details, but Tech ID is. Here is my Job Details page coding :

<?php 
// Get data from the database depending on the value of the id in the URL
mysql_select_db($database_con_sim5, $con_sim5);
$query_Recordset1 = "SELECT * FROM jobDetail WHERE jobID=" . $_GET["jobID"] ;
$query_Recordset2 = "SELECT technician.techName FROM technician 
  WHERE techID=" . $query_Recordset1["techID"] ;
$Rs1 = mysql_query($query_Recordset1);
$Rs2 = mysql_query($query_Recordset2);
while($row1 = mysql_fetch_array($Rs1)) {
  while($row2 = mysql_fetch_array($Rs2)) {
    echo "<dt><strong>Job Note ID:</strong></dt><dd>".$row1["jobNoteID"]."</dd>";
    echo "<dt><strong>Job Notes:</strong></dt><dd>".$row1["jobNotes"]."</dd>";
    echo "<dt><strong>Date Completed:</strong></dt><dd>".$row1["dateCompleted"]."</dd>";
    echo "<dt><strong>Time Spent:</strong></dt><dd>".$row1["timeSpent"]."</dd>";
    echo "<dt><strong>Job ID:</strong></dt><dd>".$row1["jobID"]."</dd>";
    echo "<dt><strong>Technician ID:</strong></dt><dd>".$row1["techID"]."</dd>";
    echo "<dt><strong>Technician Name:</strong></dt><dd>".$row2["techName"]."</dd>";
  }
}
// Close the database connection
mysql_close();
?>

The error I am getting is:

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in D:\xampp\htdocs\Sim5Server\Pages\jobDetails.php on line 129

That line is:

while($row2 = mysql_fetch_array($Rs2)) { 

I hope I am making any sense AT ALL.

To sum up, I need my final page to show data from mysql technician using the Primary/index key techID. Some way to add techID onto either listJobs' links to job details or in job details' second Recordset.

EDIT: I should probably state this will never be used on the net, I only need it to work for an assignment. in future, thanks to a comment, I will no longer be using mysql_* I am jsut using them as my entire workbook tells us to use it.

Community
  • 1
  • 1
DBeslan
  • 155
  • 1
  • 1
  • 6
  • [**Please, don't use `mysql_*` functions in new code**](http://bit.ly/phpmsql). They are no longer maintained and the [deprecation process](http://j.mp/Rj2iVR) has begun on it. See the [**red box**](http://j.mp/Te9zIL)? Learn about [*prepared statements*](http://j.mp/T9hLWi) instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli) - [this article](http://j.mp/QEx8IB) will help you decide which. If you choose PDO, [here is a good tutorial](http://j.mp/PoWehJ). – NullPoiиteя Nov 04 '12 at 07:29
  • Thank you for the information on mysql_* functions. I will definitely keep this information on hand later down the track. I will, however, still be using mysql_* in this as it is only an assignment at TAFE. – DBeslan Nov 04 '12 at 07:41

1 Answers1

0

Try making this change in your jobDetails.php page

$query_Recordset1 = "SELECT * FROM jobDetail WHERE jobID=". (int) $_GET["jobID"];
$Rs1 = mysql_query($query_Recordset1) or die(mysql_error());
while($row1 = mysql_fetch_array($Rs1)) {
  $query_Recordset2 = "SELECT technician.techName FROM technician 
  WHERE techID=" . $row1["techID"] ;
  $Rs2 = mysql_query($query_Recordset2) or die(mysql_error());
  while($row2 = mysql_fetch_array($Rs2)) {

For the second query you were using the result resource from executing the first query as techID. Also you will have to query for techName from inside the while loop fetching job details, since only then will you have the techID.

air4x
  • 5,618
  • 1
  • 23
  • 36
  • You sir, are a gentleman and a scholar. Your fix works and the explanation tells me exactly what I have done wrong.. – DBeslan Nov 04 '12 at 08:12
  • What exactly is the load on the database of running the inner query once for each outer row? I always do this kind of thing as either a single query with a join, or just two queries that are logically "merge joined" in my application code. – ErikE Jan 01 '13 at 20:19