Jump to content

[SOLVED] Ordering a mysql command in a while loop


richrock

Recommended Posts

Help - I think ???

 

I've written a while loop to search through clients to find who has been assigned 'Paddles' (auctions), but can't seem to order those results.  The tables are quite complex (for me) as they reference different bits of information in order to filter it down.

 

Here's what I've done:

 

        // Now the in-house bidders
        $getPADBID = "SELECT * FROM jos_bid_paddles";
        $resPADBID = mysql_query($getPADBID) or die(mysql_errno() . mysql_error());
        while ($row_paddles = mysql_fetch_array($resPADBID)) {

            $padusrID = $row_paddles['user_id'];
            $padass = $row_paddles['pad_num'];

            echo $padusrID."<br />";

	$getPaddle_data = "SELECT jos_bid_auctions.id as a_id, title, jos_comprofiler.user_id as uid, jos_bid_paddles.assignee as assign, ";
        $getPaddle_data .= "jos_comprofiler.firstname as pfname, jos_comprofiler.lastname as plname, ";
        $getPaddle_data .= "jos_bid_paddles.pad_num as ppadnum, jos_bid_paddles.assignee as assignee ";
        $getPaddle_data .= "FROM jos_bid_auctions ";
        $getPaddle_data .= "LEFT JOIN jos_comprofiler ON jos_comprofiler.user_id ";
        $getPaddle_data .= "LEFT JOIN jos_bid_paddles ON jos_bid_paddles.user_id ";
        $getPaddle_data .= "LEFT JOIN jos_bid_categories ON jos_bid_categories.id ";
        $getPaddle_data .= "WHERE jos_comprofiler.user_id = ".$padusrID." ";
        $getPaddle_data .= "AND jos_comprofiler.user_id = jos_bid_paddles.user_id ";
        $getPaddle_data .= "AND jos_bid_categories.active = 1 ";
        $getPaddle_data .= "ORDER BY jos_comprofiler.firstname ASC";
        $resPaddleData = mysql_query($getPaddle_data) or die(mysql_errno() . mysql_error());
        //echo $getPaddle_data."<br /><br />"; // Testing SQL

        $row_paddles = mysql_fetch_array($resPaddleData);

            $user = $row_paddles['uid'];
            $pfname = $row_paddles['pfname'];
            $plname = $row_paddles['plname'];
            $ppadnum = $row_paddles['ppadnum'];
            $passignee = $row_paddles['assignee'];

            echo $pfname.", ".$plname." - ".$ppadnum."<br />";

            if ($ppadnum == NULL) {
                // Nada to da data...
            } else {
                echo "<tr><td width='200'>";
                echo $pfname." ".$plname;
                echo "</td><td width='65'>";
                echo $ppadnum;
                echo "</td><td width='200'>";
                echo $passignee;
                echo "</td></tr>";
            }

        }

 

As you can see, I tried to add the "$getPaddle_data .= "ORDER BY jos_comprofiler.firstname ASC";" - this doesn't work because this query is repeated for each client in the list extracted from a table that only has client id's.  Any ideas?

 

For those interested:

 

I joined the same tables required to the SQL outside the while loop, like thus:

 

$getPADBID = "SELECT * FROM jos_bid_paddles LEFT JOIN jos_comprofiler ON jos_comprofiler.user_id WHERE jos_comprofiler.user_id = jos_bid_paddles.user_id ORDER BY jos_comprofiler.firstname ASC";

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.