Jump to content

[SOLVED] function help


will35010

Recommended Posts

I'm having a problem calling the second function from the first function. I don't know where the problem is. Any direction would be helpful. Thanks.

 

function vehicleinfo() {
require('lib/opendb.php');
require('lib/functions.php');
$query = mysqli_query($conn, "SELECT vin, plate, expire, year, make, model FROM vehicles");
while($row = mysqli_fetch_array($query)) {
echo "<table width='900' border='1' align='center'>
        <tr>
          <td width='225' align='center' scope='col'>VIN: " . $row['vin'] . "</td>
          <td width='228' align='center' scope='col'>YEAR: " . $row['year'] . "</td>
          <td width='225' align='center' scope='col'>MAKE: " . $row['make'] . "</td>
        </tr>
        <tr>
          <td><div align='center'>PLATE: " . $row['plate'] . "</div></td>
          <td><div align='center'>EXPIRE: " . $row['expire'] . "</div></td>
          <td><div align='center'>MODEL: " . $row['model'] . "</div></td>
        </tr>
        <tr>
          <td><div align='center'>". currentMileage($row['vin']) ."</div></td>
          <td><div align='center'>miles until oil change</div></td>
          <td><div align='center'>Get MPG</div></td>
        </tr>
      </table>
  </tr>
</table>";
}	
}

function currentMileage($vin) {
require('lib/opendb.php');
$query = mysqli_query($conn, "SELECT mileage FROM cmileage WHERE vin = ".$vin."");
$row = mysqli_fetch_array($query);
echo $row['mileage'];
}

Link to comment
https://forums.phpfreaks.com/topic/160960-solved-function-help/
Share on other sites

1. You could have use a JOIN and use one SQL to get everything.

2. In your second function var_dump $row['mileage']. What does that output?

 

Thanks for the help. The problem was with my require('lib/functions.php'). It was declaring a variable twice and causing a fatal error.  ;D

 

Link to comment
https://forums.phpfreaks.com/topic/160960-solved-function-help/#findComment-849458
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.