Someone may help me? It's urgent!

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Someone may help me? It's urgent!

    Hello guys,
    can you please give me some minutes?

    I have stuck somewhere, here is the problem:

    $all = mysql_fetch_array(mysql_query("SELECT a, b, c, d FROM them WHERE nr='1' "));

    From this, I want to print the four values in random order, like:

    print '$all[2]';
    print '$all[0]';
    print '$all[3]';
    print '$all[1]';

    But whats the way to go there?

    Thanks to all!
    mysterio.al - programming is a functional art

    #2
    i dnt get da point of doing this
    Last edited by thanatos; 17.05.10, 13:39.

    Comment


      #3
      What is the output you get with this?
      Mobile chat, iphone chat, android chat, chat, rooms http://www.aiochat.com

      Comment


        #4
        Originally posted by thanatos View Post
        i dnt get da point of doing this
        Forget the point, but help me something if you can!
        mysterio.al - programming is a functional art

        Comment


          #5
          Originally posted by kevk3v View Post
          What is the output you get with this?
          The goal is to get four values from four columns of the same row. But How can I print them in a random order? For example, everytime the page is refreshed, the order has to change.

          You get what I mean?
          mysterio.al - programming is a functional art

          Comment


            #6
            $sql = mysql_query("SELECT DISTINCT a, b, c, d FROM them WHERE nr='1' ORDER BY RAND() DESC LIMIT 0,4");
            while ($items = mysql_fetch_array($sql))
            {

            echo "$items[0]";

            }


            RAND() funtion is function where you can get random datas from ur database...now mate u can have that idea ..i use While loop


            or


            $sql = mysql_query("SELECT DISTINCT id, column, etc FROM them WHERE nr='1' ORDER BY RAND() DESC LIMIT 0,4");
            while ($items = mysql_fetch_array($sql))
            {

            echo "$items[0]<br/>";

            }

            it will show 4 lines datas

            hope it helps
            Last edited by wapmetal; 17.05.10, 14:47.
            com site: http://vampist.net
            download site: http://wapdloads.net
            fb: http://www.facebook.com/pmplx

            Comment


              #7
              is this for a game?


              ....................................
              http://photomag.lk/
              ....................................

              Comment


                #8
                Ok Wapmetal, lets say we have:

                $a = 1;
                $b = 2;
                $c = 3;
                $d = 4;

                Now I want to print those four variables in a random order by using less code as possible. You got me?
                mysterio.al - programming is a functional art

                Comment


                  #9
                  There would be 24 different ways if you hard coded this (im guessing its for a multiple choice question thing)

                  I would Use Something on the lines of this:

                  PHP Code:
                  $all mysql_fetch_array(mysql_query("SELECT a, b, c, d FROM them WHERE nr='1' "));
                  $rand array_rand($all4);
                  print 
                  $all[$rand[0]]."<br/>";
                  print 
                  $all[$rand[1]]."<br/>";
                  print 
                  $all[$rand[2]]."<br/>";
                  print 
                  $all[$rand[3]]."<br/>"

                  Comment


                    #10
                    Yes, its a multiple answer thing.

                    In your code, there are two problem. The variables are ordered from lowest to highest, and sometimes the same variable with be twice in the list.

                    My mind is bleeding, I try to find a trick but I can't. Any idea?
                    mysterio.al - programming is a functional art

                    Comment


                      #11
                      you mean in every column lets says theres a certain word that u want to be random?

                      can u give me your sql so we can help br0...thanks!
                      com site: http://vampist.net
                      download site: http://wapdloads.net
                      fb: http://www.facebook.com/pmplx

                      Comment


                        #12
                        Originally posted by wapmetal View Post
                        you mean in every column lets says theres a certain word that u want to be random?

                        can u give me your sql so we can help br0...thanks!
                        Yes, that is!

                        And there is no SQL to show, only a table with five columns (nr, a, b, c,d).
                        mysterio.al - programming is a functional art

                        Comment


                          #13
                          So more Like This ?
                          PHP Code:
                          $all mysql_fetch_array(mysql_query("SELECT a, b, c, d FROM them WHERE nr='1' ")); 
                          $randa = (0,3);
                          $randb = (0,3);
                          $randc = (0,3);
                          $randd = (0,3);
                          print 
                          $all[$randa]."<br/>"
                          print 
                          $all[$randb]."<br/>"
                          print 
                          $all[$randc]."<br/>"
                          print 
                          $all[$randd]."<br/>"

                          Comment

                          Working...
                          X