0

I have a database that has two fields: current, and previous.

Here is the code:

                            <?
$username="*****";
$password="*****";
$database="******";

mysql_connect(localhost,$username,$password) or die("Unable to connect to server");
mysql_select_db($database) or die( "Unable to select database");

$query='SELECT * FROM tasks WHERE current=1 OR previous=1';
$result=mysql_query($query);
$num=mysql_num_rows($result); 

mysql_close();

?>

It then output it and manipulate it like this:

<div class="tasklist">
    <div class="currentProject">
    Current Project:
    </div>
<?
$i=0;

while ($i < $num) {
$title=mysql_result($result,$i,"Title");
$link=mysql_result($result,$i,"Weblink");
$description=mysql_result($result,$i,"Description");
$id=mysql_result($result,$i,"ID");
$howto=mysql_result($result,$i,"howto");
$blogpost=mysql_result($result,$i,"blogpost");
$done=mysql_result($result,$i,"done");
$current=mysql_result($result,$i,"current");
$previous=mysql_result($result,$i,"previous");

if ( $current == 1 ) {
    $current = "current";
} else {
    $current = "";
}

if ( $previous == 1 ) {
    $previous = "previous";
} else {
    $previous = "";
}

?>

    <div class="<? echo $done ?> task <? echo $id ?>" id="<? echo $current.$previous ?>">
            <div class="titleWrapper">
                <div class="title">
                    <a class="article"  href="<? echo $link ?>"><? echo $title ?></a>
                </div>
            </div>
    </div><BR>

<?
$i++;
}

echo "</div>";


?>

The problem is that since previous comes before current in the database, it outputs previous and then current.

Question:

How do I make sure to output current first, and then previous?

3
  • That's incredible ancient way to query a database. Where did you get that rarity? And your database structure is under questioning too Commented Sep 25, 2010 at 19:57
  • To be honest, I ripped it off of another coders work. I am not the best with PHP, and I asked a buddy to code that for me.... and mind being more helpful other than "database structure is under questioning too"? Commented Sep 25, 2010 at 20:13
  • If you can provide a better way to do it, I would really appreciate it. Commented Sep 25, 2010 at 20:16

2 Answers 2

1

Instead of outputting both directly, store them until you actually have both, and then output both in the correct order.

Sign up to request clarification or add additional context in comments.

Comments

0

Just append this to your query order by previous.

It must work as long as current task registry has previous=0 and previous task registry has previous=1.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.