The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.

Results 1 to 5 of 5

Thread: [PHP] Array Problems, man I'm dumb lately

  1. #1

    [PHP] Array Problems, man I'm dumb lately

    Hey guys, I have this code

    PHP Code:
    $rowsy mysql_query " SELECT * FROM mainpage WHERE page = 'Random'" );
    $IDS = array ("17");
    while (
    $rows mysql_fetch_assoc($rowsy)) {
    $IDS[] =  $rows['ID'] ;
    }
    $numRows mysql_num_rows($rowsy);
    $real $numRows 1;
    $random rand(0,$rea);
    $final $IDS[$random];
    $query17 mysql_query" SELECT * FROM mainpage WHERE ID = '$final'" ); 
    Which should..
    Find the amount of rows in the table with the page set as 'Random'
    Which it does
    Then it should create an array with those ID's.
    Then it should find the rows again, this time subtracting one to correspond to the array
    Then, find a random number between zero and the amount of rows, which I'm not really sure if it does
    Then it should take that number and use it to pull an ID out of the array, which I'm pretty sure it doesn't do.
    Finally, it should pull use that ID to pull out the info from the array.

    Not working.

    Any brilliant ideas, I'm getting frustrated here.

    Yeah, I realize this is a really stupid way to do this, but it's about my only option with the way I set up the table like a moron.

  2. #2
    Just a little helpful info.

    $random always outputs 0.
    So the problem is somewhere around there I guess

  3. #3
    Quote Originally Posted by xxviii
    Hey guys, I have this code

    PHP Code:
    $rowsy mysql_query " SELECT * FROM mainpage WHERE page = 'Random'" );
    $IDS = array ("17");
    while (
    $rows mysql_fetch_assoc($rowsy)) {
    $IDS[] = $rows['ID'] ;
    }
    $numRows mysql_num_rows($rowsy);
    $real $numRows 1;
    $random rand(0,$rea);
    $final $IDS[$random];
    $query17 mysql_query" SELECT * FROM mainpage WHERE ID = '$final'" ); 
    just check ur code variables, especially the line

    PHP Code:
     $random rand(0,$rea); 
    try it as

    PHP Code:
     $random rand(0,$real); 
    edit:-
    if you want it to be random...

    in your sql code

    Code:
     ORDER BY rand() LIMIT 1

  4. #4
    Quote Originally Posted by binime
    if you want it to be random...

    in your sql code

    Code:
     ORDER BY rand() LIMIT 1

    yeah... let mysql do the job... much easier

  5. #5
    Whoa thanks guys, didn't see anyone responded. I got it to work my stupid cracked up way, I had no idea I could put rand() inside an sql query like that. Very cool, thanks a lot

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012