I want to sort the following table, that contains this data, in a .php page I'll use on my website.
I want to sort it by a few columns too, I want it to sort by points, then difference, then for.
The following is the code I have in my .php file. - <? $hostname = "***.secureserver.net"; // The mySQL DB server.
-
$username = "acssl_table"; // The username you created for this database.
-
$password = "Victoria3"; // The password you created for the username.
-
$usertable = "table"; // The name of the table you made.
-
$dbName = "acssl_table"; // This is the name of the database you made.
-
-
MYSQL_CONNECT($hostname, $username, $password) OR DIE("DB connection unavailable");
-
@mysql_select_db( "$dbName") or die( "Unable to select database");
-
?>
-
<?
-
//error message (not found message)begins
-
$XX = "No Record Found, to search again please close this window";
-
//query details table begins
-
$query = mysql_query("SELECT * FROM `table` LIMIT 0, 30 ");
-
while ($row = @mysql_fetch_array($query))
-
{
-
$variable1=$row["team"];
-
$variable2=$row["played"];
-
$variable3=$row["won"];
-
$variable4=$row["drawn"];
-
$variable5=$row["lost"];
-
$variable6=$row["for"];
-
$variable7=$row["against"];
-
$variable8=$row["difference"];
-
$variable9=$row["points"];
-
//table layout for results
-
-
print ("<tr>");
-
print ("<td width='150'><span class='BodyTable'>$variable1</span></td>");
-
print ("<td width='50' align='center'><span class='BodyTable'>$variable2</span></td>");
-
print ("<td width='50' align='center'><span class='BodyTable'>$variable3</span></td>");
-
print ("<td width='50' align='center'><span class='BodyTable'>$variable4</span></td>");
-
print ("<td width='50' align='center'><span class='BodyTable'>$variable5</span></td>");
-
print ("<td width='50' align='center'><span class='BodyTable'>$variable6</span></td>");
-
print ("<td width='50' align='center'><span class='BodyTable'>$variable7</span></td>");
-
print ("<td width='75' align='center'><span class='BodyTable'>$variable8</span></td>");
-
print ("<td width='75' align='center'><span class='BodyTable'>$variable9</span></td>");
-
print ("</tr>");
-
}
-
//below this is the function for no record!!
-
if (!$variable1)
-
{
-
print ("$XX");
-
}
-
//end
-
?>
4 1607
The images did not work for me.
I would suggest, however, that you use a simple ORDER BY clause when doing your SELECT: -
$query = mysql_query("SELECT * FROM `table` ORDER BY points DESC, difference ASC, for ASC LIMIT 0, 30 ");
-
thanks, but that doesn't completely work..
it'll only let me sort it by the Points and Difference. Whenever I try to sort using for, the entire table crashes.
why?
Even if I'm sorting by For on its own, it crashes the table.
heres another screenshot of the data, hopefully this one will work.
but i doubt the problem is in the actual database
thanks, but that doesn't completely work..
it'll only let me sort it by the Points and Difference. Whenever I try to sort using for, the entire table crashes.
why?
Even if I'm sorting by For on its own, it crashes the table.
Of course it sorts by Point and Difference only. That is what has been specified in the SELECT statement. For other columns, you just have to change the SELECT statement's ORDER BY sequence to get another order for other column(s).
So, when you want to sort on 'For' you issue the statement - $query = mysql_query("SELECT * FROM `table` ORDER BY for ASC LIMIT 0, 30 ");
Ronald :cool:
Sign in to post your reply or Sign up for a free account.
Similar topics
by: somaBoy MX |
last post by:
This may be a stupid question, but what is the easiest way to sort a mysql
resultset?
For example I have a resulset containing a colomn 'product_name_english' and
'product_name_french' and want...
|
by: Phil Powell |
last post by:
Very simplistic but I am utterly STUMPED at this one.
I have a db table "person" that I can sort by title, first_name,
last_name, or city with no problems at all because "title",
"first_name",...
|
by: anders thoresson |
last post by:
Is it possible to resort the rows in a table like in a query where using
ORDER BY, but have to new sort order stored in the table structure?
--
anders thoresson
--
MySQL General Mailing List...
|
by: yellow1912 |
last post by:
Ok, lets say I have 1000 items in my database (mysql) and want to
display X items per page. I learned to do it by querying with the LIMIT
constrain (something like this...
|
by: phillip.s.powell |
last post by:
Ok, you have three tables. You're supposed to be able to not only sort
(ORDER BY) according to a_name, no problem, but you must also have the
ability to sort (ORDER BY) the relationship between...
|
by: news reader |
last post by:
Hi,
Does anoone of you know if there is already a simple application doing
something like this.
I would enhance / tune the missing features, but would like to avoid to
start from scratch or...
|
by: weetat.yeo |
last post by:
Hi all ,
I have sql statement below ,
SELECT
serial_no,host_name,chasis_model,chasis_flash_size,chasis_dram_size,...
|
by: Vic Spainhower |
last post by:
Hello,
I have an HTML table that is being constructed from a MySQL table and
displays a form that includes a check box on 1 of the fields on the form for
each record. I have included in this PHP...
|
by: mfaisalwarraich |
last post by:
Hi Everybody,
I am using the following function to get the data from mysql database. i have entered appnum field as text filed in the database which has leading zeroes to this field like if...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |