dmccabe Posted December 19, 2008 Share Posted December 19, 2008 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 More sharing options...
ngreenwood6 Posted December 19, 2008 Share Posted December 19, 2008 You do not need this: MYSQL_ASSOC Link to comment https://forums.phpfreaks.com/topic/137691-solved-why-do-my-sql-queries-never-work/#findComment-719700 Share on other sites More sharing options...
ngreenwood6 Posted December 19, 2008 Share Posted December 19, 2008 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. Link to comment https://forums.phpfreaks.com/topic/137691-solved-why-do-my-sql-queries-never-work/#findComment-719702 Share on other sites More sharing options...
premiso Posted December 19, 2008 Share Posted December 19, 2008 $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] Link to comment https://forums.phpfreaks.com/topic/137691-solved-why-do-my-sql-queries-never-work/#findComment-719703 Share on other sites More sharing options...
premiso Posted December 19, 2008 Share Posted December 19, 2008 You do not need this: MYSQL_ASSOC Yea, it makes it return an associative array instead of both. It saves memory space. That had nothing to do with why this was not working. Link to comment https://forums.phpfreaks.com/topic/137691-solved-why-do-my-sql-queries-never-work/#findComment-719704 Share on other sites More sharing options...
dmccabe Posted December 19, 2008 Author Share Posted December 19, 2008 Excellent, thanks again guys, you never fail to amaze Link to comment https://forums.phpfreaks.com/topic/137691-solved-why-do-my-sql-queries-never-work/#findComment-719708 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.