Why won't work?

Reply

Join Date: Oct 2009
Posts: 47
Reputation: web3 is an unknown quantity at this point 
Solved Threads: 0
web3 web3 is offline Offline
Light Poster

Why won't work?

 
0
  #1
Oct 23rd, 2009
When i put in this code WHERE to='$username' won't work?

  1. <?php
  2. $connect = mysql_connect ("localhost","root","") or die (mysql_error());
  3. mysql_select_db ("login4") or die (mysql_error());
  4. session_start();
  5. $_SESSION['username'];
  6. $username = $_SESSION['username'];
  7. $query = mysql_query("SELECT * FROM pm ORDER BY id DESC");
  8. $message = '' ;
  9. while ($row = mysql_fetch_array($query)){
  10. $id = $row['id'];
  11. $to = $row['to'];
  12. $from = $row['from'];
  13. $title = $row['title'];
  14. $date = $row['date'];
  15. $message .= "<tr><td><a href='viewpm.php?&id=".$id."'>".$title."</a><br /></td><td>".$date."<br /></td></tr>";
  16. }
  17. ?>
  18. <table width="100%">
  19. <tr><td>Title</td><td>Date</td></tr>
  20. <?php
  21. print $message;
  22. ?>
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 230
Reputation: macneato is an unknown quantity at this point 
Solved Threads: 19
macneato's Avatar
macneato macneato is offline Offline
Posting Whiz in Training
 
0
  #2
Oct 23rd, 2009
Are you able to print the array?
If this reply solved your problem, please add to my reputation and don't forget to mark this thread as solved.
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 557
Reputation: network18 is an unknown quantity at this point 
Solved Threads: 64
network18 network18 is offline Offline
Posting Pro
 
0
  #3
Oct 23rd, 2009
It should be this way, thats why -
  1. <?php
  2. $connect = mysql_connect ("localhost","root","") or die (mysql_error());
  3. mysql_select_db ("login4") or die (mysql_error());
  4. session_start();
  5. $_SESSION['username'];
  6. $username = $_SESSION['username'];
  7. $query = mysql_query("SELECT * FROM pm where to='".$username."' ORDER BY id DESC");
  8. $message = '' ;
  9. while ($row = mysql_fetch_array($query)){
  10. $id = $row['id'];
  11. $to = $row['to'];
  12. $from = $row['from'];
  13. $title = $row['title'];
  14. $date = $row['date'];
  15. $message .= "<tr><td><a href='viewpm.php?&id=".$id."'>".$title."</a><br /></td><td>".$date."<br /></td></tr>";
  16. }
  17. ?>
  18. <table width="100%">
  19. <tr><td>Title</td><td>Date</td></tr>
  20. <?php
  21. print $message;
  22. ?>
provided your column name is 'to' in the pm table
"The discipline of writing something down is the first step towards making it happen."

follow me on twitter
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 47
Reputation: web3 is an unknown quantity at this point 
Solved Threads: 0
web3 web3 is offline Offline
Light Poster
 
0
  #4
Oct 23rd, 2009
@macneato
i can print array without where to='".$username."'
@network18
code didn't work
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 878
Reputation: pritaeas will become famous soon enough pritaeas will become famous soon enough 
Solved Threads: 141
Sponsor
pritaeas's Avatar
pritaeas pritaeas is offline Offline
Practically a Posting Shark
 
0
  #5
Oct 23rd, 2009
TO is a reserved word, put backticks around it: `to`
"If it is NOT source, it is NOT software."
-- NASA
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 47
Reputation: web3 is an unknown quantity at this point 
Solved Threads: 0
web3 web3 is offline Offline
Light Poster
 
0
  #6
Oct 23rd, 2009
Thanks, pritaeas!
Reply With Quote Quick reply to this message  
Reply

Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC