Note that there are some explanatory texts on larger screens.

plurals
  1. PODisplaying results in descending order of value within array variable
    primarykey
    data
    text
    <p>Hi I was wondering if anyone could help me. I have created a questionnaire, there are multiple results (displayed as a %) outputted from the questionnaire. I am able to get these results displayed on a results.php page, along with the corresponding name ($careername) and corresponding link ($link). E.g. I have 5 results which each link to a corresponding career and link and these are displayed on the results.php page. However I need the result, careername and link to display in descending order of the result value. As of now they are displaying in random order. Below is the code I am working with, if anyone has any ideas I would be grateful. </p> <pre><code>&lt;?php $careername1 = 'Nursing '; $careername2 = 'Footballer '; $careername3 = 'Dentist '; $careername4 = 'Hairdressing '; $careername5 = 'IT '; ?&gt; &lt;?php $link1 = '&lt;br&gt;&lt;a href="http://www.nhscareers.nhs.uk/explore-by-career/nursing/" target="_blank"&gt;More information on Nursing&lt;/a&gt;&lt;/br&gt;&lt;/br&gt;'; $link2 = '&lt;br&gt;&lt;a href="#" target="_blank"&gt;More information on Footballing&lt;/a&gt;&lt;/br&gt; &lt;/br&gt;'; $link3 = '&lt;br&gt;&lt;a href="#" target="_blank"&gt;More information on Dentistry&lt;/a&gt;&lt;/br&gt;&lt;/br&gt;'; $link4 = '&lt;br&gt;&lt;a href="#" target="_blank"&gt;More information on Hairdressing&lt;/a&gt;&lt;/br&gt;&lt;/br&gt;'; $link5 = '&lt;br&gt;&lt;a href="#" target="_blank"&gt;More information on IT&lt;/a&gt;&lt;/br&gt;&lt;/br&gt;'; ?&gt; &lt;?php $nursing = array($careername1, $result1, "% ", $link1); $footballer = array($careername2, $result2, "% ", $link2); $dentist = array($careername3, $result3, "% ", $link3); $hairdresser = array($careername4, $result4, "% ", $link4); $IT = array($careername5, $result5, "% ", $link5); ?&gt; &lt;h1&gt;Your results are listed below:&lt;/h1&gt; &lt;?php $items = array("$nursing", "$footballer", "$dentist", "$hairdresser", "$IT"); arsort($items); foreach ($items as $key =&gt; $val) { echo "$key = $val\n"; } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload