•
•
•
•
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,759 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: 1080 | Replies: 30
![]() |
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation:
Rep Power: 8
Solved Threads: 240
Well, notices can be ignored. But if you want to get rid of notices without disabling it, initialize every variable before using it. Here is an example.
This will generate the notice undefined index since $arr['1'] doesn't have any value and isn't initialized where as, this wouldn't generate any notice.
php Syntax (Toggle Plain Text)
<?php error_reporting(E_ALL); $arr = array(); echo $arr['1']; ?>
php Syntax (Toggle Plain Text)
<?php error_reporting(E_ALL); $arr = array(); $arr['1']=""; echo $arr['1']; ?>
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
•
•
Join Date: Jan 2008
Posts: 78
Reputation:
Rep Power: 1
Solved Threads: 1
I was able to get my data by using $row instead of col, would the sorting work better using row instead of column? Heres the code I've used so far:
I may be way off but if my $value was based on $row instead of ?col would I get a better result? My while statement worked with the $row statement. The hyperlink looks ok to me.
<?php
$host = "localhost";
$user = "root";
$pass = "xx";
$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 orders 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);
?>
<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>
</table>
</body>
</html>
<?php
while($row = mysql_fetch_row($result)) {
echo "<table cellpadding=10 border=0>";
echo "<tr>";
echo "<td><font size='2'>".$row[1]."</td>";
echo "<td><font size='2'>".$row[2]."</td>";
echo "<td><font size='2'>".$row[3]."</td>";
echo "<td><font size='2'>".$row[4]."</td>";
echo "<td><font size='2'>".$row[5]."</td>";
echo "<td><font size='2'>".$row[6]."</td>";
echo "<td><font size='2'>".$row[7]."</td>";
echo "</tr>";
}
echo "</table>";
?>I may be way off but if my $value was based on $row instead of ?col would I get a better result? My while statement worked with the $row statement. The hyperlink looks ok to me.
Last edited by rickarro : May 20th, 2008 at 12:13 pm.
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation:
Rep Power: 8
Solved Threads: 240
umm.. col is the column name which you want to sort.. Is it working for you ?
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
What have you named this script ? Is it called sort.php ?
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
Then the links should be dbphone_new.php in all these cases.
•
•
•
•
<th><a href="sort.php<?php echo $value1 ?>">First Name</th>
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