Jump to content

[SOLVED] Why do my SQL queries never work :(


dmccabe

Recommended Posts

All I am wanting to do is to out put all the items in a particular table, but no I get

"#Resourceid_6" instead, what am I doing wrong?

 

if (isset($_POST['submit'])) {
if (isset($_POST['all'])) {
	$query = "SELECT * FROM `tbl_vehicles`";
	if (!mysql_query($query)) {
		die(mysql_error());
	} else {
		$result = mysql_query($query);
		echo "<table>
				<tr>
					<td><strong>REG</strong></td>
					<td><strong>MAKE</strong></td>
					<td><strong>MODEL</strong></td>
					<td><strong>COLOUR</strong></td>
					<td><strong>REG</strong></td>
					<td><strong>STATUS</strong></td>
					<td><strong>LOCATION</strong></td>
					<td><strong>MILEAGE</strong></td>
					<td><strong>FUEL TYPE</strong></td>
					<td><strong>TRANSMISSION</strong></td>
					<td><strong>OFF FLEET DATE</strong></td>
				</tr>";
		while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
			$make_id = $row['MAKE_ID'];
			echo "<tr><td>{$row['REG']}</td>";
			$make = mysql_query("SELECT `NAME` FROM `tbl_veh_make` WHERE `ID` = '$make_id'");
			echo	"<td>$make</td>
				</tr>";
		}
		echo "</table>";
	}
}
}
?>

Link to comment
https://forums.phpfreaks.com/topic/137691-solved-why-do-my-sql-queries-never-work/
Share on other sites

Try this:

 

if (isset($_POST['submit'])) {
if (isset($_POST['all'])) {
	$query = "SELECT * FROM `tbl_vehicles`";
	$result = mysql_query($query);

echo "<table>
				<tr>
					<td><strong>REG</strong></td>
					<td><strong>MAKE</strong></td>
					<td><strong>MODEL</strong></td>
					<td><strong>COLOUR</strong></td>
					<td><strong>REG</strong></td>
					<td><strong>STATUS</strong></td>
					<td><strong>LOCATION</strong></td>
					<td><strong>MILEAGE</strong></td>
					<td><strong>FUEL TYPE</strong></td>
					<td><strong>TRANSMISSION</strong></td>
					<td><strong>OFF FLEET DATE</strong></td>
				</tr>";
		while($row = mysql_fetch_array($result)){
			$make_id = $row['MAKE_ID'];
			echo "<tr><td>" . $row['REG'] . "</td>";
			$make = mysql_query("SELECT `NAME` FROM `tbl_veh_make` WHERE `ID` = '$make_id'");
                                                   $make_row = mysql_fetch_assoc($make);
			echo	"<td>" . $make_row['name'] . "</td>
				</tr>";
		}
		echo "</table>";
	}
}
}
?>

 

if you get any errors please post them. also tell me what it is not doing.


$query = "SELECT * FROM `tbl_vehicles`";
$result = mysql_query($query) or die (mysql_error());

if (mysql_num_rows($result) > 0) {


echo "<table>











<tr>













<td><strong>REG</strong></td>













<td><strong>MAKE</strong></td>













<td><strong>MODEL</strong></td>













<td><strong>COLOUR</strong></td>













<td><strong>REG</strong></td>













<td><strong>STATUS</strong></td>













<td><strong>LOCATION</strong></td>













<td><strong>MILEAGE</strong></td>













<td><strong>FUEL TYPE</strong></td>













<td><strong>TRANSMISSION</strong></td>













<td><strong>OFF FLEET DATE</strong></td>











</tr>";







while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {









$make_id = $row['MAKE_ID'];









echo "<tr><td>{$row['REG']}</td>";









$makeRes = mysql_query("SELECT `NAME` FROM `tbl_veh_make` WHERE `ID` = '$make_id'");
$make = mysql_fetch_assoc($makeRes);
$make = $make['NAME'];









echo



"<td>$make</td>











</tr>";

}
echo "</table>";
}

 

Sorry about the formating. I would suggest using [ code] over [ php]

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.