dont display clicked links ?

Thread Solved

Join Date: Jul 2007
Posts: 2
Reputation: toasty525 is an unknown quantity at this point 
Solved Threads: 0
toasty525 toasty525 is offline Offline
Newbie Poster

dont display clicked links ?

 
0
  #1
Jul 12th, 2007
Hi

can anyone help me with this ? Im trying to create a page that lets a user click a link and once that link has been clicked the page no longer displays that link for that user, i have all the databases set up to record clicks but i cant seem to get the PHP code to not display the clicked links, The code im using is as follows:

  1. <?PHP
  2. session_start();
  3.  
  4. // is the one accessing this page logged in or not?
  5. if (!isset($_SESSION['logged_in'])
  6. || $_SESSION['logged_in'] !== true) {
  7.  
  8. // not logged in, move to login page
  9. header('Location: login.php');
  10. exit;
  11. }
  12.  
  13. echo "Welcome "; echo $_SESSION['user_logged'];
  14.  
  15. // Connect to the database
  16. include("sql.php");
  17.  
  18. $check_user_info = mysql_query("select * from tracking");
  19. $check = mysql_query("select * from members where members.username ='toasty'");
  20.  
  21. $x = mysql_fetch_array($check);
  22.  
  23. $vised = explode(",",$x['adid']);
  24. foreach($vised as $vised1)
  25. {
  26.  
  27. $check_array = array_search($vised1, $vised);
  28. if (!$check_array)
  29. {
  30. while ($row = mysql_fetch_row($check_user_info))
  31. {
  32. if ($vised1 != $row[1])
  33. {
  34. echo "<BR><a href='testframe1.php?id=$row[1]'>$row[3]</a>";
  35. }
  36. }
  37. }
  38. }
  39.  
  40. ?>

any help would be great thanks.
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 1,075
Reputation: digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice 
Solved Threads: 66
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Veteran Poster

Re: dont display clicked links ?

 
0
  #2
Jul 13th, 2007
  1. foreach($vised as $vised1)
  2. {
  3.  
  4. $check_array = array_search($vised1, $vised);
  5. if (!$check_array)

There is an error (2 actually) in the logic in the part above.

The check $check_array = array_search($vised1, $vised); always checks for a value $vised1 that is always present in $vised, since the foreach() loop goes through each index of $vised, and saves a copy of the value to $vised1.

The part above can be rewritten as:

  1. foreach($vised as $check_array=>$vised1)
  2. {
  3. if (!$check_array)

The other problem I think is that you're thinking $check_array returns true or false? Instead it returns the index. So if you were actually checking if a value existed in an array, you'd use:

  1. if ($check_array !== false)

which will also check for the TYPE to make sure it is the same type on each side of the comparison operator.
Otherwise when an index such as 0 or ' ' exist in an array, those indexes are casted to boolean before the comparison is made, thus you get a false when the index actually exists.

I'm not sure exactly how you're going about this, but it should probably something like:

  1. $links = mysql_query("select * from tracking"); // is this all the links (the larger set)?
  2. $clicked = mysql_query("select * from members where members.username ='toasty'"); // is this the links already clicked (smaller set) ?
  3.  
  4. $x = mysql_fetch_array($clicked); // id's of clicked links?
  5.  
  6. $vised = explode(",",$x['adid']);
  7.  
  8.  
  9. while ($row = mysql_fetch_row($links))
  10. {
  11. $check_array = array_search($row[1], $vised); // check if column 1 exists in the visited links
  12. if ($check_array !== false)
  13. {
  14. echo "<BR><a href='testframe1.php?id=$row[1]'>$row[3]</a>";
  15. }
  16. }


I have the comments in the code on my assumptions. Could you post the db table structures or explain on which holds what for clarification?
Last edited by digital-ether; Jul 13th, 2007 at 7:50 am. Reason: typo
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 2
Reputation: toasty525 is an unknown quantity at this point 
Solved Threads: 0
toasty525 toasty525 is offline Offline
Newbie Poster

Re: dont display clicked links ?

 
0
  #3
Jul 13th, 2007
Thank you so much digital-ether that done the trick perfectly
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 1,075
Reputation: digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice 
Solved Threads: 66
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Veteran Poster

Re: dont display clicked links ?

 
0
  #4
Jul 13th, 2007
Originally Posted by toasty525 View Post
Thank you so much digital-ether that done the trick perfectly
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC