| | |
dont display clicked links ?
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Jul 2007
Posts: 2
Reputation:
Solved Threads: 0
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:
any help would be great thanks.
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)
<?PHP session_start(); // is the one accessing this page logged in or not? if (!isset($_SESSION['logged_in']) || $_SESSION['logged_in'] !== true) { // not logged in, move to login page header('Location: login.php'); exit; } echo "Welcome "; echo $_SESSION['user_logged']; // Connect to the database include("sql.php"); $check_user_info = mysql_query("select * from tracking"); $check = mysql_query("select * from members where members.username ='toasty'"); $x = mysql_fetch_array($check); $vised = explode(",",$x['adid']); foreach($vised as $vised1) { $check_array = array_search($vised1, $vised); if (!$check_array) { while ($row = mysql_fetch_row($check_user_info)) { if ($vised1 != $row[1]) { echo "<BR><a href='testframe1.php?id=$row[1]'>$row[3]</a>"; } } } } ?>
any help would be great thanks.
php Syntax (Toggle Plain Text)
foreach($vised as $vised1) { $check_array = array_search($vised1, $vised); 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)
foreach($vised as $check_array=>$vised1) { 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)
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)
$links = mysql_query("select * from tracking"); // is this all the links (the larger set)? $clicked = mysql_query("select * from members where members.username ='toasty'"); // is this the links already clicked (smaller set) ? $x = mysql_fetch_array($clicked); // id's of clicked links? $vised = explode(",",$x['adid']); while ($row = mysql_fetch_row($links)) { $check_array = array_search($row[1], $vised); // check if column 1 exists in the visited links if ($check_array !== false) { echo "<BR><a href='testframe1.php?id=$row[1]'>$row[3]</a>"; } }
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!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
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!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
![]() |
Similar Threads
- Horizontal display of data on Repeater control in asp.net (ASP.NET)
- Pagination - not displaying results properly, please help! (PHP)
- array struct display?? (C)
- Dont want to display command window (Java)
Other Threads in the PHP Forum
- Previous Thread: php & paypal intagration
- Next Thread: dot prn encoding problem
| Thread Tools | Search this Thread |
advanced apache api array beginner binary broken cakephp check checkbox class cms code cookies cron curl database date datepart display dropdownlist dynamic echo email eregi error execution file files folder form forms function functions google head href htaccess html if...loop image include includingmysecondfileinthechain insert ip javascript job joomla jquery key library limit link login mail menu mlm multiple mysql oop password paypal pdf pdfdownload php phpvotingscript problem query radio random recursion remote screen script search server sessions smarty sms sorting source space sql startup stored syntax system table traffic tutorial unicode update upload url validator variable video web youtube zend






