multisort problem

This is a discussion on "multisort problem" within the PHP Forum section. This forum, and the thread "multisort problem are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Sep 2nd, 2007, 15:58
Junior Member
Join Date: Nov 2006
Location: us
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
multisort problem

Hi,
Not sure what is wrong with the function of array_multisort(), I have checked line by line, the error tells Parse error:
Quote:
parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in d:\easyphp1-8\www\study\array_multisort.php on line 13.
I don't understand whats wrong with my code which I have copied from php book.

PHP: Select all

<?php
    $class
=array("score" =>array(123,345,23,66,7,821,10,33,90,100), "name" =>array("Alice","Peter","Elvin","Sindy","Simon","Bob","Hank","Charlie","Caroline","Linda"));
    `

        
    array_multisort($class
["score"],SORT_NUMERIC, SORT_DESC, $class["name"], SORT_STRING, SORT_ASC);
    
    
    echo "<table bgcolor='#ffff99' border='2' width='80%'>";
    echo "<tr><th>Score</th>";
    for($a=0; $a<10; $a++){
        echo "<td>".$class
["score"][$a]."</td>";
    }
    echo "</tr><tr><th>Name</th>";
    for($a=0; $a<10; $a++){
        echo "<td>".$class
["name"][$a]."</td>";    
    }
?>
Can someone help me out this problem? Much appreciated!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Sep 2nd, 2007, 17:35
Highly Reputable Member
Join Date: Apr 2007
Location: Willich, Germany
Age: 20
Posts: 593
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: multisort problem

I think your problem is where the red is, not the array_multisort function...
Code: Select all
 <?php
    $class=array("score" =>array(123,345,23,66,7,821,10,33,90,100), "name" =>array("Alice","Peter","Elvin","Sindy","Simon","Bob","Hank","Charlie","Caroline","Linda"));
    `
        
    array_multisort($class["score"],SORT_NUMERIC, SORT_DESC, $class["name"], SORT_STRING, SORT_ASC);
    
    
    echo "<table bgcolor='#ffff99' border='2' width='80%'>";
    echo "<tr><th>Score</th>";
    for($a=0; $a<10; $a++){
        echo "<td>".$class["score"][$a]."</td>";
    }
    echo "</tr><tr><th>Name</th>";
    for($a=0; $a<10; $a++){
        echo "<td>".$class["name"][$a]."</td>";    
    }
?>
I think you'd be better off using single quotes:
PHP: Select all

<?php
    $class
=array("score" =>array(123,345,23,66,7,821,10,33,90,100), "name" =>array("Alice","Peter","Elvin","Sindy","Simon","Bob","Hank","Charlie","Caroline","Linda"));

    
array_multisort($class["score"],SORT_NUMERICSORT_DESC$class["name"], SORT_STRINGSORT_ASC);
    
    
    echo 
"<table bgcolor='#ffff99' border='2' width='80%'>";
    echo 
"<tr><th>Score</th>";
    for(
$a=0$a<10$a++){
        echo 
"<td>".$class['score'][$a]."</td>";
    }
    echo 
"</tr><tr><th>Name</th>";
    for(
$a=0$a<10$a++){
        echo 
"<td>".$class['name'][$a]."</td>";    
    }
?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Sep 2nd, 2007, 17:36
Reputable Member
Join Date: Apr 2007
Location: Scotland
Age: 17
Posts: 233
Thanks: 0
Thanked 0 Times in 0 Posts
Re: multisort problem

Could it be the random "`" under your $class variable?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Sep 3rd, 2007, 05:25
Junior Member
Join Date: Nov 2006
Location: us
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Re: multisort problem

Quote:
Originally Posted by c010depunkk View Post
I think your problem is where the red is, not the array_multisort function...
Code: Select all
 <?php
    $class=array("score" =>array(123,345,23,66,7,821,10,33,90,100), "name" =>array("Alice","Peter","Elvin","Sindy","Simon","Bob","Hank","Charlie","Caroline","Linda"));
    `
        
    array_multisort($class["score"],SORT_NUMERIC, SORT_DESC, $class["name"], SORT_STRING, SORT_ASC);
    
    
    echo "<table bgcolor='#ffff99' border='2' width='80%'>";
    echo "<tr><th>Score</th>";
    for($a=0; $a<10; $a++){
        echo "<td>".$class["score"][$a]."</td>";
    }
    echo "</tr><tr><th>Name</th>";
    for($a=0; $a<10; $a++){
        echo "<td>".$class["name"][$a]."</td>";    
    }
?>
I think you'd be better off using single quotes:
PHP: Select all

<?php
    $class
=array("score" =>array(123,345,23,66,7,821,10,33,90,100), "name" =>array("Alice","Peter","Elvin","Sindy","Simon","Bob","Hank","Charlie","Caroline","Linda"));

    
array_multisort($class["score"],SORT_NUMERICSORT_DESC$class["name"], SORT_STRINGSORT_ASC);
    
    
    echo 
"<table bgcolor='#ffff99' border='2' width='80%'>";
    echo 
"<tr><th>Score</th>";
    for(
$a=0$a<10$a++){
        echo 
"<td>".$class['score'][$a]."</td>";
    }
    echo 
"</tr><tr><th>Name</th>";
    for(
$a=0$a<10$a++){
        echo 
"<td>".$class['name'][$a]."</td>";    
    }
?>
I got it. It works fine. Thanks a lot.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Sep 3rd, 2007, 05:55
Highly Reputable Member
Join Date: Apr 2007
Location: Willich, Germany
Age: 20
Posts: 593
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: multisort problem

Ur welcome.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
array_multisort

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
First image problem and inline list problem konnor5092 Web Page Design 8 Dec 1st, 2007 09:08


All times are GMT. The time now is 22:46.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42