Array Sorting
Posted: Mon Mar 27, 2006 3:58 pm
feyd | Please use
My question is this: will this work and how can I loop thru the newly sorted array to display it?
I am a rather newbie to PHP so any and all advice will be much appreciated and welcomed.
Thank you
Leo Zayas
http://www.PoliceSoftball.com
feyd | Please use
Code: Select all
andCode: Select all
tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hello all,
This is for a webpoll application.
And my ISP is NOT running 5.0 and has no intentions of installing it in the near future.
In the database I have 2 fields, 1 that holds the choices (Duke, Memphis, UCLA and so forth separated by commas) and
the other holds the values (0,1,45, and so forth also separated by commas.
below is my code:Code: Select all
<?php
include ('../connection.php');
$theQuery = "SELECT * FROM pswebpoll WHERE pollid = 24";
$theResults = mysql_query($theQuery);
while ($theRow = mysql_fetch_row($theResults))
{
$pollid = $theRow[0];
$question = $theRow[1];
$choices = $theRow[2];
$totalchoices = $theRow[3];
$votetally = $theRow[4];
$startdate = $theRow[5];
$enddate = $theRow[6];
}
// split the choices
$newchoices = split(",", $choices, -1);
$newtally = split(",", $votetally, -1);
//put them into yet another array with the value first and then the choice
for ($count = 0; $count < sizeof($newtally); $count++)
{
$thenewchoices[] = $newtally[$count] . "," . $newchoices[$count];
}
// this gives me 12,Duke; 34,Memphis; 123,UCLA and so forth
krsort($thenewchoices); //I am not sure if this is the right one, what i want to do is sort them in descending order so it would give me
123,UCLA; 34,Memphis; 12,Duke and so forth
?>I am a rather newbie to PHP so any and all advice will be much appreciated and welcomed.
Thank you
Leo Zayas
http://www.PoliceSoftball.com
feyd | Please use
Code: Select all
andCode: Select all
tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]