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
https://forums.phpfreaks.com/topic/114348-solved-order-by/
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
https://forums.phpfreaks.com/topic/114348-solved-order-by/#findComment-588021
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
https://forums.phpfreaks.com/topic/114348-solved-order-by/#findComment-588031
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
https://forums.phpfreaks.com/topic/114348-solved-order-by/#findComment-588038
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
https://forums.phpfreaks.com/topic/114348-solved-order-by/#findComment-588053
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.