By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,116 Members | 1,319 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,116 IT Pros & Developers. It's quick & easy.

More objects from a database

P: 5
Hello there,

I want to make a list, where I have to fetch more than one object from a database.
So with the query and the "fetch_object"-function I need to sort get the "Omschrijving" and "Verkoopprijs" from a database.
They have to be sorted according to the value (selected with a dropdown menu in the html code).

What I'm getting now as a result is only the last item from the database, so nothing cheaper.

If there are any questions, please ask them.


Highlighted in bold you can find the important items in the code.

thanks in advance

Expand|Select|Wrap|Line Numbers
  1. <?
  2.         if(isset($_POST['submit'])){
  3.         $infomin = $_POST['minimumprijs'];
  4.         $infomax = $_POST['maximumprijs'];
  5.         $keuze = mysql_query("SELECT omschrijving, verkoopprijs FROM artikel WHERE verkoopprijs BETWEEN '$infomin' AND '$infomax'");
  6.         $obj = mysql_fetch_object($keuze);
  7.  
  8.  
  9.         $minprijs = $_POST['minimumprijs'];
  10.         $maxprijs = $_POST['maximumprijs'];
  11.  
  12.         if($minprijs>$maxprijs){
  13.             print "Foutmelding: De minimumprijs mag niet hoger zijn dan de maximumprijs!";
  14.         }
  15.         else{
  16.             print "<tr> <td> Artikelnaam: </td> <td> Prijs: </td> </tr> <br/> ";
  17.             print "<tr> <td> $obj->omschrijving </td> <td>$obj->verkoopprijs</td> </tr>";
  18.         }
  19.     }
  20. ?>
Oct 8 '11 #1

✓ answered by Dormilich

They have to be sorted according to the value
you have to do that already in the SQL, check the ORDER BY clause.

I want to make a list, where I have to fetch more than one object from a database.
then you would have to fetch it in a loop (with the outdated mysql_* functions and the modern MySQLi classes you typically use a while() loop, while the PDO classes work best with a foreach() loop).

Share this Question
Share on Google+
2 Replies


Dormilich
Expert Mod 5K+
P: 8,639
They have to be sorted according to the value
you have to do that already in the SQL, check the ORDER BY clause.

I want to make a list, where I have to fetch more than one object from a database.
then you would have to fetch it in a loop (with the outdated mysql_* functions and the modern MySQLi classes you typically use a while() loop, while the PDO classes work best with a foreach() loop).
Oct 9 '11 #2

P: 5
@dormilich
Thank you very much. I solved it :)
Added a while loop with $obj++ and print the $obj. it gave all values ^^
Oct 9 '11 #3

Post your reply

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