www.webdeveloper.com
Results 1 to 2 of 2

Thread: weighted random array

  1. #1
    Join Date
    Jan 2012
    Posts
    10

    weighted random array

    Trying to set up a bit of php to tap a list from mysql to make a list for multiple weighted random selections (random, but with higher ranked entries being more likely to be picked). Here's an initial at creating a weighted list to randomly select from (Feel free to laugh if it's bad enough),
    Code:
    $query = "SELECT ArticleRefference, SizeClass FROM AdvertiserList WHERE SizeClass>=4 AND BusinessType != '$NoRepeat'";
    $result= mysql_query($query);
    $row= mysql_fetch_array($result);
    while ($row =mysql_fetch_assoc($result)){
    $AdSize = $row['SizeClass'];
    for ($Weight=0; $Weight>$AdSize; $Weight++){
    array_push($BigAds, $row['ArticleRefference']);
    }
    }
    To try and understand the problem, outside the other processing, I set up this code to display the output:
    Code:
    echo "BigAds:<br>";
    for ($AdCount=0; $AdCount<=count($BigAds); $AdCount++){
    echo $BigAds[$AdCount];
    echo "<br>";
    }
    which output this:
    Code:
    BigAds:<br><br>

  2. #2
    Join Date
    Feb 2012
    Location
    youTUBE
    Posts
    234
    An output error will occur when $BigAds is empty.

    It looks as if there is no data matching the crieteria.

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
  •  
HTML5 Development Center



Recent Articles