Data from serverside not display [duplicate] - php

This question already has answers here:
LIMIT 10..20 in SQL Server
(15 answers)
Closed 3 years ago.
hello guys i try data use datatables from serverside (SQL Server) if me use code
my data not found or not availaible. this is my code
$sql.=" ORDER BY ". $columns[$requestData['order'][0]['column']]." ".$requestData['order'][0]['dir']." LIMIT ".$requestData['start']." ,".$requestData['length']." ";
please help me

Use OFFSET and FETCH in SQL Server OFFSET FETCH Clause.
SELECT * FROM table ORDER BY column OFFSET 10 ROWS FETCH NEXT 5 ROWS ONLY;
Possible duplicate: LIMIT 10..20 in SQL Server.

Related

display first n rows with pagination in mysql [duplicate]

This question already has answers here:
Simple PHP Pagination script [closed]
(3 answers)
Closed 6 years ago.
A mysql table contain 100 rows. I am trying to display first 20 rows with 5 rows per page.
I think query should be like this
SELECT * FROM `table` top 20 LIMIT 0, 5
but how can i use this concept. waiting for your help.
You can use LIMIT and OFFSET controls, LIMIT is for max rows you want to show and OFFSET is the starting position:
SELECT * FROM db_name ORDER BY db_table LIMIT 5 OFFSET 0

mysql and php fetch_assoc() not working [duplicate]

This question already has answers here:
Can I mix MySQL APIs in PHP?
(4 answers)
Closed 7 years ago.
I have the following:
<?php
include 'connect.php';
//get average from all reviews
$allreviews = "SELECT round(avg(Stars_overall),0) AS average FROM (SELECT Stars_overall FROM Reviews WHERE Meal_ID = 1 ORDER BY Order_ID DESC LIMIT 5) AS Average";
$getresult = mysqli_query($conn, $allreviews);
$row3 = mysql_fetch_assoc($getresult);
echo "aaaaa" .$row3['average']. "bbbbb";
mysqli_close($conn);
?>
Unfortunately it is not working, any clue why? It is for a review system, i'm trying to display an average of star ratings stored in database. The first sql gets all the ratings for a specific meal and the second sql calculates the average. I then want to be able to display the average
You are using mysqli, therefore you must use mysqli_fetch_assoc and not mysql_fetch_assoc.

Using a MySQL Query result as a PHP variable [duplicate]

This question already has answers here:
Read one column from one row from a MySQL database
(8 answers)
Closed 8 years ago.
I am having an issue declaring a PHP variable as a MySQL result.
Code:
$num = mysql_query("SELECT num FROM numbers ORDER BY num DESC LIMIT 1");
What it does it retrieve the latest entry in the database, which is an int, and I want it to store into the PHP variable $num. Is this possible?
Is this possible?
Yes, that is possible.
You should, however, use mysqli or PDO instead of the old mysql_ functions.
See: Why shouldn't I use mysql_* functions in PHP?
An example of how it could look:
$result = $mysqli->query("SELECT num FROM numbers ORDER BY num DESC LIMIT 1");
$num = $result->fetch_object()->num;

Limit query runtime to 2 seconds [duplicate]

This question already has answers here:
Anyway to Limit MySQL Query Execution time?
(4 answers)
Closed 9 years ago.
How can I limit the runtime of a SQL I call with a php file to 2 seconds
here an example I am using
$output = '';
$sql = "SELECT epf_application.view_url FROM epf_application INNER JOIN app_uri ON epf_application.application_id=app_uri.application_id WHERE app_uri.uri = '$URL' LIMIT 1";
foreach ($xpdo->query($sql) as $row) {
$output .= $row['view_url'];
}
I dont want to limit the whole script runtime only the request on the database
You can't! As the query is blocking and you'll only know how long it took when it's done.
So you need to optimize your Queries if they are too slow. You do that by analyzing and testing and by using INDEXES in the right places and playing with EXPLAIN.

MySQL - Start without limit [duplicate]

This question already has answers here:
MySQL offset infinite rows
(10 answers)
Closed 9 years ago.
I have the following SQL code;
SELECT * FROM myTable WHERE id = 1 LIMIT 4, 10;
I would like the sql to run from result 4 but have no end limit, so I would like the script to get all the results from 4 onwards. Is this possible?
Any help appreciated.
You can use the OFFSET option in your query. Like this
SELECT *
FROM myTable
WHERE id = 1
OFFSET 4
SELECT * FROM tbl LIMIT 4, 18446744073709551615;
resource mysql docs.

Categories