0

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

2
Contributors
3
Replies
11
Views
1 Year
Discussion Span
Last Post by diafol
0

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.

0

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.

0

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>";
}

Then

<select>
    <?=$str?>
</select>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.