Pass into the title meta-tag a variable from an URL Directory Manager

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I hope that phpers will be not angry if I'm posting that maybe stupid
question.
I have the following script, an URL Directory Manager (PHP4 from Wrox Press).
I'd like to pass the variable "category" into the TITLE META TAG from
php_category when I select the corrispondent category_id into the URL
Directory
Manager, i.e. to display the right category everytime I call it from the
script. As I'm an absolute beginner, I'd like someone could suggestme the most
rapid way to do it whitout rewriting all the code. Thanks for all, Alessandro
xxxxxxxxxxxx Tables of MySQL sample_db xxxxxxxxxxxxxxxxxxxxxxxxxxxx # Table
structure for table 'php_category' CREATE TABLE php_category ( category
varchar(30) NOT NULL, category_id varchar(15) NOT NULL, num_item int(5) NOT
NULL, PRIMARY KEY (category_id) ); # Table structure for table 'php_directory'
CREATE TABLE php_directory ( url_id int(10) NOT NULL auto_increment,
category_id varchar(15) NOT NULL, title varchar(150) NOT NULL, url
varchar(150)
NOT NULL, description text NOT NULL, registerdate date, hit int(5) NOT NULL,
lastaccesstime timestamp(14), password varchar(20) binary, email varchar(100)
NOT NULL, approved char(1) NOT NULL, PRIMARY KEY (url_id), UNIQUE url (url,
category_id) ); xxxxxxxxxxxxxxx php_directory.inc xxxxxxxxxxxxxxxxxxxxxx 
xxxxxxxxxxxxxxxxxx php_directory.php xxxxxxxxxxxxxxxxx "; $MYSQL_ERRNO = '';
$MYSQL_ERROR = ''; function directory_header() { global $new_window_width,
$new_window_height; ?>       alert(\"Error: $msg\");history.go(-1)";
directory_footer(); exit; } function user_message($msg, $url='') {
directory_header(); if(empty($url)) echo "alert(\"$msg\");history.go(-1)";
else
echo "alert(\"$msg\");self.location.href='$url'"; directory_footer(); exit; }
function get_category_info($category_id) { global $default_dbname,
$category_tablename, $root_category_id, $category_id_length, $welcome_message,
$PHP_SELF; global $link_id; if(!$link_id) $link_id =
db_connect($default_dbname); if($category_id == $root_category_id) {
$category_info_array["category"] = "Top"; $category_info_array["num_item"]
= 0;
$query = "SELECT max(category_id), count(*) FROM $category_tablename WHERE
length(category_id) = $category_id_length"; $result = mysql_query($query);
if(!$result) echo sql_error(); $query_data = mysql_fetch_row($result);
$sibling_id = $query_data[0]; $num_child = $query_data[1];
$category_info_array["num_child"] = $num_child; if(!$sibling_id)
$next_category_id = '001'; else { $sibling_length = strlen($sibling_id);
$next_category_id = $sibling_id + 1; for($i = strlen($next_category_id); $i
" .
$query_data[0] .""; $parent_array[$j] = $query_data[0]; $j++; }
$category_info_array["href_fullname"] = implode("->", $parent_href_array);
$category_info_array["fullname"] = implode("->", $parent_array); } return
$category_info_array; } function get_url_info($url_id) { global $link_id,
$default_dbname, $directory_tablename; if(!$link_id) $link_id =
db_connect($default_dbname); $query = "SELECT url_id, category_id, title, url,
description,registerdate, date_format(registerdate, '%M, %e, %Y') as
formatted_registerdate, hit, lastaccesstime, date_format(lastaccesstime, '%M,
%e, %Y %r') as formatted_lastaccesstime, password, email, approved FROM
$directory_tablename WHERE url_id = '$url_id'"; $result = mysql_query($query);
if(!$result) echo sql_error(); return mysql_fetch_array($result); } function
search_form($category_id) { global $root_category_id, $PHP_SELF;
if(!isset($category_id)) $category_id = $root_category_id; ?> 
">   Search:  ">Current Category ">All Categories OR AND   
 
  $category_href_fullname ($num_child_str, $num_item_str)

\n"; else echo "

$category_href_fullname ($num_child_str)

\n"; search_form($category_id); $query = "SELECT category, category_id FROM
$category_tablename WHERE (length(category_id) = $category_depth *
$category_id_length) AND category_id LIKE '$category_id%' ORDER BY category";
$result = mysql_query($query); if(!$result) echo sql_error();
if(mysql_num_rows($result) > 0) { ?> 
 
 \n"; echo "\n"; echo "<\"$PHP_SELF?action=show_list>
category_id=$my_category_id\"> $my_category ($num_child_str,
$num_item_str)\n";
echo "\n"; if(!($i % 2)) echo "\n"; $i++; } if(!($i % 2)) { echo " \n" ; echo
""; } ?> 
 
 $found_str - Keyword(s): $keywords


\n"; if($total_num > 0) echo "
Displaying page $page_num out of $last_page_num

\n"; $query = "SELECT url_id, category_id, title, url, description,
date_format(registerdate, '%M, %e, %Y') as formatted_registerdate, hit,
date_format(lastaccesstime, '%M, %e, %Y %r') as formatted_lastaccesstime, hit
FROM $directory_tablename WHERE $category_str AND approved = 1 $keyword_str
ORDER BY registerdate DESC $limit_str"; $result = mysql_query($query);
if(!$result) echo sql_error(); $i = 1; while($query_data =
mysql_fetch_array($result)) { $url_id = $query_data["url_id"];
$formatted_registerdate = $query_data["formatted_registerdate"];
$formatted_lastaccesstime = $query_data["formatted_lastaccesstime"]; $url =
"http://"; . $query_data["url"]; $title = $query_data["title"]; $description =
$query_data["description"]; $hit = $query_data["hit"]; echo "
<\"$PHP_SELF?action=go_url&url=$url&url_id=$url_id\">". ($i+($cur_page *
$records_per_page)).".$title \n"; echo "
>
> \n"; echo $description; echo "
> \n"; echo "Last Access: $formatted_lastaccesstime
> \n"; echo "Hit(s): " . number_format($hit) . "
> \n"; if($admin) echo "<\"$PHP_SELF?action=delete_url&url_id=$url_id>
> category_id=$category_id&url=$url> title=$title&cur_page=$cur_page\">
[Delete]
> \n"; echo "<\"javascript:open_window('$PHP_SELF?
> action=modify_url_form&url_id=$url_id>
> category_id=$category_id&cur_page=$cur_page');\"> [Modify] \n"; if(!$admin)
> echo "<\"mailto:$dirmaster_email? subject=PHPDirectory]SiteMissing>
> body=url_id:$url_id($url)\"> [Report Broken Link] \n"; echo "

\n"; $i++; } if($search_on) $search_str =
"&search_on=1&search_type=$search_type&keywords=$keywords&search_category=$s
earch_category"; echo "
"; if($page_num > 1) { $prev_page = $cur_page - 1; echo
"<\"$PHP_SELF?action=show_list&category_id=$category_id&cur_page=0$search_st
r\">[Top]"; echo
"<\"$PHP_SELF?action=show_list&category_id=$category_id&cur_page=$prev_page$
search_str\">[Prev] "; } if($page_num [Next] "; echo
"<\"$PHP_SELF?action=show_list&category_id=$category_id&cur_page=$last_page$
search_str\">[Bottom]"; } echo "
"; echo "

<\"$PHP_SELF?action=show_list\">[Directory Home] \n"; if($submittable) echo
"<\"javascript:open_window('$PHP_SELF?action=add_url_form&category_id=$categ
ory_id');\">[Submit a URL]\n"; echo "
"; ?>   "; list_sites('new', $category_id); ?>   

Submit a PHP Site!

">  "> 
 
 Category   
 Title   
 URL   
 Email   
 Password   
 Retype Password   
 Description
 ( Chars Max.)      
     
 
 $max_desc_length) error_message("Description too long! $max_desc_length chars
max!"); $title = addslashes($title); $description = addslashes($description);
$password = crypt($password, '.v'); if(!$link_id) $link_id =
db_connect($default_dbname); $query = "SELECT url FROM $directory_tablename
WHERE url = '$url' AND category_id = '$category_id'"; $result =
mysql_query($query); if(!$result) error_message(sql_error());
if(mysql_num_rows($result) != 0) error_message("$url already exists in the
directory!"); $approved = 0; if($admin) { $query = "UPDATE $category_tablename
SET num_item = num_item + 1 WHERE category_id = '$category_id'"; $result =
mysql_query($query); if(!$result) error_message(sql_error()); $approved = 1; }
$query = "INSERT INTO $directory_tablename VALUES(NULL, '$category_id',
'$title', '$url', '$description', curdate(), 0, NULL, '$password', '$email',
$approved)"; $result = mysql_query($query); if(!$result)
error_message(sql_error()); if($send_mail){ $mail_subject = "PHP Directory>>
Thank your for your listing."; $mail_body = "Thank you for sharing your
resources with us.\n"; $mail_body = "Your contribution will be listed after
review in a day or two.\n\n"; $mail_body .= "Title: $title\n"; $mail_body .=
"URL: $url\n"; $mail_body .= "Description: $description"; mail($email,
$mail_subject, $mail_body, "From: $dirmaster_email\nReply-to:
$dirmaster_email"); } $num_rows = mysql_affected_rows($link_id); if($num_rows
!= 1) error_message(sql_error()); else echo " alert(\"$title($url) has been
successfully submitted!\");
opener.location.href='$PHP_SELF?action=show_list&category_id=$category_id';
self.close(); "; } function modify_url_form() { global $PHP_SELF,
$max_desc_length, $url_id, $category_id, $admin_script, $cur_page;
directory_header(); if(basename($PHP_SELF) == $admin_script) $admin = 1;
$url_info_array = get_url_info($url_id); $category_info_array =
get_category_info($url_info_array["category_id"]); ?> 

Update your PHP site!

    * Submitted on:  
    * Hits:  
    * Last Access:  
">  "> "> 
 
 Category    
 Email   
 Password    
 Title " SIZE="30" MAXLENGTH="150">  
 URL " SIZE="30" MAXLENGTH="150">  
 Description
 ( Chars Max.)      
     
 
 $max_desc_length) error_message("Description too long! $max_desc_length chars
max!"); $url_info_array = get_url_info($url_id); if(!$admin >>
(($url_info_array["password"] != crypt($password, '.v')) ||
($url_info_array["email"] != $email))) error_message("You don't have
permission
to modify this URL!"); $title = addslashes($title); $description =
addslashes($description); if(!$link_id) $link_id =
db_connect($default_dbname);
$query = "UPDATE $directory_tablename SET title='$title', url='$url',
description='$description' WHERE url_id='$url_id'"; $result =
mysql_query($query); if(!$result) error_message(sql_error()); $num_rows =
mysql_affected_rows($link_id); if($num_rows != 1) error_message(sql_error());
else echo "alert(\"$title($url) has been successfully modified!\");
opener.location.href='$PHP_SELF?action=show_list&category_id=$category_id&cu
r_page=$cur_page'; self.close();"; } function go_url() { global
$default_dbname,
$directory_tablename; global $url_id, $url; if(isset($url_id) >>
isset($url)) {
if(!$link_id) $link_id = db_connect($default_dbname); $result =
mysql_query("UPDATE $directory_tablename SET hit = hit + 1 WHERE
url_id=$url_id"); if(!$result) error_message(sql_error()); header("Location:
$url"); exit; } } function list_sites($mode='top', $category_id='') { global
$directory_tablename, $root_category_id, $PHP_SELF, $num_top_sites,
$num_new_sites; if(!$link_id) $link_id = db_connect($default_dbname);
if($mode=='top') { $order_by_str = 'ORDER BY hit DESC'; $limit_str = "LIMIT
$num_top_sites"; } else { $order_by_str = 'ORDER BY registerdate DESC';
$limit_str = "LIMIT $num_new_sites"; } if($category_id == $root_category_id)
$category_str = '1'; else $category_str = "category_id LIKE '$category_id%'";
$query = "SELECT url_id, title, url FROM $directory_tablename WHERE
$category_str AND approved = 1 $order_by_str $limit_str"; $result =
mysql_query($query); if(!$result) echo sql_error(); if(mysql_num_rows($result)
> 0) { if($mode=='top') echo "Top $num_top_sites!
"; else if($mode=='new') echo "New $num_new_sites!
"; } $i = 1; while($query_data = mysql_fetch_array($result)) { $url_id =
$query_data["url_id"]; $url = "http://"; . $query_data["url"]; $title =
$query_data["title"]; echo " -
<\"$PHP_SELF?action=go_url&url=$url&url_id=$url_id\">$i. $title
\n"; $i++; } } ?> xxxxxxxx dir_manager.php xxxxxxxxxxxxxxxxxxx Click on the
level on which you want to add a new category.

"; echo "
>
> \n"; echo
> "<\"javascript:open_window('$PHP_SELF?action=add_category_form&parent=$roo
> t_category_id')\">" . $category_info_array["category"] ." (" .
> $category_info_array["num_child"] . ")"; } else { echo "
> Click on the category you want to edit.
>
> "; echo "
>>
>> \n"; echo
>> "<\"javascript:open_window('$PHP_SELF?action=edit_category_form&category_
>> id=$root_category_id')\">" . $category_info_array["category"] ." (" .
>> $category_info_array["num_child"] . ")"; } echo "
>> \n"; echo "
>>>
>>> \n"; while($query_data = mysql_fetch_array($result)) { $category_id =
>>> $query_data[0]; $category_info_array = get_category_info($category_id);
>>> for($i=0; $i X \n"; if($mode == 'add_category') echo
>>> "<\"javascript:open_window('$PHP_SELF?action=add_category_form&parent=$c
>>> ategory_id')\">" . $category_info_array["category"] ." (" .
>>> $category_info_array["num_child"] . ")"; else echo
>>> "<\"javascript:open_window('$PHP_SELF?action=edit_category_form&category
>>> _id=$category_id')\">" . $category_info_array["category"] ." (" .
>>> $category_info_array["num_child"] . ")"; echo "
>>> \n"; } echo "
>>
>> \n"; echo "
>
> \n"; directory_footer(); } function add_category_form() { global
> $default_dbname, $directory_tablename, $category_tablename, $PHP_SELF;
global
> $link_id, $parent; $category_info_array = get_category_info($parent);
> $category_id = $category_info_array["next_id"]; $category_fullname =
> $category_info_array["fullname"]; directory_header(); ?> 
>
> Adding a New Category: 
>
> ">  "> 
>  
>  Category ID   
>  Category Name   
>     
>  
> alert(\"$category was successfully added!\");
> opener.location.href='$PHP_SELF'; self.close();"; directory_footer(); }
> function edit_category_form() { global $default_dbname,
$directory_tablename,
> $category_tablename, $PHP_SELF; global $link_id, $category_id;
> $category_info_array = get_category_info($category_id); directory_header();
> ?> 
>
> Editing the Category: 
>
> ">  "> 
>  
>  Category ID   
>  Category Name " SIZE="20">  
>  Resources   
>     
>  
> alert(\"$category was successfully updated!\");
> opener.location.href='$PHP_SELF?mode=edit_category'; self.close();";
> directory_footer(); } function delete_category() { global $default_dbname,
> $directory_tablename, $category_tablename, $PHP_SELF; global $link_id,
> $category_id, $mode; if(empty($category_id)) error_message("Empty Category
> ID!"); if(!$link_id) $link_id = db_connect($default_dbname); $query =
"DELETE
> FROM $category_tablename WHERE category_id LIKE '$category_id%'"; $result =
> mysql_query($query); if(!$result) error_message(sql_error()); $del_subs =
> mysql_affected_rows($link_id) - 1; $query = "DELETE FROM
$directory_tablename
> WHERE category_id LIKE '$category_id%'"; $result = mysql_query($query);
> if(!$result) error_message(sql_error()); $del_items =
> mysql_affected_rows($link_id); echo "alert(\"1 category, $del_subs
> subcategories, and $del_items items were deleted!\");
> self.location.href='$PHP_SELF?mode=$mode';"; } function update_db() { global
> $default_dbname, $directory_tablename, $category_tablename, $PHP_SELF;
global
> $link_id, $category_id, $mode; directory_header(); if(!$link_id) $link_id =
> db_connect($default_dbname); $query = "SELECT category, category_id,
num_item
> FROM $category_tablename"; $result = mysql_query($query); if(!$result)
> error_message(sql_error()); $num_revs = 0; while($query_data =
> mysql_fetch_row($result)) { $category = $query_data[0]; $category_id =
> $query_data[1]; $num_item = $query_data[2]; $query = "SELECT count(*) FROM
> $directory_tablename WHERE category_id = '$category_id' AND approved = 1";
> $result2 = mysql_query($query); $query_data2 = mysql_fetch_row($result2);
> $total = $query_data2[0]; if(!$result2) error_message(sql_error());
> if($num_item != $total) { $query = "UPDATE $category_tablename SET
num_item =
> $total WHERE category_id = '$category_id'"; $result2 = mysql_query($query);
> if(!$result2) die(sql_error()); echo "Number of resources in \"$category\"
> mismatch -> revised: $total resources.
> \n"; $num_revs++; } } if(!$num_revs) echo "No inconsistency found.
> \n"; else if($num_revs) echo "$num_revs inconsistency has been corrected.
> \n"; else echo "$num_revs inconsistencies have been corrected.
> \n"; echo "Done.\n"; directory_footer(); } function view_new() { global
> $default_dbname, $directory_tablename, $category_tablename,
> $records_per_page, $PHP_SELF, $link_id; global $cur_page; if(!$link_id)
> $link_id = db_connect($default_dbname); $query = "SELECT count(*) FROM
> $directory_tablename WHERE approved != 1"; $result = mysql_query($query);
> if(!$result) echo error_message(sql_error()); $query_data =
> mysql_fetch_row($result); $total_num = $query_data[0]; if(!$total_num) echo
> error_message("No new listing!"); $limit_str = "LIMIT " . $cur_page *
> $records_per_page . ", $records_per_page"; $query = "SELECT url_id, url,
> title, description, category_id FROM $directory_tablename WHERE approved = 0
> ORDER BY registerdate $limit_str"; $result = mysql_query($query);
> if(!$result) echo error_message(sql_error()); $page_num = $cur_page + 1;
> $total_num_page = floor($total_num/$records_per_page); $last_page_num =
> $total_num_page + 1; directory_header(); top_menu(); echo "
>
> Displaying the page $page_num out of $last_page_num.
>
> "; echo "
> \n"; while($query_data = mysql_fetch_array($result)) { $url_id =
> $query_data["url_id"]; $url = "http://"; . $query_data["url"]; $title =
> $query_data["title"]; $description = $query_data["description"];
$category_id
> = $query_data["category_id"]; $category_info_array =
> get_category_info($category_id); $category_fullname =
> $category_info_array["fullname"]; echo "
>    * \n"; echo
>    "<\"javascript:open_window('$PHP_SELF?action=edit_new_form&url_id=$url_
>    id&category_id=$category_id');\">[Edit] \n"; echo "<\"$url\">$title
>    ($category_fullname) - $description\n"; echo ""; } echo "
> \n"; echo "
> \n"; echo "
> "; if($cur_page > 0) echo "<\"$PHP_SELF?action=view_new&cur_page=0\">[Top]";
> if($cur_page != 0) { $prev_page = $cur_page - 1; echo
> "<\"$PHP_SELF?action=view_new&cur_page=$prev_page\">[Prev] "; } if($cur_page
> [Next] "; } if($cur_page != $total_num_page) echo
> "<\"$PHP_SELF?action=view_new&cur_page=$total_num_page\">[Bottom]"; echo "
> "; directory_footer(); } function edit_new_form() { global $PHP_SELF,
> $max_desc_length, $url_id, $category_id; directory_header(); $url_info_array
> = get_url_info($url_id); $category_info_array =
> get_category_info($url_info_array["category_id"]); ?> 
>
> Editing a new listing.
>
>    * Submitted on:  
> ">  "> "> 
>  
>  Category   
>  Email ">  
>  Title " SIZE="30" MAXLENGTH="150">  
>  URL " SIZE="30" MAXLENGTH="150">  
>  Description
> ( Chars Max.)   
>  Action Approve Delete  
>     
>  
> alert(\"$title($url) has been successfully deleted!\");
> opener.location.href='$PHP_SELF?action=view_new'; self.close();"; } else {
> if(strlen($description) > $max_desc_length) error_message("Description too
> long! $max_desc_length chars max!"); $title = addslashes($title);
> $description = addslashes($description); $query = "UPDATE
$category_tablename
> SET num_item = num_item + 1 WHERE category_id = '$category_id'"; $result =
> mysql_query($query); if(!$result) error_message(sql_error()); $query =
> "UPDATE $directory_tablename SET title='$title', url='$url',
> description='$description', approved = 1 WHERE url_id='$url_id'"; $result =
> mysql_query($query); if(!$result) error_message(sql_error());
if($send_mail){
> $mail_subject = "PHP Directory>> Your contribution has been listed.";
> $mail_body = "Thank you for sharing your resources with us.\n"; $mail_body =
> "Your contribution has been listed. Thank you.\n\n"; $mail_body .= "Title:
> $title\n"; $mail_body .= "URL: $url\n"; $mail_body .= "Description:
> $description"; mail($email, $mail_subject, $mail_body, "From:
> $dirmaster_email\nReply-to: $dirmaster_email"); } $num_rows =
> mysql_affected_rows($link_id); if($num_rows != 1)
error_message(sql_error());
> else echo "alert(\"$title($url) has been successfully approved!\");
> self.close();"; } } function delete_url() { global $default_dbname,
> $directory_tablename, $category_tablename, $category_id, $url_id, $url,
> $title; global $PHP_SELF, $link_id; if(!$link_id) $link_id =
> db_connect($default_dbname); $query = "UPDATE $category_tablename SET
> num_item = num_item - 1 WHERE category_id = '$category_id'"; $result =
> mysql_query($query); if(!$result) error_message(sql_error()); $query =
> "DELETE FROM $directory_tablename WHERE url_id = '$url_id'"; $result =
> mysql_query($query); if(!$result) error_message(sql_error()); $num_rows =
> mysql_affected_rows($link_id); if($num_rows != 1)
error_message(sql_error());
> else echo "alert(\"$title($url) has been successfully deleted!\");
>
self.location.href='$PHP_SELF?action=show_list&category_id=$category_id';"; }
> function top_menu() { global $PHP_SELF; echo "<\"$PHP_SELF\">Admin ";
echo "|
> <\"javascript:open_window('$PHP_SELF?action=update_db');\">Update DB "; echo
> "| <\"$PHP_SELF?mode=edit_category\">Edit Category Mode "; echo "|
> <\"$PHP_SELF?mode=add_category\">Add Category Mode\n"; echo "|
> <\"$PHP_SELF?action=view_new\">New Listings\n"; echo "|
> <\"$PHP_SELF?action=show_list\">View Listings in Admin Mode\n"; echo "
>
> \n"; } switch($action) { case "add_category_form": add_category_form();
> break; case "add_category": add_category(); break; case
"edit_category_form":
> edit_category_form(); break; case "edit_category": edit_category(); break;
> case "delete_category": delete_category(); break; case "view_new":
> view_new(); break; case "edit_new_form": edit_new_form(); break; case
> "edit_new": edit_new(); break; case "add_url_form": add_url_form(); break;
> case "add_url": add_url(); break; case "modify_url_form": modify_url_form();
> break; break; case "modify_url": modify_url(); break; case "go_url":
> go_url(); break; case "delete_url": delete_url(); break; case "update_db":
> update_db(); break; case "show_list": directory_header(); top_menu();
> show_list(); directory_footer(); break; default: list_categories(); break; }
> ?> 

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux