twittoris Posted October 7, 2009 Share Posted October 7, 2009 Ok I have hit a wall. Im trying to create a simple page that allows me to enter 3 types of data website, description, adsensecode(javascript) Currently the webpage takes the input from the forms and saves it in a text file (url.txt) like this: www.reonomy.com|Real Estate| www.reonomy.com|Real Estate| Which is created by my php script here: <?PHP $filename = 'url.txt'; $fp = fopen($filename, "a"); //print $a $write = fputs($fp, $_POST["website"]); $write = fputs($fp, "|"); $write = fputs($fp, $_POST["description"]); $write = fputs($fp, "|\n"); fclose($fp); header('Location: http://URL/listcreator.php'); ?> I then have listcreator.php do this: <?php ob_start(); $sortby = $_SERVER['QUERY_STRING']; $set = ''; if ($sortby == '') { $header = 'First Name'; $sortby = 'firstname'; $set = 'y'; } if ($sortby == 'surname') { $header = 'Surname'; $set = 'y'; } if ($sortby == 'city') { $header = 'City'; $set = 'y'; } if ($sortby == 'points') { $header = 'Points'; $set = 'y'; } if ($sortby == 'car') { $header = 'Car'; $set = 'y'; } if ($sortby == 'colour') { $header = 'Colour'; $set = 'y'; } if ($sortby == 'age') { $header = 'Age'; $set = 'y'; } if ($set == '') { echo 'The variable at the end of the web address did not match one required by the code. Please check the web address for errors.'; exit; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <title>Adsense Free Web Directory</title> <style type="text/css"> <!-- body, th, td, p, small { font-family:'Times New Roman',Times,serif; font-size:100%; color:#444; } small {font-size:90%;} table { border:1px solid #ccf; padding:3px; } td, th { background-color:#def; padding:7px 20px 7px 20px; } th {background-color:#dee; color:#677;} h1 {font-size:120%; color:#558;} h1 .sortby {color:#855;} --> </style> </head> <body> <?php echo '<h1>Flat File Database Sorted By <span class="sortby">'.$header.'</span></h1> <p>To sort the columns click on the headers.</p> <table summary="List of demo fields"> <tr> <th><a href="?">Website</a></th> <th><a href="?surname">Description</a></th> <th><a href="?city">Ad</a></th> </tr>'; $fp = fopen('cookies.txt','r'); if (!$fp) {echo 'ERROR: Unable to open file.</table></body></html>'; exit;} while (!feof($fp)) { $line = fgets($fp,2048); //use 2048 if very long lines $row++; list ($website, $description, $adsense)= split ('\|', $line); //$points, $car, $colour, $age) if ($sortby == 'website') $sortkey = strtolower($website); if ($sortby == 'description') $sortkey = strtolower($description); if ($sortby == 'adsense') $sortkey = strtolower($adsense); //if ($sortby == 'points') $sortkey = $points; //if ($sortby == 'car') $sortkey = strtolower($car); //if ($sortby == 'colour') $sortkey = strtolower($colour); //if ($sortby == 'age') $sortkey = $age; $col[$row] = array($sortkey, $website, $description, $adsense); //, $points, $car, $colour, $age); } fclose($fp); sort($col); reset ($col); $arrays = count($col) - 1; $loop = -1; while ($loop < $arrays) { $loop++; echo ' <tr> <td>'.$col[$loop][1].'</td> <td>'.$col[$loop][2].'</td> <td>'.$col[$loop][3].'</td> </tr>'; } echo ' </table> <p><small>1 December 2004 · Last updated: '.date('j F Y', getlastmod()); $HtmlCode= ob_get_contents(); ob_end_flush(); $fh=fopen('cookies.html','w'); fwrite($fh,$HtmlCode); fclose($fh); ?> </body> </html> I am having trouble with two things: 1. Making the table that is created display the urls as links 2. I want to make a variable equal a google adsense ad and place it in the 3rd colum of my table Can someone give me some direction? Thanks Link to comment https://forums.phpfreaks.com/topic/176892-solved-php-and-adsensejavascript-in-a-table-generated-from-a-text/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.