User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 455,985 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,801 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 1078 | Replies: 30
Reply
Join Date: Jan 2008
Posts: 78
Reputation: rickarro is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
rickarro rickarro is offline Offline
Junior Poster in Training

Re: shorting problem

  #21  
May 20th, 2008
Originally Posted by nav33n View Post
Then the links should be dbphone_new.php in all these cases.

AArggg, wish i'd seen that..... that got the first column sorting fine, click once, sorts dsc, click again, sorts asc. The rest of the columns get the page error as before.
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 240
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: shorting problem

  #22  
May 20th, 2008
Did you change all the column links ?
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Jan 2008
Posts: 78
Reputation: rickarro is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
rickarro rickarro is offline Offline
Junior Poster in Training

Re: shorting problem

  #23  
May 20th, 2008
Yes I changed them all. I've got a couple of different configurations going, one of them i went back to part of the original script you provided and it is working a little better. What it does now is if I go to sort.php (http://localhost/sort.php) i get column headings and data. If I click on "First Name" (colomn 1) it sorts perfectly like it is supposed to (which gives a page ref of: http://localhost/sort.php?col=fname&order=desc). If I click on any other column heading, result: page error. If I go back to the original page (http://localhost/sort.php), I can then click any column heading and it will work, but only that column heading, all others will error if clicked.
Does this make sense?
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 240
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: shorting problem

  #24  
May 20th, 2008
Can you post your latest code ?
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Jan 2008
Posts: 78
Reputation: rickarro is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
rickarro rickarro is offline Offline
Junior Poster in Training

Re: shorting problem

  #25  
May 20th, 2008
Here is my latest code. Its named sort.php just to keep things simple. Data displays good but the sorting errors after the first column is selected.

[code]
<html>
<body>

<?php
// set database server access variables:
$host = "localhost";
$user = "root";
$pass = "xxx";
$db = "phonebook";
// create query
$conn=mysql_connect($host,$user,$pass);
mysql_select_db($db);
if(isset($_GET['col']) && isset($_GET['order'])) {
$column=$_GET['col'];
$order=$_REQUEST['order'];
if($column == "fname"){
if($order=="asc"){ $order="desc"; } else {
$order="asc"; }
$value1="?col=fname&order=$order";
$query="select * from people order by $column $order";
}
if($column == "lname"){
if($order=="asc"){ $order="desc"; } else {
$order="asc"; }
$value2="?col=lname&order=$order";
$query="select * from people order by $column $order";
}
if($column == "phone_num"){
if($order=="asc"){ $order="desc"; } else {
$order="asc"; }
$value3="?col=phone_num&order=$order";
$query="select * from people order by $column $order";
}
if($column == "ext"){
if($order=="asc"){ $order="desc"; } else {
$order="asc"; }
$value4="?col=ext&order=$order";
$query="select * from people order by $column $order";
}
if($column == "title"){
if($order=="asc"){ $order="desc"; } else {
$order="asc"; }
$value5="?col=title&order=$order";
$query="select * from people order by $column $order";
}
if($column == "dept"){
if($order=="asc"){ $order="desc"; } else {
$order="asc"; }
$value6="?col=dept&order=$order";
$query="select * from people order by $column $order";
}
if($column == "fax"){
if($order=="asc"){ $order="desc"; } else {
$order="asc"; }
$value7="?col=fax&order=$order";
$query="select * from people order by $column $order";
}

}else {

$value1="?col=fname&order=asc";
$value2="?col=lname&order=asc";
$value3="?col=phone_num&order=asc";
$value4="?col=ext&order=asc";
$value5="?col=title&order=asc";
$value6="?col=dept&order=asc";
$value7="?col=fax&order=asc";
$query="SELECT * FROM people";
}
$result=mysql_query($query);

?>

<table border=1>
<th><a href="sort.php<?php echo $value1 ?>">First Name</th>
<th><a href="sort.php<?php echo $value2 ?>">Last Name</th>
<th><a href="sort.php<?php echo $value3 ?>">Phone Number</th>
<th><a href="sort.php<?php echo $value4 ?>">Extension</th>
<th><a href="sort.php<?php echo $value5 ?>">Title</th>
<th><a href="sort.php<?php echo $value6 ?>">Department</th>
<th><a href="sort.php<?php echo $value7 ?>">Fax Number</th>

<?php
while($row=mysql_fetch_row($result)){
print "<tr>
<td>".$row[1]."</td>
<td>".$row[2]."</td>
<td>".$row[3]."</td>
<td>".$row[4]."</td>
<td>".$row[5]."</td>
<td>".$row[6]."</td>
<td>".$row[7]."</td>
</tr>";
}

?>
</table>
</body>
</html>
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 240
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: shorting problem

  #26  
May 21st, 2008
Looks ok to me. I don't understand. What error are you getting ? What do you mean by sorting errors ?
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Jan 2008
Posts: 78
Reputation: rickarro is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
rickarro rickarro is offline Offline
Junior Poster in Training

Re: shorting problem

  #27  
May 21st, 2008
Ok, I'll try to explain. When I open sort.php I see headings and listed data. I click on the first column heading (First Name) and it sorts by first name asc. I click on the First Name heading again, it sorts by first name dsc, working perfectly for that column. If I then click on the second column heading (Last Name), I get a "page cannot be found" page.

If I close the page and start over, opening sort.php again, and instead of clicking on the first column, I click on the second column first (Last name), it sorts correctly until I click on a different column heading, then I get the "page cannot be found" page.

When sort.php first opens, the heading links display on mouse over:

http://sort.php?col=fname&order=asc
http://sort.php?col=lname&order=asc
http://sort.php?col=phone_number&order=asc
etc...........

But once a column heading is clicked to sort, all other headings say on mouse over:


http://localhost/sort.php<br/><b>Notice</b>:Undefined variable:value2 in <b>C:/Inetpub/wwwroot/sort.php</b>on line<b>76</b><br/>

So I guess in a nutshell, once a column heading is clicked, all the other column headings will show an Undefined variable, they will not sort and error out.

Does this make sense? Sorry if it doesn't. Could it be that the page is not refreshing back to original page once a column is clicked? Just guessing here.
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 240
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: shorting problem

  #28  
May 21st, 2008
huh.. Thats strange.. Disable notices and try again.. The page is refreshed since its reloaded again. Strange.
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Jan 2008
Posts: 78
Reputation: rickarro is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
rickarro rickarro is offline Offline
Junior Poster in Training

Re: shorting problem

  #29  
May 21st, 2008
Ahhhhh, disabling notices did the trick, no more errors. The only thing its doing now (which I can live with) is once I click on a different heading, it takes two clicks to start the sort. It looks like the first click gives the focus, the second click does the sort. It does this anytime I change the column. Its deffinately something I can live with but I did notice thats what it was doing.

Thanks for all your hard work, you are patient and dedicated!!!!!
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 240
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: shorting problem

  #30  
May 21st, 2008
Heh.. so, notices were the culprit here ? eh ? But, this code isn't really "brilliant". But it works. You can tune it a little more!
Umm.. It shouldn't take 2 clicks to sort. Because, first time, no records will be sorted. When you click on a column, it will see if $order is set. If its set to asc, it will change it to desc and vice versa. So, it has to do its work anyway. Strange ! But I am glad its atleast working !
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 9:24 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC