943,983 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 1237
  • PHP RSS
Jul 12th, 2007
0

dont display clicked links ?

Expand Post »
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:

php Syntax (Toggle Plain Text)
  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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
toasty525 is offline Offline
10 posts
since Jul 2007
Jul 13th, 2007
0

Re: dont display clicked links ?

php Syntax (Toggle Plain Text)
  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:

php Syntax (Toggle Plain Text)
  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:

PHP Syntax (Toggle Plain Text)
  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:

php Syntax (Toggle Plain Text)
  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
Moderator
Reputation Points: 457
Solved Threads: 101
Nearly a Posting Virtuoso
digital-ether is offline Offline
1,250 posts
since Sep 2005
Jul 13th, 2007
0

Re: dont display clicked links ?

Thank you so much digital-ether that done the trick perfectly
Reputation Points: 10
Solved Threads: 0
Newbie Poster
toasty525 is offline Offline
10 posts
since Jul 2007
Jul 13th, 2007
0

Re: dont display clicked links ?

Click to Expand / Collapse  Quote originally posted by toasty525 ...
Thank you so much digital-ether that done the trick perfectly
Moderator
Reputation Points: 457
Solved Threads: 101
Nearly a Posting Virtuoso
digital-ether is offline Offline
1,250 posts
since Sep 2005

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: php & paypal intagration
Next Thread in PHP Forum Timeline: dot prn encoding problem





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC