3

The warning I'm getting is:

Warning: mysqli_result::fetch_array() expects parameter 1 to be long, object given in...line 103.

I've commented next to the line 103 while ($row = $result->fetch_array($result)) {

Question 2: Can I store any of this in an include file or should I?

Question 3: For the $query can I store any of these Buyer, Seller, etc. in an array somewhere? How?

/* FETCH CONTACT INFORMATION */

$query = ("SELECT * FROM contacts WHERE contacttype IN ('Buyer','Seller','Buyer / Seller','Investor') AND leadstatus = 'New' ORDER BY date DESC");

$ID = $row ['ID'];     
$firstname = $row ['firstname'];     
$lastname = $row['lastname'];
$ID = $row['ID'];   
$partner  = $row['spousefirst'];   
$phonecell = $row['phonecell'];
$email = $row['email'];
$date = $row['date'];
$contacttype = $row['contacttype'];
$agentassigned = $row['agentassigned'];
$leadstatus = $row['leadstatus'];

$result = $mysqli->query($query) or die ("Error: ".mysqli_error($mysqli));

echo'
  <table class="results" id="results">
    <thead> 
      <tr> 
        <th width="10"><input type="checkbox" name="checkAll" id="checkAll" class="checkall" value="check all"></th>
        <th>NAME</td> 
        <th>PARTNER</td> 
        <th>PHONE</td> 
        <th>EMAIL</td> 
        <th>DATE</td> 
        <th>TYPE</td> 
        <th>AGENT</td> 
        <th>STATUS</td> 
        <th>NOTES</td> 
        <th>TASKS</td> 
        <th>&nbsp;</td>
       </tr> 
     </thead>';

while ($row = $result->fetch_array($result)) {  // THIS IS LINE 103

      echo'
     <tbody>       
       <tr>
        <td width="10"><input type="checkbox" name="" id="" value="'.$ID.'"></td>
        <td><a href="/backend/leads/view/?ID='.$ID.'"><strong>'.$firstname.' '.$lastname.'</strong></a></td>
        <td><a href="/backend/leads/view/?ID='. $ID.'">'.$partner.'</a></td>
        <td>'.$phonecell.'</td>
        <td><a href="mailto:'. $email.'">'.$email.'</a></td>
        <td>'.date("M jS, g:i A", strtotime($date)).'</td>
        <td>'.$contacttype.'</td>
        <td>'.$agentassigned.'</td>
        <td>'.$leadstatus.'</td>
        <td><a href="/backend/contacts/notes.php?ID='.$ID.'">View</a> +</td>
        <td><a href="/backend/contacts/todo.php?ID='.$ID.'">View</a> +</td>
        <td><a href="/backend/contacts/deletesuccess.php?ID='.$ID.'">D</a></td>
       </tr>
     </tbody>       
    </table>';

}
?>
Josh
  • 133
  • 1
  • 4
  • 11
  • 1
    For questions 2 and 3, please create new questions. See http://meta.stackexchange.com/q/39223/164291 for more info. –  Jun 30 '12 at 00:01
  • I edited my answer to address your other two questions... – Michael Berkowski Jun 30 '12 at 00:15
  • possible duplicate of [mysql_fetch_array() expects parameter 1 to be resource, boolean given in select](http://stackoverflow.com/questions/2973202/mysql-fetch-array-expects-parameter-1-to-be-resource-boolean-given-in-select) – Somnath Muluk Jul 19 '12 at 13:16

1 Answers1

4

In object-oriented mode, the parameter to fetch_array() specifies the fetch type (MYSQLI_ASSOC, MYSQLI_NUM), and doesn't take a result resource.

while ($row = $result->fetch_array(MYSQLI_ASSOC)) {

In your loop then, we assume you want to be using keys from $row rather than plain variables. Move the variable assignments into your loop from above.

while ($row = $result->fetch_array(MYSQLI_ASSOC)) {

  // Move these assignments into the loop so they are available to your
  // echo statement when constructing your <tbody>
  $ID = $row ['ID'];     
  $firstname = $row ['firstname'];     
  $lastname = $row['lastname'];
  $partner  = $row['spousefirst'];   
  $phonecell = $row['phonecell'];
  $email = $row['email'];
  $date = $row['date'];
  $contacttype = $row['contacttype'];
  $agentassigned = $row['agentassigned'];
  $leadstatus = $row['leadstatus'];

  echo'
 <tbody>       
   <tr>
    <td width="10"><input type="checkbox" name="" id="" value="'.$ID.'"></td>
    <td><a href="/backend/leads/view/?ID='.$ID.'"><strong>'.$firstname.' '.$lastname.'</strong></a></td>
    <td><a href="/backend/leads/view/?ID='. $ID.'">'.$partner.'</a></td>
    <td>'.$phonecell.'</td>
    <td><a href="mailto:'. $email.'">'.$email.'</a></td>
    <td>'.date("M jS, g:i A", strtotime($date)).'</td>
    <td>'.$contacttype.'</td>
    <td>'.$agentassigned.'</td>
    <td>'.$leadstatus.'</td>
    <td><a href="/backend/contacts/notes.php?ID='.$ID.'">View</a> +</td>
    <td><a href="/backend/contacts/todo.php?ID='.$ID.'">View</a> +</td>
    <td><a href="/backend/contacts/deletesuccess.php?ID='.$ID.'">D</a></td>
   </tr>
 </tbody>       
</table>';

}

Edit

About your other few questions...

I would say there isn't much to gain from storing this in an include file. It isn't a lot of code, and if you don't plan on reusing it in other places there won't be a benefit to moving it out of this file.

Your query is static, not making use of any PHP variables. It is therefore also not of much benefit to store them in an array, which would then require extra work in PHP to convert into SQL.

$options = array('Buyer','Seller','Buyer / Seller','Investor');
// Join them into a string and quote both ends of it.
// If this includes any user input, you must call `$mysqli->real_escape_string()` on _each_ of them.
// Since in this one instance it is static in your code though without variables, that isn't necessary here
$options = "'" . implode("','", $options) . "'";
$query = ("SELECT * FROM contacts WHERE contacttype IN ($options) AND leadstatus = 'New' ORDER BY date DESC");
Michael Berkowski
  • 267,341
  • 46
  • 444
  • 390