random number

Discussion in 'PHP' started by irdogg, Aug 23, 2011.

  1. #1
    hi everybody :eek: im trying to cycle through a list of numbers in the database is it possible

    if(!$_GET['categ_id']) $_GET['categ_id'] = 1;
    Code (markup):
    to example:

    if(!$_GET['categ_id']) $_GET['categ_id'] = 1,2,3;
    Code (markup):
    1 2 and three being the category id's thanx in advance
     
    irdogg, Aug 23, 2011 IP
  2. Technoslab

    Technoslab Peon

    Messages:
    46
    Likes Received:
    3
    Best Answers:
    3
    Trophy Points:
    0
    #2
    You can define an array to hold multiple values like 1,2,3 or store it as csv in a string.
     
    Technoslab, Aug 23, 2011 IP
  3. irdogg

    irdogg Well-Known Member

    Messages:
    358
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    135
    #3
    so the example should work?
     
    irdogg, Aug 23, 2011 IP
  4. Technoslab

    Technoslab Peon

    Messages:
    46
    Likes Received:
    3
    Best Answers:
    3
    Trophy Points:
    0
    #4
    Be a bit more specific on what you intend to do with the list of numbers.
     
    Technoslab, Aug 23, 2011 IP
  5. irdogg

    irdogg Well-Known Member

    Messages:
    358
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    135
    #5
    the numbers are categories in the script i need it to cycle through the categories aka the numbers to make my page look fresh
     
    irdogg, Aug 23, 2011 IP
  6. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #6
    1) You can't assign a value to a $_GET.

    2) $category = isset($_GET['categ_id']) ? $_GET['categ_id'] : rand(1, 3);

    If $_GET['categ_id'] is being sent to the file you'll use that. Otherwise you'll get a random number from 1 to 3.
     
    Rukbat, Aug 24, 2011 IP
  7. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #7
    mysql_query("SELECT * FROM categ_id ORDER BY RAND() LIMIT 10"); // for 10 results
     
    MyVodaFone, Aug 24, 2011 IP
  8. irdogg

    irdogg Well-Known Member

    Messages:
    358
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    135
    #8
    only one category can be called at a time this will work?
     
    irdogg, Aug 24, 2011 IP
  9. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #9
    mysql_query("SELECT * FROM categ_id ORDER BY RAND() LIMIT 1"); // for 1 random category
     
    MyVodaFone, Aug 24, 2011 IP
  10. irdogg

    irdogg Well-Known Member

    Messages:
    358
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    135
    #10
    hmm i tried them all and nothing changes just load like normal
     
    irdogg, Aug 24, 2011 IP