<M/> 170

Oh a got another question... how do I make every even/odd number have for example: all evens are blue... and odds are red?

Do you know if that is possible?

And how come the table's won't separate when I insert break tags?

I know you helped me truly a lot but do you mind answering this last question????

Thank you for all your help!
Sedique

<M/> 170

You don't realize how much you've helped me! You solved my biggest problem and I'd like to thank you for that! Those errors I made are stupidity of mine I guess and I think I was experimenting...

But I came up with a question, is there other ways in sorting a loop or maybe a better way and a way I shouldn't do it?

Other than that question, you really helped me through this one!
I truly thank you and wish you the best of luck in computer programming! Hopefully, I'll be as good as you in maybe about a 2-3 years!

Thanks!
Sedique

<M/> 170

Dear DANIWEB community members,

I have a question about sorting a label, and I've tried so hard in figureing it out but I realized that I am doing something wrong but not sure what... What I am doing is sorting the numbers, which is created by the loop, that populate the array...

The first table shows all the numbers in a random order

The second table displays the numbers in order and the numbers are the ones that come from table 1.

Anyone have a clue on how to do it?

``````<?php
\$red = array();
\$x=0;
\$min=900;
\$max=2000;
echo "<table border=\"1\">";
for(\$row=1;\$row<=20; \$row++){
echo "<tr>\n";

for(\$col=1;\$col<=20; \$col++){
\$x=rand(\$min,\$max);
\$red[\$row][\$col] = \$x;
\$blue[\$row][\$col]=\$table[\$row][\$col];
echo"<td>\$x</td>\n";
}
echo "</tr>";
}

sort(\$red);
foreach (\$red as \$key=> \$value) {
echo \$value. "<br>\n";
echo "</table>";
echo "<table border=\"1\">";
\$red[\$row][\$col] = \$x;
echo"<td>\$y</td>\n";
}
echo "</tr>";
echo "</table>";
?>

<?php
sort(\$red);
foreach (\$red as \$key => \$value) {
echo \$value. "<br>\n";
}
?>``````

Please take your time and help me! If this is unclear please tell me so I can be clearer!
Thanks!,
Sedique

<M/> 170

Well, I am trying to take a table that is randomly sorted, and I wanted to put it in order (biggest to smallest)... apparently, whatever I do, it doesn't work... And I filled the array up with a loop... (maybe my loop is designed wrong?)

That's what I am trying to do!
Thanks!

<M/> 170

Apparently, I do have knowledge on how to do arrays... but the link you gave me wasn't very helpful... do you have any other solutions?

Thanks!

<M/> 170

I have a 2 dim array (5x5) - I want to sort random integers that are contained within the array (from smallest to largest).... When I use asort() function I get the orginal table back... Also, the bubble sort didn't work... it only sorts the rows indpendently....

Reference:/// Can someone PLEASE Help and point out what is wrong.... feel free to write back a few lines of code that may work....

Thanks!

``````<?php
// Assign values ....

\$table = array();
\$x=0;
\$min=60;
\$max=101;

echo "<table border=\"1\">";
for(\$row=1;\$row<=4; \$row++){

echo "<tr>\n";

for(\$col=1;\$col<=5; \$col++){
\$x=rand(\$min,\$max);
\$table[\$row][\$col] = \$x;

echo"<td>\$x</td>\n";
}
echo "</tr>";
}
echo "</table>";
asort(\$table);

//Try her to re-display the table using BUBBLE SORT each row gets sorted but not the entire table...

echo "<table border=\"1\">";
for(\$row=1;\$row<=5; \$row++){

echo "<tr>\n";

for(\$col=1;\$col<=5; \$col++){

for(\$j=1;\$j<=5;\$j++){

if (\$table[\$row][\$col]>\$table[\$row][\$col+1]){

\$temp=\$table[\$row][\$col];
\$table[\$row][\$col]=\$table[\$row][\$col+1];
\$table[\$row][\$col+1]=\$temp;
}
}

}
echo "</tr>";
}
echo "</table>";

//
asort(\$table);  // The asort() does not affect the table - it gives back the same one....

echo "<table border=\"1\">";
for(\$row=1;\$row<=4; \$row++){

echo "<tr>\n";

for(\$col=1;\$col<=5; \$col++){

\$y= \$table[\$row][\$col];

echo"<td>\$y</td>\n";
}
echo "</tr>";
}
echo "</table>";
?>

:)``````
<M/> 170

Can you write me a couple of lines on how to do it? Apparently, I have messed up numerous times today in making this work... do you mind helping?

Thanks again!

<M/> 170

No, this isn't for a class of any sort... this is just me trying to figure out different ways of manipulating arrays...

Apparently I want to use a loop to sort these... you know how to set this up?

Thanks for the quick response!

<M/> 170

How do I sort this loop? I can't sort it because I just began learning PHP, so I don't know as much as most of you users... Can anyone help me?

``````<?php
\$red = array();
\$x=0;
\$min=500;
\$max=2000;

echo "<table border=\"1\">";
for(\$row=1;\$row<=20; \$row++){

echo "<tr>\n";
//Need table ONE to have 20 by 20 rows & columns
//Need the table to contain numbers between 900 - 2000 (Randomly)
//Table two will take table ONE and sorts it from Smallest to Biggest
//Table three will take table ONE and sorts it from Biggest to Smallest
//Table 4 will only show a (*) net to the Odd Numbers and (#) next to the Even Numbers

for(\$col=1;\$col<=20; \$col++){
\$x=rand(\$min,\$max);
\$red[\$row][\$col] = \$x;
\$blue[\$row][\$col]=\$table[\$row][\$col];

echo"<td>\$x</td>\n";
}
echo "</tr>";
}
echo "</table>";

\$blue= array();
echo "<table border=\"1\">";

for(\$row=1;\$row<=20; \$row++){
echo "<tr>\n";

for(\$col=1;\$col<=20;\$col++){
\$blue[\$row][\$col] = \$y;
echo"<td>\$y</td>\n";
}
echo "</tr>";
}
echo "</table>";
?>``````