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: Aug 2007
Posts: 10
Reputation: ruman_eee is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 1
ruman_eee ruman_eee is offline Offline
Newbie Poster

Help shorting problem

  #1  
Dec 4th, 2007
Hi everyone,

I hope all are fine.

Is there have anyone who knows about shorting a table whose containers are uploaded from the database.

Please help
AddThis Social Bookmark Button
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

  #2  
Dec 4th, 2007
first of all, what is shorting a table ? secondly, what are containers ?
Sorry for my ignorance, I didn't understand your question.
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: Aug 2007
Posts: 10
Reputation: ruman_eee is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 1
ruman_eee ruman_eee is offline Offline
Newbie Poster

Help Re: shorting problem

  #3  
Dec 4th, 2007
thank you for responding.

Firstly,
there have a table of column:
<table><tr >
<th> ID</th>
<th> Name</th>
<th> Title</th>
<th>Option</th>
</tr></table>
this table data are uploaded from database.

I need to sort them.

Just like in phpmyadmin table data shorting method.
Reply With Quote  
Join Date: Jul 2006
Posts: 191
Reputation: vssp is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 5
vssp vssp is offline Offline
Junior Poster

Re: shorting problem

  #4  
Dec 4th, 2007
When click the id pass the value url sort=id
and change the query dynamically
Thanks
VSSP
Reply With Quote  
Join Date: Aug 2007
Posts: 10
Reputation: ruman_eee is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 1
ruman_eee ruman_eee is offline Offline
Newbie Poster

Re: shorting problem

  #5  
Dec 4th, 2007
thanks a lot
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

  #6  
Dec 4th, 2007
Ok..this might look a lil complicated, but it works.
  1. <?php
  2. $conn=mysql_connect($host,$user,$pass);
  3. mysql_select_db($db);
  4. if(isset($_GET['col']) && isset($_GET['order'])){
  5. $column=$_GET['col'];
  6. $order=$_REQUEST['order'];
  7. if($column == "blah1"){
  8. if($order=="asc"){ $order="desc"; } else { $order="asc"; }
  9. $value1="?col=blah1&order=$order";
  10. $query="select col1,col2,col3 from table order by $column $order";
  11. }
  12. if($column == "blah2"){
  13. if($order=="asc"){ $order="desc"; } else { $order="asc"; }
  14. $value2="?col=blah2&order=$order";
  15. $query="select col1,col2,col3 from table order by $column $order";
  16. }
  17. if($column == "blah3"){
  18. if($order=="asc"){ $order="desc"; } else { $order="asc"; }
  19. $value3="?col=blah3&order=$order";
  20. $query="select col1,col2,col3 from table order by $column $order";
  21. }
  22. } else {
  23. $value1="?col=blah1&order=asc";
  24. $value2="?col=blah2&order=asc";
  25. $value3="?col=blah3&order=asc";
  26. $query="select col1,col2,col3 from table";
  27. }
  28. $result=mysql_query($query);
  29. ?>
  30. <html>
  31. <body>
  32. <table border=1>
  33. <th><a href="testtab.php<?php echo $value1 ?>">blah1</th><th><a href="testtab.php<?php echo $value2 ?>">blah2</th><th><a href="testtab.php<?php echo $value3 ?>">blah3</th>
  34. <?php
  35. while($row=mysql_fetch_array($result)){
  36. print "<tr><td>".$row['col1']."</td><td>".$row['col2']."</td><td>".$row['col3']."</td></tr>";
  37. }
  38. ?>
  39. </table>
  40. </body>
  41. </html>

Hope it helps.
Cheers,
Naveen
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

  #7  
May 19th, 2008
nav33n,
Sorry to bug you with this, but I was playing with your script and adding some stuff to suite my script and am having a few problems. Can you check what I've done here to see where i'm going wrong?

<?php 

// set database server access variables: 
$host = "localhost"; 
$user = "xxx"; 
$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 col1,col2,col3,col4,col5,col6,col7 from table order by $column $order";
	}
	if($column == "lname"){
		if($order=="asc"){ $order="desc"; } else {
$order="asc"; }
		$value2="?col=lname&order=$order";
		$query="select col1,col2,col3,col4,col5,col6,col7 from table order by $column $order";
	}
	if($column == "phone_num"){
		if($order=="asc"){ $order="desc"; } else { 
$order="asc"; }
		$value3="?col=phone_num&order=$order";
		$query="select col1,col2,col3,col4,col5,col6,col7 from table order by $column $order";
	}
	if($column == "ext"){
		if($order=="asc"){ $order="desc"; } else {
$order="asc"; }
		$value4="?col=ext&order=$order";
		$query="select col1,col2,col3,col4,col5,col6,col7 from table order by $column $order";
	}
	if($column == "title"){
		if($order=="asc"){ $order="desc"; } else {
$order="asc"; }
		$value5="?col=title&order=$order";
		$query="select col1,col2,col3,col4,col5,col6,col7 from table order by $column $order";
		}
	if($column == "dept"){
		if($order=="asc"){ $order="desc"; } else {
$order="asc"; }
		$value6="?col=dept&order=$order";
		$query="select col1,col2,col3,col4,col5,col6,col7 from table order by $column $order";
		}
	if($column == "fax"){
		if($order=="asc"){ $order="desc"; } else {
$order="asc"; }
		$value7="?col=fax&order=$order";
		$query="select col1,col2,col3,col4,col5,col6,col7 from table 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=$order";
		$value5="?col=title&order=$order";
		$value6="?col=dept&order=$order";
		$value7="?col=fax&order=$order";
		$query="select col1,col2,col3,col4,col5,col6,col7 from table";
		}
}  //I had to add this one or I got an invalid $end error
$result=mysql_query($query);
?>

<html>
<body>
<table border=1>
<th><a href="testtab.php<?php echo $value1 ?>">First Name</th>
<th><a href="testtab.php<?php echo $value2 ?>">Last Name</th>
<th><a href="testtab.php<?php echo $value3 ?>">Phone Number</th>
<th><a href="testtab.php<?php echo $value4 ?>">Extension</th>
<th><a href="testtab.php<?php echo $value5 ?>">Title</th>
<th><a href="testtab.php<?php echo $value6 ?>">Department</th>
<th><a href="testtab.php<?php echo $value7 ?>">Fax Number</th>
<?php
while($row=mysql_fetch_array($result)){
	print "<tr>
	<td>".$row['col1']."</td>
	<td>".$row['col2']."</td>
	<td>".$row['col3']."</td>
	<td>".$row['col4']."</td>
	<td>".$row['col5']."</td>
	<td>".$row['col6']."</td>
	<td>".$row['col7']."</td>
	</tr>";
}
?>

</body>
</html>
Here is the error i'm getting, which is not making sense to me.
Notice: Undefined variable: query in C:\Inetpub\wwwroot\dbphone_new.php on line 86
It gives my my column headings as links:
First Name Last Name Phone Number Extension Title Department Fax Number
but then i get:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\Inetpub\wwwroot\dbphone_new.php on line 100

Can you point me in the right direction?

Thanks.
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

  #8  
May 20th, 2008
Try this.
  1. <?php
  2.  
  3. // set database server access variables:
  4. $host = "localhost";
  5. $user = "root";
  6. $pass = "";
  7. $db = "test";
  8.  
  9. // create query
  10. $conn=mysql_connect($host,$user,$pass);
  11. mysql_select_db($db);
  12. if(isset($_GET['col']) && isset($_GET['order'])) {
  13. $column=$_GET['col'];
  14. $order=$_REQUEST['order'];
  15. if($column == "fname"){
  16. if($order=="asc"){ $order="desc"; } else {
  17. $order="asc"; }
  18. $value1="?col=fname&order=$order";
  19. $query="select * from orders order by $column $order";
  20. }
  21. if($column == "lname"){
  22. if($order=="asc"){ $order="desc"; } else {
  23. $order="asc"; }
  24. $value2="?col=lname&order=$order";
  25. $query="select * from orders order by $column $order";
  26. }
  27. if($column == "phone_num"){
  28. if($order=="asc"){ $order="desc"; } else {
  29. $order="asc"; }
  30. $value3="?col=phone_num&order=$order";
  31. $query="select * from orders order by $column $order";
  32. }
  33. if($column == "ext"){
  34. if($order=="asc"){ $order="desc"; } else {
  35. $order="asc"; }
  36. $value4="?col=ext&order=$order";
  37. $query="select * from orders order by $column $order";
  38. }
  39. if($column == "title"){
  40. if($order=="asc"){ $order="desc"; } else {
  41. $order="asc"; }
  42. $value5="?col=title&order=$order";
  43. $query="select * from orders order by $column $order";
  44. }
  45. if($column == "dept"){
  46. if($order=="asc"){ $order="desc"; } else {
  47. $order="asc"; }
  48. $value6="?col=dept&order=$order";
  49. $query="select * from orders order by $column $order";
  50. }
  51. if($column == "fax"){
  52. if($order=="asc"){ $order="desc"; } else {
  53. $order="asc"; }
  54. $value7="?col=fax&order=$order";
  55. $query="select * from orders order by $column $order";
  56. }
  57. } else {
  58. $value1="?col=fname&order=asc";
  59. $value2="?col=lname&order=asc";
  60. $value3="?col=phone_num&order=asc";
  61. $value4="?col=ext&order=asc";
  62. $value5="?col=title&order=asc";
  63. $value6="?col=dept&order=asc";
  64. $value7="?col=fax&order=asc";
  65. $query="select * from orders";
  66. } //I had to add this one or I got an invalid $end error
  67. $result=mysql_query($query);
  68. ?>
  69.  
  70. <html>
  71. <body>
  72. <table border=1>
  73. <th><a href="sort.php<?php echo $value1 ?>">First Name</th>
  74. <th><a href="sort.php<?php echo $value2 ?>">Last Name</th>
  75. <th><a href="sort.php<?php echo $value3 ?>">Phone Number</th>
  76. <th><a href="sort.php<?php echo $value4 ?>">Extension</th>
  77. <th><a href="sort.php<?php echo $value5 ?>">Title</th>
  78. <th><a href="sort.php<?php echo $value6 ?>">Department</th>
  79. <th><a href="sort.php<?php echo $value7 ?>">Fax Number</th>
  80. <?php
  81. while($row=mysql_fetch_array($result)){
  82. print "<tr>
  83. <td>".$row['col1']."</td>
  84. <td>".$row['col2']."</td>
  85. <td>".$row['col3']."</td>
  86. <td>".$row['col4']."</td>
  87. <td>".$row['col5']."</td>
  88. <td>".$row['col6']."</td>
  89. <td>".$row['col7']."</td>
  90. </tr>";
  91. }
  92. ?>
  93.  
  94. </body>
  95. </html>
Last edited by nav33n : May 20th, 2008 at 5:26 am.
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

  #9  
May 20th, 2008
Now I'm getting this over and over:

Notice: Undefined index: col1 in C:\Inetpub\wwwroot\dbphone_new.php on line 92
Notice: Undefined index: col2 in C:\Inetpub\wwwroot\dbphone_new.php on line 93
Notice: Undefined index: col3 in C:\Inetpub\wwwroot\dbphone_new.php on line 94
Notice: Undefined index: col4 in C:\Inetpub\wwwroot\dbphone_new.php on line 95
Notice: Undefined index: col5 in C:\Inetpub\wwwroot\dbphone_new.php on line 96
Notice: Undefined index: col6 in C:\Inetpub\wwwroot\dbphone_new.php on line 97
Notice: Undefined index: col7 in C:\Inetpub\wwwroot\dbphone_new.php on line 98

for this area:

while($row=mysql_fetch_array($result)){
print "<tr>
<td>".$row['col1']."</td>
<td>".$row['col2']."</td>
<td>".$row['col3']."</td>
<td>".$row['col4']."</td>
<td>".$row['col5']."</td>
<td>".$row['col6']."</td>
<td>".$row['col7']."</td>
</tr>";
}
?>
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

  #10  
May 20th, 2008
Note: Enabling E_NOTICE during development has some benefits. For debugging purposes: NOTICE messages will warn you about possible bugs in your code. For example, use of unassigned values is warned. It is extremely useful to find typos and to save time for debugging. NOTICE messages will warn you about bad style. For example, $arr[item] is better to be written as $arr['item'] since PHP tries to treat "item" as constant. If it is not a constant, PHP assumes it is a string index for the array.
Source : http://nl3.php.net/manual/en/errorfu...rror-reporting

Btw, notices can be ignored. Check if col1, col2,... col7 exists in the table !
Last edited by nav33n : May 20th, 2008 at 10:44 am.
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