Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-29-2008, 06:15 PM   PM User | #1
synking
New Coder

 
Join Date: Jul 2008
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
synking is an unknown quantity at this point
PHP link to seperate div in page

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
Code:
<?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.
synking is offline   Reply With Quote
Old 07-29-2008, 08:04 PM   PM User | #2
dr34mc0d3r
New to the CF scene

 
Join Date: Apr 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
dr34mc0d3r is an unknown quantity at this point
You cant dynamically insert include files - the include files are parsed before any other code on the page is even looked at.
dr34mc0d3r is offline   Reply With Quote
Old 07-29-2008, 08:16 PM   PM User | #3
scoop_987
New Coder

 
Join Date: Jul 2008
Posts: 91
Thanks: 4
Thanked 9 Times in 9 Posts
scoop_987 is an unknown quantity at this point
sounds like you need to modify the nav.php page rather than the index. So post the nav.php and ill help ya
__________________
Current Project: Nothing at the minute
scoop_987 is offline   Reply With Quote
Old 07-29-2008, 10:40 PM   PM User | #4
synking
New Coder

 
Join Date: Jul 2008
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
synking is an unknown quantity at this point
here is the nav.php and if i can not dynamically use include what would be best.
PHP Code:
<?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>');

        }
    }
?>
synking is offline   Reply With Quote
Old 07-29-2008, 11:12 PM   PM User | #5
Len Whistler
Senior Coder

 
Len Whistler's Avatar
 
Join Date: Jul 2002
Location: Vancouver, BC Canada
Posts: 1,323
Thanks: 26
Thanked 100 Times in 100 Posts
Len Whistler is on a distinguished road
Quote:
Originally Posted by synking View Post
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
PHP Code:
<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
PHP Code:
$articles $_GET['id']
$result mysql_query("SELECT * FROM products WHERE articles ='$articles'"


----------------
__________________
Leonard Whistler

Last edited by Len Whistler; 07-29-2008 at 11:17 PM..
Len Whistler is offline   Reply With Quote
Old 07-31-2008, 02:33 PM   PM User | #6
synking
New Coder

 
Join Date: Jul 2008
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
synking is an unknown quantity at this point
Ok i have been messing around with what you said len i have this as a link.

Code:
<a href="test.php?ID=2">News </a>
here is how i am querying the database.

Code:
$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.
synking is offline   Reply With Quote
Old 07-31-2008, 03:49 PM   PM User | #7
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,689
Thanks: 158
Thanked 2,184 Times in 2,171 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
You need to fetch the data from the mysql result ,see http://php.net/mysql_fetch_array
BTW, always sanitise all external data
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
abduraooft is offline   Reply With Quote
Old 07-31-2008, 04:00 PM   PM User | #8
synking
New Coder

 
Join Date: Jul 2008
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
synking is an unknown quantity at this point
Quote:
Originally Posted by abduraooft View Post
You need to fetch the data from the mysql result ,see http://php.net/mysql_fetch_array
BTW, always sanitise all external data

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.
synking is offline   Reply With Quote
Old 07-31-2008, 04:02 PM   PM User | #9
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,689
Thanks: 158
Thanked 2,184 Times in 2,171 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
Could you post your function query() defined in connector class ?
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
abduraooft is offline   Reply With Quote
Old 07-31-2008, 04:13 PM   PM User | #10
synking
New Coder

 
Join Date: Jul 2008
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
synking is an unknown quantity at this point
i just noticed something
PHP Code:
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 is offline   Reply With Quote
Old 07-31-2008, 04:47 PM   PM User | #11
synking
New Coder

 
Join Date: Jul 2008
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
synking is an unknown quantity at this point
ok i updated that code to this since i forgot to due it first

PHP Code:
$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 is offline   Reply With Quote
Old 07-31-2008, 09:19 PM   PM User | #12
synking
New Coder

 
Join Date: Jul 2008
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
synking is an unknown quantity at this point
got this fixed here is the code don't know what was wrong.

PHP Code:
<?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");
}
synking is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:36 PM.


Advertisement
Log in to turn off these ads.