i have a value from my database. i want to select the most highest value and split it into say ten. then echo it in my select.Any help pls

Recommended Answers

All 3 Replies

Member Avatar

This doesn't make much sense. Are you saying you want to get the maximum value from a field in the table? What does split into 10 mean? Do you mean that you want to select the 10 highest values of a field in a table?

Echo it in a select? I'm assuming you mean place this/these value/s in a select form field?

What have you got so far? Not sure how you expect us to help without any info about the table / fields.

ok the issue is say the highest value in the databse is 500. i want to echo 100 200 300 400 500 in the select box. please thus all am saying.

Member Avatar

So not split into 10?
OK, I think I have an idea...

$sql = "SELECT field FROM table ORDER BY field DESC LIMIT 1";  //or
$sql = "SELECT MAX(field) FROM table"; //2nd one probably quicker - difference depends on whether 'field' is indexed or not

After you get your result (into $val) - easy if using PDO and fetchColumn (http://php.net/manual/en/pdostatement.fetchcolumn.php)

The you need to split it into increments. For this you'd need to create a splitting function to output an array of values (max 10 elements).

Then just create the innards of your select by concatenating:

$str = '';
foreach($arrayValues as $v)
       $str .= "<option value='$v'>$v</option>";


Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.