Web Hosting Vodahost    

Home Take The Royal Tour! Order Now Features Prices
Go Back   Web Hosting > VodaHost Web Hosting Support > mySQL & PHP

Notices

mySQL & PHP Discussions, information and help with mySQL and PHP.

Reply
 
LinkBack Thread Tools
  #1  
Old 08-22-2007, 06:35 PM
Private
 
Join Date: May 2006
Posts: 1
Question newbie once again bites off more than he can chew. sql/php

Hello everyone,

I’ve created a sql based search feature and have successfully created the following DB:
Create database users;


And I’ve successfully created the following tables:
insert into users set
title="example",
description="example description example description example description example description",
url="www.mclexa.com",
status="certified",
file="none",
keywords="happy sad glad mad jump high low fast slow"


I then successfully modified the following sql search script to quiry the DB and return the results of the search and paginate the pages using this script:
<?
//This is only displayed if they have submitted the form
if ($searching =="yes")
{
echo "<h2>Results</h2><p>";
//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
$hostname_logon = "localhost" ;
$database_logon = "data base name" ;
$username_logon = "user name" ;
$password_logon = "my password" ;
//open database connection
$connections = mysql_connect($hostname_logon, $username_logon, $password_logon) or die ( "Unabale to connect to the database" );
//select database
mysql_select_db($database_logon) or die ( "Unable to select database!" );

// We preform a bit of filtering
$find = strtoupper($find);
$find = strip_tags($find);
$find = trim ($find);
//__________________________________________________ _______________________________
//This checks to see if there is a page number. If not, it will set it
//to page 1
if (!(isset($pagenum)))
{
$pagenum = 1;
}
//__________________________________________________ _______________________________
//Now we search for our search term, in the field the user specified
$data = mysql_query("SELECT * FROM users WHERE upper($field) LIKE'%$find%'");
$rows = mysql_num_rows($data);
//__________________________________________________ ___________________________________
//This is the number of results displayed per page
$page_rows = 10;
//This tells us the page number of our last page
$last = ceil($rows/$page_rows);
//this makes sure the page number isn't below one, or more than
//our maximum pages
if ($pagenum < 1)
{
$pagenum = 1;
}
elseif ($pagenum > $last)
{
$pagenum = $last;
}
//This sets the range to display in our query
$max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows;
//__________________________________________________ ____________________
//Now we search for our search term, in the field the user specified
$data_p = mysql_query("SELECT * FROM users WHERE upper($field) LIKE'%$find%'");
//This is where you display your query results
while($info = mysql_fetch_array( $data_p ))
{
Print $info['title'];
echo "<br>";
Print $info['status'];
echo "<br>";
Print $info['description'];
echo "<br>";
Print $info['url'];
echo "<br>";
Print "";
echo "<br>";
Print "";
echo "<br>";
Print "";
echo "<br>";
}
// This shows the user what page they are on, and the total
//number of pages
echo " --Page $pagenum of $last-- <p>";
// First we check if we are on page one. If we are then we don't
//need a link to the previous page or the first //page so we do
//nothing. If we aren't then we generate links to the first page,
//and to the previous page.
if ($pagenum == 1)
{
}
else
{
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1'> <<-First</a> ";
echo " ";
$previous = $pagenum-1;
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'> <-Previous</a> ";
}
//just a sp****
echo " ";
//This does the same as above, only checking if we are on the
//last page, and then generating the Next and Last //links
if ($pagenum == $last)
{
}
else {
$next = $pagenum+1;
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'>Next -></a> ";
echo " ";
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last'>Last ->></a> ";
}
}
?>



QUESTIONS:
1. How do you alter the scripts code to provide a text format similar to that illustrated at the link below?
http://www.mclexa.com/examplesearchresult.html

2. How do I connect a link to the variable entered into the “title” field to cause a url jump to the variable url entered into the "url" field?

3. How do you alter the scripts code to provide a link to 1 of 2 possible urls based entirely upon the value stored in the “status” coulumb? Example: if “status” contains the word pending - connect a link to the word “pending” that will cause a jump to http://www.mclexa.com/pending.html.
if “status” contains the word certified - connect a link to the word “certified” that will cause a jump to http://www.mclexa.com/certified.html.

4. When the words "VIEW DOCUMENT" are clicked - how do I cause a pop up window to appear and display the PDF or JPEG document entered and stored in the “file” field?

Forever in your dept!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT +1. The time now is 10:33 PM.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC7
2007 VodaHost.com - All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54