Forum Moderators: coopster

Message Too Old, No Replies

create entry from database

         

ploppy

10:02 am on Aug 19, 2007 (gmt 0)

10+ Year Member



hi. i am hoping someone can help me solve this problem i have spent the las 5 days over. now admit defeat :-)

here's the scenario. I have a database with a table

idx_link

in that table there is a field:

description

what i am trying to is to pass the field, description into meta_content on a page which uses php to pass variables etc. here is the php page:

/*===================================================
ShowDetailPage()
===================================================*/

function ShowDetailPage() {

// vars global configuration
global $dbConn, $theme_name, $theme_path, $rev_max_rows, $category_separator;

// vars url & form
global $id;

// vars messages
global $msg;

// vars template
global $link_detail, $description, $pagination, $review_rows, $ofc_review;

global $linkid;

global $page_title, $link_id, $category_id, $category_name,
$category_path, $category_path_with_link;

$tpl = new Template();

if (empty($id))
$id = $linkid;

$links_obj = new clsLink;
$links_obj->query = "select * from idx_link where link_id = '$id'";
$links_obj->table_name = "idx_link";
$links_obj->category_table_name = "idx_category";
$links_obj->review_table_name = "idx_review";
$links_obj->category_separator = $category_separator;
$links_obj->max_rows = 1;
$links_obj->rating_image_path = "themes/" . $theme_name . "/images/rating/";
$links_obj->rev_rating_image_path = "themes/" . $theme_name . "/images/review/";
$links_obj->date_format = $msg["10161"];
$links_obj->template_file = $theme_path . "detail_link.html";
$link_detail = $links_obj->Display();


// official review
$query = "select official_review, category_id from idx_link where link_id = '$id'";
$result = $dbConn->Execute($query);
$ofc_review = $result->Fields("official_review");
$category_id = $result->Fields("category_id");

if (!empty($ofc_review)) {
$ofc_review_html = $msg["10163"];

if (empty($ofc_review_html))
$ofc_review_html = '<%$ofc_review%>';
}

$tpl->assign('ofc_review', $ofc_review);
$ofc_review = $tpl->fetch('var:' . $ofc_review_html);

// review

$links_obj->pg_size = $rev_max_rows;
$links_obj->href = "detail.php";
$links_obj->more_param = "&linkid=$id";
$links_obj->template_file = $theme_path . "review_rows.html";

if ($links_obj->GetNumberOfReview($id) > 0) {

// get avg_review
global $num_review, $avg_review, $avg_review_image;

$query = "select reviews, avg_review from idx_link where link_id = '$id'";
$result2 = $dbConn->Execute($query);
$avg_review = $result2->Fields("avg_review");
$num_review = $result2->Fields("reviews");
$avgr = $avg_review * 2;

if (round($avgr) == 1)
$avg_review_image = "<img src=" . "themes/" . $theme_name . "/images/review/" . "0half.gif" . ">";
elseif (round($avgr) == 2)
$avg_review_image = "<img src=" . "themes/" . $theme_name . "/images/review/" . "0.gif" . ">";
elseif (round($avgr) == 3)
$avg_review_image = "<img src=" . "themes/" . $theme_name . "/images/review/" . "1half.gif" . ">";
elseif (round($avgr) == 4)
$avg_review_image = "<img src=" . "themes/" . $theme_name . "/images/review/" . "2.gif" . ">";
elseif (round($avgr) == 5)
$avg_review_image = "<img src=" . "themes/" . $theme_name . "/images/review/" . "2half.gif" . ">";
elseif (round($avgr) == 6)
$avg_review_image = "<img src=" . "themes/" . $theme_name . "/images/review/" . "3.gif" . ">";
elseif (round($avgr) == 7)
$avg_review_image = "<img src=" . "themes/" . $theme_name . "/images/review/" . "3half.gif" . ">";
elseif (round($avgr) == 8)
$avg_review_image = "<img src=" . "themes/" . $theme_name . "/images/review/" . "4.gif" . ">";
elseif (round($avgr) == 9)
$avg_review_image = "<img src=" . "themes/" . $theme_name . "/images/review/" . "4half.gif" . ">";
elseif (round($avgr) == 10)
$avg_review_image = "<img src=" . "themes/" . $theme_name . "/images/review/" . "5.gif" . ">";

$tpl = new Template;
$tpl->assign('avg_review', $avg_review);
$tpl->assign('num_review', $num_review);
$tpl->assign('avg_review_image', $avg_review_image);
$review_header = $tpl->fetch('var:' . $msg["10162"]);
$links_obj->header = $review_header;
$review_rows = $links_obj->header;
$review_rows .= $links_obj->DisplayReview($id);
}

$pagination = $links_obj->pagination;

$link_id = $id;

$query = "select name
from idx_category
where category_id = '$category_id'";
$row = $dbConn->FetchOne($query);
$category_name = $row['name'];

$query = "select path, path_with_url
from idx_category_path
where category_id = '$category_id'";
$row = $dbConn->FetchOne($query);
$category_path = $row['path'];
$category_path_with_link = $row['path_with_url'];

DisplayTemplate($theme_path . "detail.html",
"\$page_title,\$avg_review,\$num_review,\$avg_review_image,\$link_detail,".
"\$pagination,\$review_rows,\$ofc_review,\$link_id,".
"\$category_id,\$category_name,\$category_path,\$category_path_with_link");
}

/*===================================================
main
===================================================*/

include "application.php";

AddFilter("page_cache");
RunPreFilter(__FILE__);

if (!defined('CACHED_PAGE')) {
if (empty($id)) {
$id = $linkid;
}
$query = "select title, suspended from idx_link where link_id = '$id'";
$result = $dbConn->Execute($query);
$link_title = $result->Fields("title");
$suspended = $result->Fields("suspended");
$page_title = $link_title;

// check if suspended
if ($suspended) {
DisplayTemplate($theme_path . "suspended.html");
RunPostFilter(__FILE__);
}

ShowDetailPage();
}

RunPostFilter(__FILE__);

and here is html:

<%include file="header.html"
title="$page_title"
meta_keywords=""
meta_description=""
%>

</td>
</tr>
<tr>
<td>

<!-- main content here -->

<br />

<!-- link detail information -->
<%$link_detail%>
<br />

<!-- official review -->
<%if $ofc_review%>
<b>Official Review</b><br />
<%$ofc_review%>
<%/if%>

<!-- show review -->
<%if $num_review gt '0'%>
<p>
<b>Average Registered User Rating: </b> <%$avg_review_image%>
<b><%$avg_review%></b> (out of 5)<br />
Number of review: <%$num_review%> Reviews
</p>
<%$review_rows%>

<p><%$pagination%></p>
<%/if%>

<!-- other link by this user -->
<%block_view_other_links link_id="$link_id" title="Other links owned by this user"%>

<!-- other link in this category -->
<%block_view_other_links category_id="$category_id" max_item="5" title="Other links at $category_path"%>

<br />
<br />

<!-- end of main content -->

</td>
</tr>
<tr>
<td>

<%include file="footer.html"%>

ignore the asp tags %, they are used by the program. i hope this makes sense and someone can help. many thanks.

Habtom

10:19 am on Aug 19, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You want to get the description from idx_link and put it in the META description, is that what you are trying to do?

I scanned the code, and couldn't get the obvious queries and you trying to display the description. May be I missed it.

You can begin by changing <% %> to <?php?>

And now tell us what exactly is the problem you are facing. Is it an error? You couldn't get the display at all. Can you clarify it a bit more, and posting the relevant code.

Habtom

ploppy

10:29 am on Aug 19, 2007 (gmt 0)

10+ Year Member



hi habtom firstly, ignore the % tags. the program is php and the % tags are used to communicate with smarty. what i am trying to do is to incorporate the description field from the database into meta_description when someone clicks the detail link which is what is called as posted above. at the moment, no meta information is posted and i would like each page to have meta_description from the description field. hope that helps. cheers

Habtom

11:59 am on Aug 19, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Write a separate query for it, or include the fieldname in one of the queries you have and print the meta description where it is appropriate.

$query = "select official_review, category_id, meta_description from idx_link where link_id = '$id'";
$result = $dbConn->Execute($query);
$ofc_review = $result->Fields("official_review");
$category_id = $result->Fields("category_id");
$meta_description = $result->Fields("meta_description");

Habtom

ploppy

1:52 pm on Aug 19, 2007 (gmt 0)

10+ Year Member



habtom thanks for that. where exactly would i place the code in relation to above script? thanks

Habtom

1:58 pm on Aug 19, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



// official review
$query = "select official_review, category_id from idx_link where link_id = '$id'";
$result = $dbConn->Execute($query);
$ofc_review = $result->Fields("official_review");
$category_id = $result->Fields("category_id");

The above code is part of what you posted on your first post. Now you need the description from idx_link. Rewrite the above as follows (check the description field name)

// official review
$query = "select official_review, category_id, description from idx_link where link_id = '$id'";
$result = $dbConn->Execute($query);
$ofc_review = $result->Fields("official_review");
$category_id = $result->Fields("category_id");
$description = $result->Fields("description");

And now use $description where you want to use it. I can't put it on the page as you don't have your META tags anywhere.

But this should give you a start. Good Luck.

Habtom

ploppy

10:20 pm on Aug 19, 2007 (gmt 0)

10+ Year Member



habtom. not working. being a newbie to php, perhaps i am doing something wrong. at the simplest level, if i wanted to pull a field from called description and place contents in meta_content? thanks

Habtom

4:44 am on Aug 20, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> not working

What do you mean? The query above will give you the description you are looking for. Please go a bit specific and tell us what part you couldn't understand.

Habtom

ploppy

10:02 am on Aug 20, 2007 (gmt 0)

10+ Year Member



hi habtom. sorry to be so vague. i am not explaining myself very well am i :-) being totally new to php, i am trying to understand the structure of the language so i understand how things work. what i have done is to repost the original php file:

 /*===================================================
ShowDetailPage()
===================================================*/

function ShowDetailPage() {

// vars global configuration
global $dbConn, $theme_name, $theme_path, $rev_max_rows, $category_separator;

// vars url & form
global $id;

// vars messages
global $msg;

// vars template
global $link_detail, $pagination, $review_rows, $ofc_review;

global $linkid;

global $page_title, $link_id, $category_id, $category_name,
$category_path, $category_path_with_link;

$tpl = new Template();

if (empty($id))
$id = $linkid;

$links_obj = new clsLink;
$links_obj->query = "select * from idx_link where link_id = '$id'";
$links_obj->table_name = "idx_link";
$links_obj->category_table_name = "idx_category";
$links_obj->review_table_name = "idx_review";
$links_obj->category_separator = $category_separator;
$links_obj->max_rows = 1;
$links_obj->rating_image_path = "themes/" . $theme_name . "/images/rating/";
$links_obj->rev_rating_image_path = "themes/" . $theme_name . "/images/review/";
$links_obj->date_format = $msg["10161"];
$links_obj->template_file = $theme_path . "detail_link.html";
$link_detail = $links_obj->Display();

// official review
$query = "select official_review, category_id from idx_link where link_id = '$id'";
$result = $dbConn->Execute($query);
$ofc_review = $result->Fields("official_review");
$category_id = $result->Fields("category_id");

if (!empty($ofc_review)) {
$ofc_review_html = $msg["10163"];

if (empty($ofc_review_html))
$ofc_review_html = '<%$ofc_review%>';
}

$tpl->assign('ofc_review', $ofc_review);
$ofc_review = $tpl->fetch('var:' . $ofc_review_html);

// review

$links_obj->pg_size = $rev_max_rows;
$links_obj->href = "detail.php";
$links_obj->more_param = "&linkid=$id";
$links_obj->template_file = $theme_path . "review_rows.html";

if ($links_obj->GetNumberOfReview($id) > 0) {

// get avg_review
global $num_review, $avg_review, $avg_review_image;

$query = "select reviews, avg_review from idx_link where link_id = '$id'";
$result2 = $dbConn->Execute($query);
$avg_review = $result2->Fields("avg_review");
$num_review = $result2->Fields("reviews");
$avgr = $avg_review * 2;

if (round($avgr) == 1)
$avg_review_image = "<img src=" . "themes/" . $theme_name . "/images/review/" . "0half.gif" . ">";
elseif (round($avgr) == 2)
$avg_review_image = "<img src=" . "themes/" . $theme_name . "/images/review/" . "0.gif" . ">";
elseif (round($avgr) == 3)
$avg_review_image = "<img src=" . "themes/" . $theme_name . "/images/review/" . "1half.gif" . ">";
elseif (round($avgr) == 4)
$avg_review_image = "<img src=" . "themes/" . $theme_name . "/images/review/" . "2.gif" . ">";
elseif (round($avgr) == 5)
$avg_review_image = "<img src=" . "themes/" . $theme_name . "/images/review/" . "2half.gif" . ">";
elseif (round($avgr) == 6)
$avg_review_image = "<img src=" . "themes/" . $theme_name . "/images/review/" . "3.gif" . ">";
elseif (round($avgr) == 7)
$avg_review_image = "<img src=" . "themes/" . $theme_name . "/images/review/" . "3half.gif" . ">";
elseif (round($avgr) == 8)
$avg_review_image = "<img src=" . "themes/" . $theme_name . "/images/review/" . "4.gif" . ">";
elseif (round($avgr) == 9)
$avg_review_image = "<img src=" . "themes/" . $theme_name . "/images/review/" . "4half.gif" . ">";
elseif (round($avgr) == 10)
$avg_review_image = "<img src=" . "themes/" . $theme_name . "/images/review/" . "5.gif" . ">";

$tpl = new Template;
$tpl->assign('avg_review', $avg_review);
$tpl->assign('num_review', $num_review);
$tpl->assign('avg_review_image', $avg_review_image);
$review_header = $tpl->fetch('var:' . $msg["10162"]);
$links_obj->header = $review_header;
$review_rows = $links_obj->header;
$review_rows .= $links_obj->DisplayReview($id);
}

$pagination = $links_obj->pagination;

$link_id = $id;

$query = "select name
from idx_category
where category_id = '$category_id'";
$row = $dbConn->FetchOne($query);
$category_name = $row['name'];

$query = "select path, path_with_url
from idx_category_path
where category_id = '$category_id'";
$row = $dbConn->FetchOne($query);
$category_path = $row['path'];
$category_path_with_link = $row['path_with_url'];

DisplayTemplate($theme_path . "detail.html",
"\$page_title,\$avg_review,\$num_review,\$avg_review_image,\$link_detail,".
"\$pagination,\$review_rows,\$ofc_review,\$link_id,".
"\$category_id,\$category_name,\$category_path,\$category_path_with_link");
}

/*===================================================
main
===================================================*/

include "application.php";

AddFilter("page_cache");
RunPreFilter(__FILE__);

if (!defined('CACHED_PAGE')) {
if (empty($id)) {
$id = $linkid;
}
$query = "select title, suspended from idx_link where link_id = '$id'";
$result = $dbConn->Execute($query);
$link_title = $result->Fields("title");
$suspended = $result->Fields("suspended");
$page_title = $link_title;

// check if suspended
if ($suspended) {
DisplayTemplate($theme_path . "suspended.html");
RunPostFilter(__FILE__);
}

ShowDetailPage();
}

RunPostFilter(__FILE__);

this php points to detail.html which then points to detail_link.html. in the detail.html file there is an entry:

<%include file="header.html"
title="$page_title"
meta_keywords=""
meta_description=""
%>

i need to place the variable $description

so that the entry reads:

<%include file="header.html"
title="$page_title"
meta_keywords=""
meta_description="$description"
%>

i need to read each listings description from the idx_link table and place as meta_description when there page is called. thanks ever so much for help. appreciate your time.

ploppy

1:38 pm on Aug 20, 2007 (gmt 0)

10+ Year Member



{BUMP}