ianhaney50 Posted October 30, 2015 Share Posted October 30, 2015 (edited) Hi I have decided to build my own repair tracking system which thought would be better and also learn as well at the same time and is all working perfect I just can't seem to get the value of the last repair_id number, it is not AI or anything I have the following code $sql = "SELECT repair_id FROM repairs"; then where I want it to echo, I have the following <?php echo $repair_id; ?> I know I am missing something like return to retrieve the column value or something but not 100% Sorry Edited October 30, 2015 by ianhaney50 Quote Link to comment Share on other sites More sharing options...
ianhaney50 Posted October 30, 2015 Author Share Posted October 30, 2015 Sorry just a update I have the following now $sql = "SELECT repair_id FROM repairs LIMIT 1"; $result = $conn->query($sql); if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { echo "Last Repair ID: " . $row["repair_id"]. "<br>"; } } else { echo "0 results"; } $conn->close(); It's just returning blank and just says Last Repair ID: I am not getting any errors as have php error reporting in Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted October 30, 2015 Share Posted October 30, 2015 are you sure there's data in that column in the database table? without an ORDER BY term in your query, that query is will return the first row that's stored in your table, which is not even guaranteed to be the first row you inserted, and which can even change if you optimize or backup/restore your data. i suggest you review all the posts in your last thread, so that you won't be writing and testing extra code trying to get and use data that you cannot guarantee the value of until after a row has been inserted into your database table. Quote Link to comment Share on other sites More sharing options...
ianhaney50 Posted October 30, 2015 Author Share Posted October 30, 2015 Yeah is defiantly data in that column, I changed it to just id and that worked perfect but for some reason it don't like repair_id Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted October 30, 2015 Share Posted October 30, 2015 the capitalization of your column name in the database table probably isn't exactly - repair_id. The query won't produce an error if the capitalization in the query doesn't match the actual table definition, but the php code won't match the column name. if your php error_reporting/display_errors settings are actually turned full on, you would be getting an undefined index error message, unless this code is inside of a html tag or a form element, in which case the error message will only be seen if you do a 'view source' of the output in your browser. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.