Jump to content

Recommended Posts

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 by ianhaney50
Link to comment
https://forums.phpfreaks.com/topic/298928-display-specific-column-value/
Share on other sites

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

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.

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.