Jump to content

display records


ianhaney50

Recommended Posts

I could not get the last repair_id outputting so am tackling this issue from another angle, I am going to do away with repair_id and just use id which is AI and primary key

 

I am going to display the whole row instead but limit it to 1 and order by ID DESC so shows the highest id number but the issue I got is it shows all records but the second I put LIMIT 1 in it only shows the id number and no other data, am getting bit fed up with to be honest but want to get it done

 

I have the following coding at the moment

<?php
$servername = "";
$username = "";
$password = "";
$dbname = "";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

//run the query
$sql = "SELECT * FROM repairs ORDER BY id DESC";
$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) {

//fetch the results
while($row = mysqli_fetch_assoc($result)) {

echo $row['id'] . $row['repair_id'] . " " . $row['customer_name'] . " " . $row['customer_email'] . " "  . $row['customer_phone'];
}
} else {
    echo "0 results";
}
echo $sql;

mysqli_close($conn);

?>

This is outputting the following

 

17 16 15 14 13 12004 Ian Haney ianhaney@broadwaymediadesigns.co.uk 01268 92843011004 Ian Haney ianhaney@broadwaymediadesigns.co.uk 01268 92843010 9 8003 Ian Haney ianhaney@broadwaymediadesigns.co.uk 01268 9284307003 Ian Haney ianhaney@broadwaymediadesigns.co.uk 01268 9284306003 Ian Haney ianhaney@broadwaymediadesigns.co.uk 01268 9284305002 Ian Haney ianhaney@broadwaymediadesigns.co.uk 01268 9284304001 Ian Haney ianhaney@broadwaymediadesigns.co.uk 01268 9284303 2 SELECT * FROM repairs ORDER BY id DESC

 

Please help me and see where I am going wrong with it

Link to comment
Share on other sites

Your output seems to be exactly what you are echo-ing.  If you want it formatted, do it with your echo or simply add another echo to output a line break. (inside the loop).

 

As for missing items and the limit 1 points - show us that code if you want to discuss it.

Link to comment
Share on other sites

Thank you for the reply, appreciate it

 

Below is the code with the LIMIT in the query

<?php
$servername = "";
$username = "";
$password = "";
$dbname = "";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

//run the query
$sql = "SELECT id, customer_name, customer_email, customer_phone FROM repairs ORDER BY id DESC LIMIT 1";
$result = $conn->query($sql);

if ($result->num_rows > 0) {

//fetch the results
while($row = $result->fetch_assoc()) {

echo $row['id'] . " " . $row['customer_name'] . " " . $row['customer_email'] . " "  . $row['customer_phone'];
}
} 
else {
    echo "0 results";
}
echo $sql;

$conn->close();

?>

All that code does is output the following

 

17 SELECT id, customer_name, customer_email, customer_phone FROM repairs ORDER BY id DESC LIMIT 1 

 

It seems to stop at the id number and not output the name, email and phone

Link to comment
Share on other sites

Very strange isn't it

 

I altered the coding to what you provided and now outputs the following

 

id 17 name email phone 
SELECT id, customer_name, customer_email, customer_phone FROM repairs ORDER BY id DESC LIMIT 1 

 

is very weird that it outputs the id number but not the customer name, email and phone

Link to comment
Share on other sites

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.