Jump to content

[SOLVED] Order by


PHP Nubsauce

Recommended Posts

Hey all, see if you can figure this one out..

 

 $links33 = @mysql_query("SELECT * FROM ".$mysql_pretext."_customer_payments WHERE customer_id = '$customerid' ORDER BY date ASC");

 

I'm trying to display all customer payments from oldest to newest, and its doing that, but its breaking it up by customer!

 

Example:

 

1-1-08 customer a

2-2-08 customer a

3-3-08 customer a

1-2-08 customer b

2-3-08 customer b

3-4-08 customer b

 

Any help making it look like so:

 

1-1-08 customer a

1-2-08 customer b

2-2-08 customer a

2-3-08 customer b

3-3-08 customer a

3-4-08 customer b

 

 

Please?

 

Nubsauce

Link to comment
Share on other sites

	<?php  $links34 = @mysql_query("SELECT * FROM ".$mysql_pretext."_customers WHERE referrer_id = '$id'");
if (!$links34) {
echo("Error retrieving projects from the database!<br>Error: " . mysql_error());
exit();
}

while ($link = mysql_fetch_array($links34)) {
$customerid = $link["ID"];
$clientcompany = $link["company"];

?>
                        <?php

 $links33 = @mysql_query("SELECT * FROM ".$mysql_pretext."_customer_payments WHERE customer_id = '$customerid' ORDER BY date ASC");
if (!$links33) {
echo("Error retrieving customer payments from the database!<br>Error: " . mysql_error());
exit();
}
?>

Link to comment
Share on other sites

if the format of the date stored in db is "1-1-08" then no surprise you are having problems.

 

Store dates in a DATE type field in ISO date format YYYY-MM-DD. Then you can sort, do date comparisons, select ranges, use Mysql datetime functions.

 

But your format is totally useless. Store dates for function, not appearance. Format on output.

Link to comment
Share on other sites

I figured this one out myself, thanks for the help tho

 

	<?php  $links33 = @mysql_query("SELECT * FROM ".$mysql_pretext."_customer_payments LEFT JOIN ".$mysql_pretext."_customers ON (".$mysql_pretext."_customer_payments.customer_id = ".$mysql_pretext."_customers.ID) WHERE referrer_id = '$id' ORDER BY date ASC");
if (!$links33) {
echo("Error retrieving projects from the database!<br>Error: " . mysql_error());
exit();
}
$rowstotal = mysql_num_rows($links);
?>

Link to comment
Share on other sites

But your format is totally useless. Store dates for function, not appearance. Format on output.

 

First you ask me what my field type is, then you just throw that comment in there afterwards.

 

Thats a big "...."

 

Yes, my field type is date.

 

Thanks,

 

Nubsauce.

 

 

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.