473,388 Members | 1,408 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Order By

38
Hi

I am trying to order the following query by price when the varaible $concern=="price"; But it is not working. Here is my code.

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3.     for($key=0 ;$key<count($first);$key++)
  4.   {
  5.    if(($first[$key])>0.1){
  6.             $blank++;
  7.             $set=$key+1;
  8.         if($concern=="price"){
  9.             $sql2 = "SELECT * FROM laptop2 WHERE CODE=$set ORDER BY PRICE";
  10.             $query2 = $DB->Query($sql2);
  11.            }
  12.  
  13.  echo'<p> <hr noshade="noshade" /></p>';
  14.    }
  15.  
  16.                if($array = $DB->FetchArray($query2)){
  17.  
  18.     echo "<table  bgcolor=LightGrey border=1>\n";
  19.     echo"<tr><td>ID</td><td>Brand</td><td>Model</td><td>Processor (GHz)</td>
  20.     <td>Hard Drive (GB)</td><td> Graphic card (MB)</td>
  21.     <td>Battery life(Hours)</td><td>Multimedia</td><td>Price (£)</td></tr>\n";
  22.   // do {
  23.  
  24.  printf("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</d><td>%s</d><td>%s</d><td>%s</d> </tr>",$array['CODE'],$array['BRAND'],$array['MODEL'],$array['PROCESSOR (Ghz)'],
  25.             $array["STORAGE (GB)"],$array["GRAPHIC CARD (MB)"],$array["BATTERY"],$array["MULTIMEDIA"],$array["PRICE"]);
  26.      // print_r($array);
  27.  
  28.     }while($array=$DB->FetchArray($query2));
  29.    echo"</table>\n";
  30.  
Can you spot something?

Thanks
Jan 21 '09 #1
9 1333
Markus
6,050 Expert 4TB
I doubt your column 'price' is uppercase (PRICE - like you wrote in your query). Make it lowercase. Also, for the future's sake, you should *really* be using back-ticks around your column names and table names.

Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT
  3.     *
  4. FROM
  5.     `laptop2`
  6. WHERE
  7.     `code` = '{$set}'
  8. ORDER BY
  9.     `price`
  10.  
  11.  
However, your columns may be uppercase and, if so, disregard my suggestion.
Jan 21 '09 #2
poreko
38
Thank you for your suggestions but in my columns price is uppercase.
Jan 21 '09 #3
Markus
6,050 Expert 4TB
Does your $DB->query() return any errors? Try echo()ing mysql_error() after you have performed the query.
Jan 21 '09 #4
poreko
38
$DB->query() does not return errors. What do you mean by echo()ing mysql_error()?
Jan 21 '09 #5
Markus
6,050 Expert 4TB
You can get the last error generated by mysql by mysql_error(). So, after the query, do this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. die(mysql_error());
  3.  
  4.  
Jan 21 '09 #6
Atli
5,058 Expert 4TB
That would be your standard:
Expand|Select|Wrap|Line Numbers
  1. $result = mysql_query($sql) or die(mysql_error());
If you have created yourself a class to handle the database interactions, you should add something to capture the error in case the query fails.

Edit: Seconds to late :]
Jan 21 '09 #7
poreko
38
I already have that added it my class
Jan 21 '09 #8
Markus
6,050 Expert 4TB
OK. What exactly is not working?
Jan 22 '09 #9
poreko
38
It is not sorting it by price, the results are still random.
Jan 22 '09 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: svilen | last post by:
hello again. i'm now into using python instead of another language(s) for describing structures of data, including names, structure, type-checks, conversions, value-validations, metadata etc....
9
by: Steven T. Hatton | last post by:
The following works: template <typename T> struct ID3M{ static const T ID; }; template <typename T> const T ID3M<T>::ID = {{1,0,0},{0,1,0},{0,0,1}};
15
by: | last post by:
The data file is a simple Unicode file with lines of text. BCP apparently doesn't guarantee this ordering, and neither does the import tool. I want to be able to load the data either sequentially...
27
by: Abdullah Kauchali | last post by:
Hi folks, Can one rely on the order of keys inserted into an associative Javascript array? For example: var o = new Object(); o = "Adam"; o = "Eve";
8
by: kaosyeti | last post by:
i have a (hopefully) small problem. i have created a system where a user enters customer information into a table through a form. this table has no primary key. there are 9 fields on the form to...
104
by: Beowulf | last post by:
I have the view below and if I use vwRouteReference as the rowsource for a combo box in an MS Access form or run "SELECT * FROM vwRouteReference" in SQL Query Analyzer, the rows don't come through...
13
by: bevanward | last post by:
Hi All I am finding unexpected results when inserted into a newly created table that has a field of datatype int identity (1,1). Basically the order I sort on when inserting into the table is...
3
by: Hartmut Dippon | last post by:
Hi all, I hope somebody can help me with following problem: I have an application where I can drag&drop files/dirs from within explorer onto my form. If multiple files/dirs are selected I...
54
by: Rasjid | last post by:
Hello, I have just joined and this is my first post. I have never been able to resolve the issue of order of evaluation in C/C++ and the related issue of precedence of operators, use of...
25
by: DanicaDear | last post by:
Hello again Bytes...I missed you! First, background: In a hotstick lab, we ship orders every two years. We ship a new order and the customer uses the new box to return the previous year's order....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
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...
0
marktang
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,...
0
Oralloy
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.