Jump to content

john-formby

Members
  • Posts

    91
  • Joined

  • Last visited

Everything posted by john-formby

  1. I do this on a couple of sites. Here is the code I use: $path = 'existingfolder/existingfolder/newfolder/'; mkdir($path,0777); chmod($path,0777);
  2. Can you use something like: <?php $sql = mysql_query("SELECT field FROM tblblah"); $row = mysql_fetch_array($sql); echo substr($row['field'],0,400); ?>
  3. Something like: $page = $_GET['p']; if($page == 'home'){ <a href="index.php?p=home"><img src="home1.gif" alt="home" /></a> } else { <a href="index.php?p=home"><img src="home.gif" alt="home" /></a> } if($page == 'contact'){ <a href="index.php?p=contact"><img src="contact1.gif" alt="home" /></a> } else { <a href="index.php?p=contact"><img src="contact.gif" alt="home" /></a> } if($page == 'links'){ <a href="index.php?p=links"><img src="links1.gif" alt="home" /></a> } else { <a href="index.php?p=links"><img src="links.gif" alt="home" /></a> }
  4. Like this: <?php if(isset($_POST['action'])) { $action = $_POST['action']; $name = $_POST['name']; echo "<h1> Hello $name </h1>"; if ($action == "b1") echo "you just clicked button 1"; if ($action == "b2") echo "you just clicked button 2"; } echo ' <form method="post" action= "testpage.php"> Name : <input type="text" name="name" size="30" value="" maxlength="60"/><br /><br /> <input type="submit" value="b1" name="action" /> <input type="submit" value="b2" name="action" /><br /><br /> </form>'; ?>
  5. If you are not storing lastname in a session, you could add a query like: $sql = mysql_query("SELECT MM_lastname FROM tblusers WHERE MM_Username = '$username'"); $row = mysql_fetch_array($sql); echo $row['MM_lastname'];
  6. Are you are storing the lastname in a session? If you are, you can add: $lastname = $_SESSION['MM_lastname']; below: $username = $_SESSION['MM_Username']; Then if you want to echo it out, you can use: <?php echo $username.' '.$lastname; ?>
  7. I am making the following assumptions: 1. All users must be logged in to make alterations 2. The updates are done through forms 3. User ID is stored in a session Based on this, here is how I would do it: 1. New db table to store transactions with following fields: - transID (unique ID number) - userID (obtained from session) - transtype (determined by the form modified) - transdatetime (timestamp) 2. When a user modifies a form, e.g. their profile, we need to have a hidden field for the transaction type, e.g. <input type="hidden" name="transtype" value="profile" />. 3. When posting the change, an Insert query (in addition to the query that updates) is done to the transaction table which assigns a unique transID grabs the userID from session, and the transtype from POST and timestamps NOW() e.g. $userID = $_SESSION['userID']; $transtype = $_POST['transtype']; $sql = mysql_query("INSERT INTO tbltrans (transID, userID, transtype, transdatetime) VALUES ('', '$userID', '$transtype', NOW()); This is just a very brief overview. If you need more details let me know and I will be happy to expand.
  8. This one is nice: http://linux.softpedia.com/get/Text-Editing-Processing/Markup/eArea-11980.shtml
  9. <?php echo '$username'; ?> should be: <?php echo $username; ?> by adding ' ' you are making it a text string
  10. This is what I would do: 1. Have a form script that uploads an image and creates a thumbnail and resized large image. Store the image names in a database table 2. Have a page that queries the database and displays all the thumbnail images. These would be hyperlinked images that load a large version of the image in a new page. 3. Have a page to display the large version of the image. You can add an extra level of complexity by adding pagination to display a few thumbnails per page. Hope this helps
  11. I am guessing that you want to store this value in the database? The way I would do it (there may be better ways) is to have 2 fields, the first ID field is used to generate the autonumber (type = integer). Then the second field is used to create the new ID (type = varchar). Have a look at the following example: testpage.php <?php $dbHost = "localhost"; $dbUser = "blah"; $dbPass = "blah"; $dbname = "blah"; $db = mysql_connect($dbHost,$dbUser,$dbPass); mysql_select_db($dbname,$db); if(isset($_POST['submit'])) { $urname = $_POST['urname']; $sql = mysql_query("INSERT INTO tbltest (IDnum, IDmain, urname) VALUES ('', '0', '$urname')"); $lastid = mysql_insert_id(); $IDmain = 'abc_'.$lastid; $sql2 = "UPDATE tbltest SET IDmain='$IDmain' WHERE IDnum = '$lastid"; $result = mysql_query($sql2); } echo '<form name="test" action="testpage.php" method="post"> <input type="text" name="urname" /> <input type="submit" name="submit" value="submit" /> </form>'; ?> Hope this helps
  12. Hi, I have a script that I use for uploading photos to my site that does exactly what you want. It resizes correctly (width & height) and creates 2 files (big & small). You can specify the size of the file and the location to save. Have a look and let me know if you have any problem. <?php include('common/dbconnect.php'); if(isset($_POST['submit'])) { //rename file storage variable for convenience $img = $_FILES['uploadfile']; //get the type of the file //note that the type can be determined by the MIME type, but this is prone to error and can be fooled. //This way, even if the user is uploading an executable, if it is named .jpg, it can never be executed //the type is found by taking the substring of the name after the last '.', strrpos finds the last instance of a character in a string $type = substr($img['name'], strrpos($img['name'], '.') + 1); //ensure the type is gif or jpg, and that the size is less than 512kB (expressed in bytes) if(($type == "gif" || $type == "jpg") && $img['size'] < 512000) { //get the current timestamp $time = time(); //create the names for the two files //first, get the name of the file, using a similar method to that getting the type earlier $name = substr($img['name'], 0, strrpos($img['name'], '.')); //then it's just a matter of putting the pieces together $fullsizeName = $name.'_'.$time.'.'.$type; $thumbName = $name.'_'.$time.'_thumb.'.$type; //create a php image object from the uploaded file if($type == "gif") $imgObj = imagecreatefromgif($img['tmp_name']); else $imgObj = imagecreatefromjpeg($img['tmp_name']); //get the width and height of the image $width = imageSX($imgObj); $height = imageSY($imgObj); //resize both width and height if width > 600 if($width > 600) { $height = $height * (600 / $width); $width = 600; } //get the thumb width and height: if($height * 1.5 < $width) { //if so, we limit by width $thumbWidth = 150; $thumbHeight = $height * (150 / $width); } else { //otherwise, we limit by height $thumbHeight = 100; $thumbWidth = $width * (100 / $height); } //create the new image objects $newImage = imagecreatetruecolor($width, $height); $newThumb = imagecreatetruecolor($thumbWidth, $thumbHeight); //copy the old image objects to the new ones, given their new dimensions //see further documentation at php.net/imagecopyresampled imagecopyresampled($newImage, $imgObj, 0, 0, 0, 0, $width, $height, imageSX($imgObj), imageSY($imgObj)); imagecopyresampled($newThumb, $imgObj, 0, 0, 0, 0, $thumbWidth, $thumbHeight, imageSX($imgObj), imageSY($imgObj)); //move the images to their destinations if($type == "gif") { imagegif($newImage, 'images/photo/'.$fullsizeName); imagegif($newThumb, 'images/photo/'.$thumbName); } else { imagejpeg($newImage, 'images/photo/'.$fullsizeName); imagejpeg($newThumb, 'images/photo/'.$thumbName); } //destroy the image objects to save space on the server imagedestroy($imgObj); imagedestroy($newImage); imagedestroy($newThumb); //insert data into the database - ID (autonumber), mysql_query("INSERT INTO tblgallery VALUES ('', '".$fullsizeName."', '".$thumbName."');"); } else echo "The input is not acceptable"; } echo '<form name="uploadimage" action="upload.php" method="post"> <input class="input6" type="file" name="uploadfile" /> <input type="submit" name="submit" value="submit" /> </form>'; ?>
  13. Is there a submit button that you have to press to view the image or is this done dynamically? Can you post some code or give a link?
  14. It is a bit dangerous to allow people to have access directly to the database. If people need to add / edit / delete data you should create a simple admin section.
  15. I have had another go at the pagination and have managed to get it to display just 10 records (which I want per page).  The problem is that I know there are more than 10 results for the query but am unable to see any page numbers.  Please can someone have a look at my code and tell me where I am going wrong.  I have highlighted where I have inserted the pagination code. [code]<?php // Connect to the database. include "dblinks.inc"; // Create the search function: function searchForm() {   // Re-usable form     // variable setup for the form.     echo '<div id="maincol"><h1>Search</h1>';   $searchwords = (isset($_GET['words']) ? htmlspecialchars(stripslashes($_REQUEST['words'])) : '');   $normal = (($_GET['mode'] == 'normal') ? ' selected="selected"' : '' );   $boolean = (($_GET['mode'] == 'boolean') ? ' selected="selected"' : '' );     echo '<form method="get" action="'.$_SERVER['PHP_SELF'].'">';   echo '<input type="hidden" name="cmd" value="search" />';   echo 'Search for: <input type="text" name="words" value="'.$searchwords.'" /> ';   echo 'Mode: ';   echo '<select name="mode">';   echo '<option value="normal"'.$normal.'>Normal</option>';   echo '<option value="boolean"'.$boolean.'>Boolean</option>';   echo '</select> ';   echo '<input type="submit" value="Search" />';   echo '</form>'; } // Create the navigation switch $cmd = (isset($_GET['cmd']) ? $_GET['cmd'] : ''); // ************** Pagination Start **************** $num_per_page=10; $num_pages=ceil($num/$num_per_page); $pages=Array(); FOR ($i=0;$i<$num_pages;$i++) IF ($mode == normal) { $pages[]="<a href=\"?cmd=search&words=searchstring&mode=normal=".$i."\">[".($i+1)."] </a>"; } ELSE { $pages[]="<a href=\"?cmd=search&words=searchstring&mode=boolean=".$i."\">[".($i+1)."] </a>"; } $pages=implode("&nbsp;",$pages); #Here's your string with the page links, output where ever if ($start<0) $start=0; $x=($start*$num_per_page); $y=$num_per_page; // ************** Pagination End **************** switch($cmd) {   default:     searchForm();   break;       case "search":     searchForm();     echo '<h3>Search Results:</h3>';         $searchstring = mysql_escape_string($_GET['words']);     switch($_GET['mode'])     {       case "normal":         $sql = "SELECT link_id, link_text, url, description, keywords, time_added, new_window,                MATCH(link_text, description, keywords)                AGAINST ('$searchstring') AS score FROM links                WHERE MATCH(link_text, description, keywords)                AGAINST ('$searchstring') ORDER BY score DESC LIMIT {$x},{$y}";       break;             case "boolean":         $sql = "SELECT link_id, link_text, url, description, keywords, time_added, new_window,               MATCH(link_text, description, keywords)                AGAINST ('$searchstring' IN BOOLEAN MODE) AS score FROM links                WHERE MATCH(link_text, description, keywords)                AGAINST ('$searchstring' IN BOOLEAN MODE) ORDER BY score DESC LIMIT {$x},{$y}";       break;     }          // echo $sql;         $result = mysql_query($sql) or die (mysql_error()); // ************** Pagination Start **************** $num=mysql_num_rows($result); // ************** Pagination End ****************     while($row = mysql_fetch_object($result))     {       echo '<hr /><br />'; if ($row->new_window == 1) { echo '<b class="linkhead"><a href="'.$row->url.'"target=\"_blank\">'.stripslashes(htmlspecialchars($row->link_text)).'</a></b>'; } else { echo '<b class="linkhead"><a href="'.$row->url.'">'.stripslashes(htmlspecialchars($row->link_text)).'</a></b>'; }       echo '<br />'.stripslashes(htmlspecialchars($row->description)).'<br />'; if ($row->new_window == 1) { echo '<a href="'.$row->url.'"target=\"_blank\">'.stripslashes(htmlspecialchars($row->url)).'</a><br /><br />'; } else { echo '<a href="'.$row->url.'">'.stripslashes(htmlspecialchars($row->url)).'</a><br /><br />'; }     }   break; } echo '<hr /><br />'; // ************** Pagination Start **************** echo $pages; // ************** Pagination End **************** echo '</div>'; ?>[/code] Thanks, John
  16. Hi again, I have been using the Full-Text Search tutorial ound on this site and now have it working exactly as I require except for one thing; I need to add pagination to the results.  I have tried a couple of methods but am unable to make it work.  Please could someone help me with this, I am really struggling.  I have seen this question posted on other forums yet the poster has never received a definitive answer. Here is the search code I am using: [code]<?php // Conect to the database. include "dblinks.inc"; // Create the search function: function searchForm() {   // Re-usable form     // variable setup for the form.     echo '<div id="maincol"><h1>Search</h1>';   $searchwords = (isset($_GET['words']) ? htmlspecialchars(stripslashes($_REQUEST['words'])) : '');   $normal = (($_GET['mode'] == 'normal') ? ' selected="selected"' : '' );   $boolean = (($_GET['mode'] == 'boolean') ? ' selected="selected"' : '' );     echo '<form method="get" action="'.$_SERVER['PHP_SELF'].'">';   echo '<input type="hidden" name="cmd" value="search" />';   echo 'Search for: <input type="text" name="words" value="'.$searchwords.'" /> ';   echo 'Mode: ';   echo '<select name="mode">';   echo '<option value="normal"'.$normal.'>Normal</option>';   echo '<option value="boolean"'.$boolean.'>Boolean</option>';   echo '</select> ';   echo '<input type="submit" value="Search" />';   echo '</form>'; } // Create the navigation switch $cmd = (isset($_GET['cmd']) ? $_GET['cmd'] : ''); switch($cmd) {   default:     searchForm();   break;       case "search":     searchForm();     echo '<h3>Search Results:</h3>';         $searchstring = mysql_escape_string($_GET['words']);     switch($_GET['mode'])     {       case "normal":         $sql = "SELECT link_id, link_text, url, description, keywords, time_added, new_window,                MATCH(link_text, description, keywords)                AGAINST ('$searchstring') AS score FROM links                WHERE MATCH(link_text, description, keywords)                AGAINST ('$searchstring') ORDER BY score DESC";       break;             case "boolean":         $sql = "SELECT link_id, link_text, url, description, keywords, time_added, new_window,               MATCH(link_text, description, keywords)                AGAINST ('$searchstring' IN BOOLEAN MODE) AS score FROM links                WHERE MATCH(link_text, description, keywords)                AGAINST ('$searchstring' IN BOOLEAN MODE) ORDER BY score DESC";       break;     }          // echo $sql;         $result = mysql_query($sql) or die (mysql_error());         while($row = mysql_fetch_object($result))     {       echo '<hr /><br />'; if ($row->new_window == 1) { echo '<b class="linkhead"><a href="'.$row->url.'"target=\"_blank\">'.stripslashes(htmlspecialchars($row->link_text)).'</a></b>'; } else { echo '<b class="linkhead"><a href="'.$row->url.'">'.stripslashes(htmlspecialchars($row->link_text)).'</a></b>'; }       echo '<br />'.stripslashes(htmlspecialchars($row->description)).'<br />'; if ($row->new_window == 1) { echo '<a href="'.$row->url.'"target=\"_blank\">'.stripslashes(htmlspecialchars($row->url)).'</a><br /><br />'; } else { echo '<a href="'.$row->url.'">'.stripslashes(htmlspecialchars($row->url)).'</a><br /><br />'; }     }   break; } echo '<hr /><br /></div>'; ?>[/code] Thanks, John
  17. Thanks, I knew it had to be something simple, I just couldn't find it.  You are a legend ;D John
  18. Thanks, but it still isn't working.  When I hover over a link the following shows up in the status bar: http://www.google.co.uk/ target=/ It is definately the right value because I use load links on standard pages using it and it works fine. Any ideas? Thanks
  19. Hi, Thanks for your reply.  That was one of the first things I tried but it still didn't work?  I have no idea how to make this work. John
  20. Hi, I have followed the tutorial in the tutorials section - MySQL Full-Text Search With PHP and have modified it to fit in with my page layout.  The problem is that the search results are links to other sites and some of them need to open in a new window.  In my table I have the field new_window which has two values, 0 = open in existing window, 1 = open in new window.  I have tried adding an IF statement to the code to get the value of new_window and either open it in a new window or the existing one.  Unfortunately I am unable to get it to work. Could someone please have a look at my code and tell me where I am going wrong. [code]<?php include("common/header1.php"); ?> </head> <body> <? include("common/header2.php"); ?> <?php // Conect to the database. include "dblinks.inc"; // Create the search function: function searchForm() {   // Re-usable form     // variable setup for the form.     echo '<div id="maincol"><h1>Search</h1>';   $searchwords = (isset($_GET['words']) ? htmlspecialchars(stripslashes($_REQUEST['words'])) : '');   $normal = (($_GET['mode'] == 'normal') ? ' selected="selected"' : '' );   $boolean = (($_GET['mode'] == 'boolean') ? ' selected="selected"' : '' );     echo '<form method="get" action="'.$_SERVER['PHP_SELF'].'">';   echo '<input type="hidden" name="cmd" value="search" />';   echo 'Search for: <input type="text" name="words" value="'.$searchwords.'" /> ';   echo 'Mode: ';   echo '<select name="mode">';   echo '<option value="normal"'.$normal.'>Normal</option>';   echo '<option value="boolean"'.$boolean.'>Boolean</option>';   echo '</select> ';   echo '<input type="submit" value="Search" />';   echo '</form>'; } // Create the navigation switch $cmd = (isset($_GET['cmd']) ? $_GET['cmd'] : ''); switch($cmd) {   default:     searchForm();     break;       case "search":     searchForm();     echo '<h3>Search Results:</h3>';         $searchstring = mysql_escape_string($_GET['words']);     switch($_GET['mode'])     {       case "normal":         $sql = "SELECT link_id, link_text, url, description, keywords, time_added, new_window,                MATCH(link_text, description, keywords)                AGAINST ('$searchstring') AS score FROM links                WHERE MATCH(link_text, description, keywords)                AGAINST ('$searchstring') ORDER BY score DESC";       break;             case "boolean":         $sql = "SELECT link_id, link_text, url, description, keywords, time_added, new_window,               MATCH(link_text, description, keywords)                AGAINST ('$searchstring' IN BOOLEAN MODE) AS score FROM links                WHERE MATCH(link_text, description, keywords)                AGAINST ('$searchstring' IN BOOLEAN MODE) ORDER BY score DESC";       break;     }          // echo $sql;         $result = mysql_query($sql) or die (mysql_error());         while($row = mysql_fetch_object($result))     {       echo '<hr /><br />'; if ($row['new_window'] == 1) { echo '<b class="linkhead"><a href="'.$row->url.' target=\"_blank\">'.stripslashes(htmlspecialchars($row->link_text)).'</a></b>'; } else { echo '<b class="linkhead"><a href="'.$row->url.'">'.stripslashes(htmlspecialchars($row->link_text)).'</a></b>'; }       echo ' &nbsp; - &nbsp; Relevance: '.number_format($row->score, 1).'<br />';       echo stripslashes(htmlspecialchars($row->description)).'<br />';       echo '<a href="'.$row->url.'">'.$row->url.'</a>';     }   break; } echo '<hr /><br /></div>'; ?> <? include("common/rightcol.php"); include("common/navigation.php"); include("common/footer.php"); ?>[/code] The bit of code that is supposed to load the link in an existing / new window is below: [code]if ($row['new_window'] == 1) { echo '<b class="linkhead"><a href="'.$row->url.' target=\"_blank\">'.stripslashes(htmlspecialchars($row->link_text)).'</a></b>'; } else { echo '<b class="linkhead"><a href="'.$row->url.'">'.stripslashes(htmlspecialchars($row->link_text)).'</a></b>'; } [/code] Thanks, John
  21. EDIT: It has taken me all day, but I have sorted it :D Thanks
  22. At the moment I have a CSS menu in the form of an unordered list which links to all the pages I want to display.  I have a link database which holds all of the data.  The table for the database is as follows: [code]CREATE TABLE `links` (   `link_id` int(11) NOT NULL auto_increment,   `category_code` varchar(10) NOT NULL default '0',   `link_text` varchar(254) NOT NULL default '',   `url` varchar(254) NOT NULL default '',   `description` text NOT NULL,   `keywords` text NOT NULL,   `time_added` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,   `new_window` tinyint(4) NOT NULL default '0',   PRIMARY KEY  (`link_id`) ) ENGINE=MyISAM;[/code] I have created a page for every menu option which contains the following: [code]<?php include("common/header1.php"); ?> </head> <body onload="initialiseMenu();"> <? include("common/header2.php"); ?>                <div id="maincol"><h1>Graphics - Advice Forums</h1> <?php include "dblinks.inc"; $pageSize = 5; $pageNumber = isset($_REQUEST['page']) ? intval($_REQUEST['page']) : 1; $query="SELECT * FROM links WHERE category_code = 321 ORDER BY link_text ASC LIMIT ".(($page-1) * $pageSize).','.$pageSize; $result=mysql_query($query); while ($row = mysql_fetch_assoc($result)) { $link_text=$row['link_text']; $description=$row['description']; $url=$row['url']; $popup = ($row['new_window'] == 1); $newdes = stripslashes($description); if($popup) {   $link = '<a href="'.$url.'" onclick="window.open(this.href);return false">'; } else {   $link = '<a href="'.$url.'" >'; } echo "<hr /><br />".$link."<b>$link_text</b></a><br>$newdes<br/>".$link."$url</a><br /><br />"; } echo "<hr /><br />"; $numberOfRecords = mysql_result(mysql_query('SELECT count(*) FROM links WHERE category_code=321'),0,0); for($i = 0; $i < $numberOfRecords; $i += $pageSize) {   $page = 1 + floor($i/$pageSize);   echo '<a href="'.$_SERVER['PHP_SELF'].'?page='.$page.'"> [ '.$page.' ] </a>'; } mysql_close(); ?> <br /><br /> </div> <? include("common/rightcol.php"); include("common/navigation.php"); include("common/footer.php"); ?>[/code] The problem is that when I want to update something it takes me ages.  I was wondering if there is some way that I can send the navigation links to one page which will display the data I require based on the category_id?  It would also have to be able to create the title for the page.  Something like 'Links - Web Design Tutorials' I don't want to automatically create the menu as I am happy with it the way it is, I just want to be able to automatically create the results. Here is an extract from the menu: [code]<li><a href="#">Links</a>      <ul>      <li><a href="#">Web Design</a>      <ul>      <li><a href="../lwdtutorials.php?page=1">Tutorials</a></li>      <li><a href="../lwdadviceforums.php?page=1">Advice Forums</a></li>      <li><a href="../lwdcodearchives.php?page=1">Code Archives</a></li>                 <li><a href="#">Languages</a>      <ul>      <li><a href="../lwdasp.php?page=1">ASP</a></li>      <li><a href="../lwdcgi.php?page=1">CGI</a></li>      <li><a href="../lwdcss.php?page=1">CSS</a></li>      <li><a href="../lwdhtml.php?page=1">HTML</a></li>      <li><a href="../lwdjavascript.php?page=1">JavaScript</a></li>      <li><a href="../lwdjsp.php?page=1">JSP</a></li>      <li><a href="../lwdphp.php?page=1">PHP</a></li>                 </ul>                 </li>[/code] I had a go at creating the table (which can be seen below) and altering the code but I always get errors.  Please can someone help me with this. [code]CREATE TABLE `category` (   `category_code` varchar(10) NOT NULL default '0',   `parent_category` varchar(10) default NULL,   `description` varchar(40) NOT NULL default '',   PRIMARY KEY  (`category_code`) ) ENGINE=MyISAM[/code] For example I made LINKS the parent category with a value with a category_code of 3, left parent_category as NULL and description as Links I gave Web Design Tutorials a category code of 300, parent_category of 3 and description of Web Design Tutorials. I had a go at changing the navigation menu to link to one page (linkspage.php) and assigning the category_code (linkspage.php?category_id=300)  The linkspage code was a modification of the code that was displayed on every page.  Unfortunately it did not work and I ended up with about 50 errors, none of which I could understand. I don't know if anyone will be able to understand my ramblings, so please ask questions if you don't know what I am talking about. Thanks, John
  23. Hi, I have a search script running on my website but it does not support boolean operators.  I am finding that the results I am getting are very limited and many are being ignored as the words are not next to each other in the keyword row. I have tried to follow a couple of tutorials I found on the net but have been unsuccessful in implementing them.  What I want is to be able to search through the keywords row in my database using boolean operators and display the results as my current search does, but in order of relevance. I would really appreciate some help with this as I am not having any success. Here is my search form: [code]<form name="search" method="post" action="srch.php"> <input class="form3" type="text" name="find" maxlength="255" /> <input style="vertical-align: top;" class="submit" type="submit" name="search" value="Go" /> <input type="hidden" name="searching" value="yes" /> </form>[/code] Here is my search processing / results page [code]<? //This is only displayed if they have submitted the form if ($searching =="yes") { //If they did not enter a search term we give them an error if ($find == "") { echo "<p>You forgot to enter a search term"; exit; } // Otherwise we connect to our Database mysql_connect("localhost", "USER", "PASS") or die(mysql_error()); mysql_select_db("pagelinks") or die(mysql_error()); // We preform a bit of filtering $find = strtoupper($find); $find = strip_tags($find); $find = trim ($find); //Now we search for our search term, in the field the user specified $data = mysql_query("SELECT * FROM links WHERE keywords LIKE '%$find%'"); $num_per_page=10; $num=mysql_num_rows($data); $num_pages=ceil($num/$num_per_page); $pages=Array(); for ($i=0;$i<$num_pages;$i++) $pages[]="<a href=\"?searching=yes&find=$find&start=".$i."\">[".($i+1)."] </a>"; $pages=implode("&nbsp;",$pages); #Here's your string with the page links, output where ever if ($start<0) $start=0; $x=($start*$num_per_page); $y=$num_per_page; $query="SELECT * FROM links WHERE keywords LIKE '%{$find}%' LIMIT {$x},{$y}"; $data = mysql_query($query); //And we display the results while($result = mysql_fetch_array( $data )) { echo "<hr /><br />"; if ($result['new_window'] == 1) { echo "<b><a href=\"".$result['url']."\" target=\"_new\">".$result['link_text']."</a></b>"; } else { echo "<b><a href=\"".$result['url']."\">".$result['link_text']."</a></b>"; } echo "<br />"; echo $result['description']; echo "<br />"; if ($result['new_window'] == 1) { echo "<a href=\"".$result['url']."\" target=\"_new\">".$result['url']."</a>"; } else { echo "<a href=\"".$result['url']."\">".$result['url']."</a>"; } echo "<br /><br />"; } echo "<hr /><br />"; //This counts the number or results - and if there wasn't any it gives them a little message explaining that $anymatches=mysql_num_rows($data); if ($anymatches == 0) { echo "Sorry, but we can not find an entry to match your query<br><br>"; } //And we remind them what they searched for echo "<b>Searched For:</b> " .$find; } echo "<br /><br />"; echo $pages; ?>[/code] Thanks, John
  24. Yay, its sorted  ;D  Pages needed to be set up as an array. John
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.