...

View Full Version : PHP link to seperate div in page



synking
07-29-2008, 06:15 PM
I am trying to setup a page to display articles i have in a database to speed up content and make it easier to edit content and what not.... but what i am trying to do i don't know if it is possible.

i have the page here
<?PHP

if(empty($content)) {
$content = 'body.php';
}

if(empty($links)) {
$links = 'nav.php';
}


if(empty($header)) {
$header = 'head.php';
}
?>
<html>
<head><title>testing php cms front end</title>
<link href="style2.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="maincontainer">
<div id="topsection"><?php include $header; ?>
</div>
<div id="contentwrapper">
<div id="leftcolumn">
<div id="inner_space"><?PHP include $links; ?>
</div>
</div>
<div id="contentcolumn">
<div id="inner_space"><?PHP include $content; ?>
</div>
</div>
</div>
<div id="footer">should be fooot.
</div>
</div>
</body>
</html>

what i want is to have the nav.php Show links to the sections of the database and then have that link to the div that contains the content and show the articles related to that section.

dr34mc0d3r
07-29-2008, 08:04 PM
You cant dynamically insert include files - the include files are parsed before any other code on the page is even looked at.

scoop_987
07-29-2008, 08:16 PM
sounds like you need to modify the nav.php page rather than the index. So post the nav.php and ill help ya

synking
07-29-2008, 10:40 PM
here is the nav.php and if i can not dynamically use include what would be best.
<?PHP

require_once ('../includes/DbConnector.php');


$connector = new DbConnector();

$allowed_pages = array("news", "content", "contact", "service", "downloads");

if(isset($_GET['page']) && in_array($_GET['page'], $allowed_pages)) {

$page = $_GET['page'];

} else {

$page = "news";
}

$result = $connector->query('SELECT s.id AS `sectionID`,
s.name, s.parentid,
a.id AS `articleID`,
a.thedate, a.title, a.section, a.thearticle
FROM cmssection s
LEFT JOIN cmsarticles a ON (a.section = s.id)
WHERE s.id = 2');

if(!$result) {

echo ('<p class="error"> Error From SQL query: ' .$connector->getSqlError(). '</p>');

} else {

while ($row = $connector->fetchArray($result)) {

echo ('<p>');
echo ('<a href="test.php?content=" '.$row['section'].'>'.$row['name'].'</a>');

}
}
?>

Len Whistler
07-29-2008, 11:12 PM
but what i am trying to do i don't know if it is possible.

what i want is to have the nav.php Show links to the sections of the database and then have that link to the div that contains the content and show the articles related to that section.

Any thing is possible with PHP/MySQL. I would use the GET method and pass database info through the URL. Quick example below.

nav.php

<a href= "articles.php?id=books">Books</a>
<a href= "articles.php?id=magazines">Magazines</a>
<a href= "articles.php?id=pens">Pens</a>

articles.php

$articles = $_GET['id']
$result = mysql_query("SELECT * FROM products WHERE articles ='$articles'")



----------------

synking
07-31-2008, 02:33 PM
Ok i have been messing around with what you said len i have this as a link.


<a href="test.php?ID=2">News </a>

here is how i am querying the database.



$articles = $_GET['id'];
$result = $connector->query("SELECT * FROM cmsarticles WHERE section ='$articles'");
if(!$result) {
echo ('<p class="error">Error from query: ' .$connector->getSqlError(). '</p>');

} else {
echo $result;
}


but it gives me a resource id #11 message and i tried mysql site to see what that is but i get nothing.

abduraooft
07-31-2008, 03:49 PM
You need to fetch the data from the mysql result ,see http://php.net/mysql_fetch_array
BTW, always sanitise all external data (http://php.net/mysq_real_escape_string)

synking
07-31-2008, 04:00 PM
You need to fetch the data from the mysql result ,see http://php.net/mysql_fetch_array
BTW, always sanitise all external data (http://php.net/mysq_real_escape_string)


I acctually do that is what that connector class is it uses mysql_fetch_array to query the data base. And i don't think that is the problem as it works for every thing else.

abduraooft
07-31-2008, 04:02 PM
Could you post your function query() defined in connector class ?

synking
07-31-2008, 04:13 PM
i just noticed something

function query($query){

$this->theQuery = $query;
return mysql_query($query, $this->link);

}


function getQuery(){
return $this->thequery;
}


function getNumRows($result){
return mysql_num_rows($result);

}

//***function: FetchArray, Purpose: Get array of query results***
function fetchArray($result){

return mysql_fetch_array($result);


} I don't know what i am talking about.

synking
07-31-2008, 04:47 PM
ok i updated that code to this since i forgot to due it first


$articles = $_GET['id'];
$result = $connector->query("SELECT * FROM cmsarticles WHERE section ='$articles'");
if(!$result) {
echo ('<p class="error">Error from query: ' .$connector->getSqlError(). '</p>');

} else {
while ($row = $connector->fetchArray($result)) {

echo "<p>\n";
echo $row['title'];
echo '<br>';
echo $row['thearticle'];
echo '</p>';
}
} but i still get the same issue resource id #11

synking
07-31-2008, 09:19 PM
got this fixed here is the code don't know what was wrong.


<?PHP

require_once ('../includes/DbConnector.php');


$connector = new DbConnector();

$result = $connector->query('SELECT * FROM cmssection');
if(!$result) {
echo ('<p class="error">Error from query: ' .$connector->getSqlError(). '</p>');

} else {

echo ("<table border=\"0\" width=\"180\"> \n");
echo ("<tr> \n");
echo ("<td><h5>Main Links</h5></td></tr> \n");

while ($row = $connector->fetchArray($result)) {

echo ("<tr> \n");
echo ('<td width="100%" bgcolor="#E6E6E6"><a href="test.php?ID='.$row['ID'].'" class="menulink">'.$row['name']. '</a></td>');
echo ("</tr> \n");


}
echo ("</table> \n");
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum