/    Sign up×
Community /Pin to ProfileBookmark

using "href" to other file

Hi,
I have this code called comp_initial.php as shown beloow:

[code=php]
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<title>The Blog Warehouse</title>
<meta http-equiv=”content-type”
content=”text/html; charset=iso-8859-1″ />
</head>
<body>
<h1>Companies in the Blogosphere (Boolean search)</h1>

<?php

$dbcnx = @mysql_connect(‘localhost’, ‘root’, ‘password’);
if (!$dbcnx) {
exit(‘<p>Unable to connect to the database server at this time.</p>’);
}

// Select the blog database
if (!@mysql_select_db(‘ijob’)) {
exit(‘<p>Unable to locate the blog collection database at this time.</p>’);
}
?>

<?php
$a_name_qeury = “select comp_name from company_list where comp_name like ‘a%'”;
$a_name_result = @mysql_query($a_name_qeury );
if(!$a_name_result) {
exit (‘<p>Error retrieving blog entries from database!<br />’.
‘Error: ‘.mysql_error(). ‘</p>’);
}
while ($a_name_output =mysql_fetch_array($a_name_result)){
$a_name =$a_name_output[comp_name];

$a_qeury = “select id, 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>’);
}
$a_output = mysql_fetch_array($a_result);
if ($a_output != “”) {
$id = $a_output[id];
echo “<a href = ‘comp_name.php?id = $id’>A</a>”;
}
}

?>

</body>
</html>
[/code]

‘comp_name.php is the file to display the names retrieved from MySQL table, using id as the condition. ‘comp_name.php is shown as below:

[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]”;
}
}

?>
[/code]

However, there are some bugs in the codes. When A is clicked, nothing comes out. Could anyone help? ?

Thanks a lot ?

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@chazzySep 04.2006 — in sql, strings (varchar) need to be surrounded by single quotes ' not double quotes "

the query you build looks like this...

<i>
</i>select id, content from blog_entry where content like "%some_name%";


when it should be

<i>
</i>select id, content from blog_entry where content like '%some_name%';
×

Success!

Help @yunfanny spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...