Jump to content

MYSQL statement


vang163

Recommended Posts

ah yeah, forgot about that.  The desc makes the list overall 100, 99, 98, etc.. so 100 is position 0, so offset 10 is 91 or whatever.  If you change it from desc to asc then the results will be

 

11

12

13

14

...

 

It will be the result set you want, but not the right order. So you can

 

a) remove the desc and reverse the order of the results through php, or

b) change your offset to what 80, 10?

Link to comment
Share on other sites

i do not want to go back to the script and start editing each time i want to view different set of data in different order.

appreciate if anyone could show me or point me the direction on how this can be done with the correct sql statement or logic, thanks.

 

Link to comment
Share on other sites

well if you're talking about getting different results depending on your mood/situation, then that's done by having options in a form to check/select, and building a dynamic query string based on that info... I thought you were wanting help on writing a very specific query string (which is why I moved it to mysql forum).  Are you wanting help on building a dynamic query string in general?

Link to comment
Share on other sites

my initial question written on the other day was:

 

hi,

i've a table with 100 records.

i displayed the data into 10 records per page, therefore i've 10 pages of data.

 

using this query - "select * from table order by $column $direction limit $set_limit $limit_size"

where $column is the table column name

$direction - asc or desc

 

Assuming i'm at page 1, I can view the display data (1,2,3,4..10) in ascending order by default. But when i want to display the data in descending order for page 1, I'm getting descending order data from page 10.

 

I want to be able to see the page 1 data in ascending and in descending order. This applies to all other pages. (2,3,4...10)

Can someone show me how this can be done, thanks.

 

But i did not know what the other helpers are referring to.

That is why i thought the problem lies with the sql statement.

Your assistance in this matter is greatly appreciated, thanks.

Link to comment
Share on other sites

this is my code, i use a function to display the data.

$limit - refers to the number of data rows display. eg. display 10 records per page

$page - refers to the current page number.

 

function displayData($tableName, $column, $direction, $limit, $page)
{
$set_limit = ($page * $limit) - $limit;

$sql = "SELECT * FROM $tableName ORDER BY $column $direction LIMIT $set_limit, $limit";
$result = mysql_query($sql) or die('Query Failed.');
$count = mysql_num_rows($result);	
if ($count <= 0)
{	echo 'No match.';
}
else if ($count > 0)
{	while($row = mysql_fetch_assoc($result))	
	{	echo "   <tr>";
		echo "    <td>" . $row['id'] . "</td>";
		echo "    <td>" . $row['tel'] . "</td>";
		echo "    <td>" . $row['fax'] . "</td>";
		echo "    <td>" . $row['Owner'] . "</td>";
		echo "    <td>" . $row['countryCode'] . "</td>";
		echo "    <td>" . $row['country'] . "</td>";
		echo "   </tr>";
	}
}
}

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.