Hi,
I have the following php code to get the hyperlink of the retrieved company name(s), which may related to several entries to be displayed when the hyperlink is clicked:
[code=php]
<?php
$dbcnx = @mysql_connect(‘localhost’, ‘root’, ‘password’);
if (!$dbcnx) {
exit(‘<p>Unable to connect to the database server at this time.</p>’);
}
if (!@mysql_select_db(‘ijob’)) {
exit(‘<p>Unable to locate the blog collection database at this time.</p>’);
}
?>
<?php
$id = $_GET[‘id’];
$select = “SELECT comp_id, comp_name from company_list where comp_id=’$id’ order by comp_name”;
$retrieve = @mysql_query($select);
if(!$retrieve) {
exit (‘<p>Error retrieving blog entries from database!<br />’.
‘Error: ‘.mysql_error(). ‘</p>’);
}
while ($result = mysql_fetch_array($retrieve)) {
if ($result != “”) {
$a_name = $result[‘comp_name’];
$a_qeury = “select id, title, content from blog_entry where content like “;
$a_qeury = $a_qeury . ‘”%’;
$a_qeury = $a_qeury . $a_name;
$a_qeury = $a_qeury . ‘%”‘;
$a_result = @mysql_query($a_qeury);
if(!$a_result) {
exit (‘<p>Error retrieving blog entries from database!<br />’.
‘Error: ‘.mysql_error(). ‘</p>’);
}
while ($a_output = mysql_fetch_array($a_result)){
if ($a_output != “”) {
echo ‘<a href=”blogentry_name.php?id=’.$a_output[‘id’].'”>’.$result[‘comp_name’].'</a>’;
}
}
}
}
?>
blogentry_name.php:
[code=php]
<?php
$dbcnx = @mysql_connect(‘localhost’, ‘root’, ‘password’);
if (!$dbcnx) {
exit(‘<p>Unable to connect to the database server at this time.</p>’);
}
if (!@mysql_select_db(‘ijob’)) {
exit(‘<p>Unable to locate the blog collection database at this time.</p>’);
}
?>
<?php
$id = $_GET[‘id’];
$select = “SELECT DISTINCT title, id, publish_date from blog_entry where id=’$id’ GROUP BY title order by publish_date”;
$retrieve = @mysql_query($select);
if(!$retrieve) {
exit (‘<p>Error retrieving blog entries from database!<br />’.
‘Error: ‘.mysql_error(). ‘</p>’);
}
while ($result = mysql_fetch_array($retrieve)) {
if ($result != “”) {
echo ‘<a href=”comp_content.php?id=’.$id.'”>’.$result[‘title’].'</a>’;
echo “$result[publish_date]”;
}
}
?>
As a result, the same company name will appear multiple time when it related to multiple number of entries. For example, there are 3 entries related to “AOL” and “AOL” will appear 3 times, each links to different entry. :rolleyes: However, this is not as what I want. It is designed to display the same comapnay name once; when this company name is clicked, the list of related entries will appear. So how should I change the codes ? ?
Thank you very much. ?