SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict
    Join Date
    Jan 2007
    Posts
    296
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Access & PHP not recognising my error message

    I am having some trouble changing my script form running with mysql to running with access. Everything is working except when i went to run my error message if no records have been found. I have been looking for an answer and believe it is something to do with the result returning -1 but have no idea how to fix the issue.

    Here is the code and thanks for any help

    Code:
    <?php
    
    require_once('databaseconnection.php'); 
    
    $keywordentered = $_GET['keyword']; 
     
    switch($_GET['type']) {
      case 'ordernumber':
       $result = odbc_exec($odbc, "SELECT * FROM orderpartnumbertable WHERE Order_No LIKE '".$keywordentered."%'"); 
        break;
      case 'partnumber':
        $result = odbc_exec($odbc, "SELECT * FROM orderpartnumbertable WHERE Part_No LIKE '".$keywordentered."%'");
        break;
      case 'accountname':
        $result = odbc_exec($odbc, "SELECT * FROM orderpartnumbertable WHERE Account_Name LIKE '".$keywordentered."%'");
        break;
    }
    
    if(odbc_num_rows($result) == 0){
    echo("Sorry your query has returned no results!");
    exit;
    }
    
    
    echo '<table border=1>';
    echo '<tr><th>Order Number</th><th>Part Number</th><th>Account Name</th><th>FNP Site</th><th>More Info</th></tr>';
    while (($row = odbc_fetch_array($result)) !== false) {
      echo '<tr>';
      echo '<td>' . $row['Order_No'] . '</td>';
      echo '<td>' . $row['Part_No'] . '</td>';
      echo '<td>' . $row['Account_Name'] . '</td>';
       echo '<td>' . $row['FNP_Site'] . '</td>';
       echo '<td>' . '<a href="ordersearchdetails.php?fnp_site=' . rawurlencode($row['FNP_Site']) . '">More Info</a>' . '</td>'; 
      echo '</tr>';
    }
    echo '</table>'; 
    ?>
    Here is my contents of my connection file

    Code:
    $odbc = odbc_connect ('orderpartsearchconnection', 'root', '') or die ('could not connect to ODBC Database!');

    Thank You

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,401
    Mentioned
    147 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by Struggling View Post
    I have been looking for an answer and believe it is something to do with the result returning -1 but have no idea how to fix the issue.
    If the result returns -1 when no records are found then try:

    PHP Code:
    if($result == -1){
    echo(
    "Sorry your query has returned no results!");
    exit;


  3. #3
    SitePoint Addict
    Join Date
    Jan 2007
    Posts
    296
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That doesn't work either. i did a quick exit of what is stored in the variable result and it echos to the screen

    Resource id #4

    I am not sure what this means??/

  4. #4
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,401
    Mentioned
    147 Post(s)
    Tagged
    4 Thread(s)
    It's the ODBC result identifier.
    What does odbc_num_rows($result) echo?

  5. #5
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,401
    Mentioned
    147 Post(s)
    Tagged
    4 Thread(s)

  6. #6
    SitePoint Addict
    Join Date
    Jan 2007
    Posts
    296
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That is what brings out the results resource id4. Seems a hard problem to sort been seraching the net and no one seems to be able to solve it as far as i can see for now.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •