MySQL Forums
Forum List  »  PHP

Sorting data with query and displaying on page
Posted by: Matthew Graves
Date: June 30, 2005 04:53PM

I am having a bit of a problem getting my site to increment data once pulled from the DB. As of right now it pulls the correct data, but when I sort it in descending order it will not test correctly in the IF statements I have setup, if I don't sort it the correct IF statement is executed. Below is the code:

$sql = "SELECT * FROM snex_data where spo=$postart";
$rs = mysql_query($sql, $connect);


if (mysql_num_rows($rs) > 0)
{
$sql1 = "SELECT * FROM snex_data where spo=$postart order by svisit DESC LIMIT 1";
$rs1 = mysql_query($sql1,$connect);
$row = mysql_fetch_array($rs1);
echo $row['svisit'];//Temporary to display array data -- Shows correct data

if ($row['svisit'] == '1st Visit') {
$visit = '2nd Visit';
} elseif ($row['svisit'] == '2nd Visit'){
$visit = '3rd Visit';
} elseif ($row['svisit'] == '3rd Visit'){
$visit = '4th Visit';
} elseif ($row['svisit'] == '4th Visit'){
$visit = '5th Visit';
} elseif ($row['svisit'] == "5th Visit'){
$visit = '6th Visit';
} elseif ($row['svisit'] == "6th Visit'){
$visit = '7th Visit';
} elseif ($row['svisit'] == "7th Visit'){
$visit = '8th Visit';
} elseif ($row['svisit'] == "8th Visit'){
$visit = '9th Visit';
} elseif ($row['svisit'] == "9th Visit'){
$visit = '10th Visit';
} elseif ($row['svisit'] == "10th Visit'){
$visit = '11th Visit';
} else
{
$visit = '1st Visit';
echo 'else';
$po = $postart;
}
}


I know this is a long way of doing it but it works when I dont sort the data, but it always pulls the visit of the first ticket it encounters. I need to find the highest visit and then add 1 to that. The ECHO statements are just there to tell me where it is in the statements. Basically it will select 1 PO number and then needs to get the latest visit and then take that latest visit and proceed to the next one. Even if I take out the LIMIT statement in the query it still will not work. Any help with this would be great.

Thanks,

Matt

Options: ReplyQuote


Subject
Written By
Posted
Sorting data with query and displaying on page
June 30, 2005 04:53PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.