•
•
•
•
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
![]() |
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation:
Rep Power: 8
Solved Threads: 240
first of all, what is shorting a table ? secondly, what are containers ?
Sorry for my ignorance, I didn't understand your question.
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*
*PM asking for help will be ignored*
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation:
Rep Power: 8
Solved Threads: 240
Ok..this might look a lil complicated, but it works.
Hope it helps.
Cheers,
Naveen
php Syntax (Toggle Plain Text)
<?php $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 == "blah1"){ if($order=="asc"){ $order="desc"; } else { $order="asc"; } $value1="?col=blah1&order=$order"; $query="select col1,col2,col3 from table order by $column $order"; } if($column == "blah2"){ if($order=="asc"){ $order="desc"; } else { $order="asc"; } $value2="?col=blah2&order=$order"; $query="select col1,col2,col3 from table order by $column $order"; } if($column == "blah3"){ if($order=="asc"){ $order="desc"; } else { $order="asc"; } $value3="?col=blah3&order=$order"; $query="select col1,col2,col3 from table order by $column $order"; } } else { $value1="?col=blah1&order=asc"; $value2="?col=blah2&order=asc"; $value3="?col=blah3&order=asc"; $query="select col1,col2,col3 from table"; } $result=mysql_query($query); ?> <html> <body> <table border=1> <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> <?php while($row=mysql_fetch_array($result)){ print "<tr><td>".$row['col1']."</td><td>".$row['col2']."</td><td>".$row['col3']."</td></tr>"; } ?> </table> </body> </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*
*PM asking for help will be ignored*
•
•
Join Date: Jan 2008
Posts: 78
Reputation:
Rep Power: 1
Solved Threads: 1
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?
Here is the error i'm getting, which is not making sense to me.
It gives my my column headings as links:
First Name Last Name Phone Number Extension Title Department Fax Number
but then i get:
Can you point me in the right direction?
Thanks.
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>Notice: Undefined variable: query in C:\Inetpub\wwwroot\dbphone_new.php on line 86
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.
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation:
Rep Power: 8
Solved Threads: 240
Try this.
php Syntax (Toggle Plain Text)
<?php // set database server access variables: $host = "localhost"; $user = "root"; $pass = ""; $db = "test"; // 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 orders order by $column $order"; } if($column == "lname"){ if($order=="asc"){ $order="desc"; } else { $order="asc"; } $value2="?col=lname&order=$order"; $query="select * from orders 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 orders order by $column $order"; } if($column == "ext"){ if($order=="asc"){ $order="desc"; } else { $order="asc"; } $value4="?col=ext&order=$order"; $query="select * from orders order by $column $order"; } if($column == "title"){ if($order=="asc"){ $order="desc"; } else { $order="asc"; } $value5="?col=title&order=$order"; $query="select * from orders order by $column $order"; } if($column == "dept"){ if($order=="asc"){ $order="desc"; } else { $order="asc"; } $value6="?col=dept&order=$order"; $query="select * from orders order by $column $order"; } if($column == "fax"){ if($order=="asc"){ $order="desc"; } else { $order="asc"; } $value7="?col=fax&order=$order"; $query="select * from orders 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 orders"; } //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="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_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>
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*
*PM asking for help will be ignored*
•
•
Join Date: Jan 2008
Posts: 78
Reputation:
Rep Power: 1
Solved Threads: 1
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:
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>";
}
?>•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation:
Rep Power: 8
Solved Threads: 240
•
•
•
•
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.
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*
*PM asking for help will be ignored*
![]() |
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- HP Pavilion ze5155 BIOS problem... (Troubleshooting Dead Machines)
- yet another mp3 player problem (Gadgets and Gizmos)
- USB power surge problem (Peripherals)
- HELP ! SEVERE PC PROBLEM...mystery crashing, cna't figure it out after 3 weeks ! (Windows NT / 2000 / XP / 2003)
- PC suddenly died, no post or moitor,only fans. (Troubleshooting Dead Machines)
- Another Boot problem..... (Troubleshooting Dead Machines)
- Horizontal lines across display (Monitors, Displays and Video Cards)
- hi - damn, i just had a major bad problem (Windows NT / 2000 / XP / 2003)
- GAteway Solo 5150 Laptop Problem (Monitors, Displays and Video Cards)
- Presario 700- won't do anything! (Troubleshooting Dead Machines)
Other Threads in the PHP Forum
- Previous Thread: A website which autoupdates from a database?
- Next Thread: PHP not displaying all content.



Linear Mode