Results 1 to 5 of 5

Thread: recordsets to display in random order

  1. #1
    Join Date
    Dec 2007
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default recordsets to display in random order

    Hello,

    I am trying to figure out how to have my recordsets in Dreamweaver CS3 (created with Mysql and php) display in a random order each time the page is requested. Basically I do not want the same companies information to show up first each time. Below is a portion of the code I am using. i have tried ORDER BY RAND () and some other things but continue to get an error each time.

    Is there someone that can show me what to do and where to place it?

    Thank you so much!

    <?php
    if (!function_exists("GetSQLValueString")) {
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
    {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

    $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

    switch ($theType) {
    case "text":
    $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
    break;
    case "long":
    case "int":
    $theValue = ($theValue != "") ? intval($theValue) : "NULL";
    break;
    case "double":
    $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
    break;
    case "date":
    $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
    break;
    case "defined":
    $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
    break;
    }
    return $theValue;
    }
    }

    $maxRows_rsvendors = 10;
    $pageNum_rsvendors = 0;
    if (isset($_GET['pageNum_rsvendors'])) {
    $pageNum_rsvendors = $_GET['pageNum_rsvendors'];
    }
    $startRow_rsvendors = $pageNum_rsvendors * $maxRows_rsvendors;

    $varzip_rsvendors = "1";
    if (isset($_POST['Zip'])) {
    $varzip_rsvendors = $_POST['Zip'];
    }
    $varcategory_rsvendors = "1";
    if (isset($_POST['Category'])) {
    $varcategory_rsvendors = $_POST['Category'];
    }
    mysql_select_db($database_connect, $connect);
    $query_rsvendors = sprintf("SELECT commercial.Company_Name, commercial.Street, commercial.City, commercial.`State`, commercial.Zip, commercial.Phone, commercial.Website, commercial.Email, commercial.Category, commercial.Photo, commercial.About, commercial.Contact, commercial.General_liability_insurance, commercial.GLI_amount, commercial.Workers_comp, commercial.WC_amount, commercial.Accept_credit_cards, commercial.Years_in_business FROM commercial WHERE commercial.Zip=%s AND commercial.Category=%s ", GetSQLValueString($varzip_rsvendors, "text"),GetSQLValueString($varcategory_rsvendors, "text"));
    $query_limit_rsvendors = sprintf("%s LIMIT %d, %d", $query_rsvendors, $startRow_rsvendors, $maxRows_rsvendors);
    $rsvendors = mysql_query($query_limit_rsvendors, $connect) or die(mysql_error());
    $row_rsvendors = mysql_fetch_assoc($rsvendors);

    if (isset($_GET['totalRows_rsvendors'])) {
    $totalRows_rsvendors = $_GET['totalRows_rsvendors'];
    } else {
    $all_rsvendors = mysql_query($query_rsvendors);
    $totalRows_rsvendors = mysql_num_rows($all_rsvendors);
    }
    $totalPages_rsvendors = ceil($totalRows_rsvendors/$maxRows_rsvendors)-1;
    ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
    <title>Untitled Document</title>
    <link href="vol.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">
    <!--
    function MM_preloadImages() { //v3.0
    var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
    }
    //-->
    </script>

  2. #2
    Join Date
    Jan 2008
    Posts
    32
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default

    Dear god that query string is ugly!
    Yours looks like this:
    PHP Code:
    SELECT commercial.Company_Namecommercial.Streetcommercial.Citycommercial.`State`, commercial.Zipcommercial.Phonecommercial.Websitecommercial.Emailcommercial.Categorycommercial.Photocommercial.Aboutcommercial.Contactcommercial.General_liability_insurancecommercial.GLI_amountcommercial.Workers_compcommercial.WC_amountcommercial.Accept_credit_cardscommercial.Years_in_business FROM commercial WHERE commercial.Zip=%AND commercial.Category=%
    When it could look like this:
    PHP Code:
    SELECT FROM commercial WHERE ((`Zip`='%s')AND(`Category`='%s')) 
    Please change it.

    You can randomize arrays using shuffle($array). Read up more about PHP functions and data types by using PHP.net's built-in documentation by going to http://www.php.net/FUNCTION.

  3. #3
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    Dear God you are a wee bit pushy.

    Please change that.
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

  4. #4
    Join Date
    Dec 2007
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks for the tips Leafy, I did get it figured out.

    Did not intend to be pushy Blizzard, just asking for help and am new at this.

  5. #5
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    Quote Originally Posted by Perspective View Post
    Did not intend to be pushy Blizzard, just asking for help and am new at this.
    That wasn't aimed at you
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

Bookmarks

Posting Permissions

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