views:

40

answers:

1

As of now I have no errors in my program, but I need the primary key for one of the tables for a relation for the following Query. but instead of getting a actual number the value the query is sending back is

Resource id #4

Here is my Code: (The query that I'm having issues with is the $sql_branch, is there a function to change the result from "Resource id #4" to just 4?

$sql_branch = "SELECT BranchNum
              FROM Branch
              WHERE BranchName = '$_POST[branch]'";

$sql_result = "SELECT AuthorFirst, AuthorLast, OnHand, Title
              FROM Inventory i, Wrote w, Author a, Book b
              WHERE i.BookCode = b.BookCode AND i.BookCode = w.BookCode
              AND a.AuthorNum = w.AuthorNum AND i.BranchNum = 1";


$connect = mysql_connect('students', 'xxxx', 'xxxx') or exit(mysql_error());

mysql_select_db('henrybooks', $connect);

if(mysql_query($sql_branch, $connect)) {
  $branch = mysql_query($sql_branch, $connect);
}
else {
  echo mysql_error();
}

if(mysql_query($sql_result, $connect)) {
  $result = mysql_query($sql_result, $connect);
}
else {
  echo mysql_error();
}
echo $branch."<br>";
echo $sql_branch."<br>";
echo "<table>
        <tr>
           <td>Author</td>
           <td>Title</td>
           <td>Number Available</td>
        </tr>";
while( $row = mysql_fetch_array($result)) {
  echo "<tr>";
  echo "<td>".$row['AuthorFirst'].$row['AuthorLast']."</td>";
  echo "<td>".$row['Title']."</td>";
  echo "<td>".$row['OnHand']."</td>";
  echo "</tr>";
}

echo "</table>";
?>

Thanks!

+4  A: 

You are not pulling results from the mysql_query. Try this:

if($branch_result = mysql_query($sql_branch, $connect)) {
  $branch = mysql_fetch_array($branch_result);
}
mwotton
thankyou! I'm a fool for not seeing that!
rajh2504
No prob. I often need a fresh set of eyes over my code to see the glaringly obvious that I am too close to see.
mwotton
@mwotton as for in the query I'm guessing I'd put the result in as <code>'$branch[BranchNum]'</code>
rajh2504
@rajh2504: That's right. Since you're fetching an associative array with mysql_fetch_array() the field names become the array keys.
mwotton