Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    New Coder
    Join Date
    Jul 2008
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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.

  • #2
    New to the CF scene
    Join Date
    Apr 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You cant dynamically insert include files - the include files are parsed before any other code on the page is even looked at.

  • #3
    New Coder
    Join Date
    Jul 2008
    Posts
    91
    Thanks
    4
    Thanked 9 Times in 9 Posts
    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

  • #4
    New Coder
    Join Date
    Jul 2008
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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>');

            }
        }
    ?>

  • #5
    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
    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'"


    ----------------
    Last edited by Len Whistler; 07-29-2008 at 11:17 PM.
    Leonard Whistler

  • #6
    New Coder
    Join Date
    Jul 2008
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #7
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,849
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    You need to fetch the data from the mysql result ,see http://php.net/mysql_fetch_array
    BTW, always sanitise all external data
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #8
    New Coder
    Join Date
    Jul 2008
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #9
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,849
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Could you post your function query() defined in connector class ?
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #10
    New Coder
    Join Date
    Jul 2008
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #11
    New Coder
    Join Date
    Jul 2008
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #12
    New Coder
    Join Date
    Jul 2008
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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");
    }


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •