Jump to content

Gem

Members
  • Posts

    129
  • Joined

  • Last visited

Posts posted by Gem

  1.  

    Hiya ... I just got this code from the tutorials part of phpfreaks.com, and it works very well (thanks crayon violent!)

     

    Im having a problem with it though.

     

    I need the results the other way round ... i.e. the last entry in my database to be on page one, first entry on last page ... see what I mean??

     

    Heres the code ...

     

    <?php
    // database connection info
    $conn = mysql_connect("=)") or trigger_error("SQL", E_USER_ERROR);
    $db = mysql_select_db('bssql',$conn) or trigger_error("SQL", E_USER_ERROR);
    
    // find out how many rows are in the table 
    $sql = "SELECT COUNT(*) FROM articles";
    $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
    $r = mysql_fetch_row($result);
    $numrows = $r[0];
    
    // number of rows to show per page
    $rowsperpage = 2;
    // find out total pages
    $totalpages = ceil($numrows / $rowsperpage);
    
    // get the current page or set a default
    if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {
       // cast var as int
       $currentpage = (int) $_GET['currentpage'];
    } else {
       // default page num
       $currentpage = 1;
    } // end if
    
    // if current page is greater than total pages...
    if ($currentpage > $totalpages) {
       // set current page to last page
       $currentpage = $totalpages;
    } // end if
    // if current page is less than first page...
    if ($currentpage < 1) {
       // set current page to first page
       $currentpage = 1;
    } // end if
    
    // the offset of the list, based on current page 
    $offset = ($currentpage - 1) * $rowsperpage;
    
    // get the info from the db 
    $sql = "SELECT title, subtitle, article FROM articles LIMIT $offset, $rowsperpage";
    $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
    
    // while there are rows to be fetched...
    while ($list = mysql_fetch_assoc($result)) {
       // echo data
       echo $list['title'] . " : " . $list['subtitle'] . " : " . $list['article'] . "<br />";
    } // end while
    
    /******  build the pagination links ******/
    // range of num links to show
    $range = 3;
    
    // if not on page 1, don't show back links
    if ($currentpage > 1) {
       // show << link to go back to page 1
       echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> ";
       // get previous page num
       $prevpage = $currentpage - 1;
       // show < link to go back to 1 page
       echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> ";
    } // end if 
    
    // loop to show links to range of pages around current page
    for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {
       // if it's a valid page number...
       if (($x > 0) && ($x <= $totalpages)) {
          // if we're on current page...
          if ($x == $currentpage) {
             // 'highlight' it but don't make a link
             echo " [<b>$x</b>] ";
          // if not current page...
          } else {
             // make it a link
     echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> ";
          } // end else
       } // end if 
    } // end for
    
    // if not on last page, show forward and last page links	
    if ($currentpage != $totalpages) {
       // get next page
       $nextpage = $currentpage + 1;
        // echo forward link for next page 
       echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> ";
       // echo forward link for lastpage
       echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> ";
    } // end if
    /****** end build pagination links ******/
    ?>

     

    Hope you can help ... Thanks in advance =)

     

    PS: If anyone know's an easy code to produce a "contents list" that will display just the titles, and when clicked goes to the right page ... that would be very helpful too =)

     

     

  2. Thats great guys .. thanks a million

     

    I cant actually make it wider at the moment because I've used a lot of images and it messes it up if I try to change the size now ... I originally did it that size so it would fit nicely on a 800x600 res ?! Fair comment though

     

    Also I cant help the colors because blue and yellow are my club colors ...

     

    as opposed to our old website ....

     

    www.bradleystokejudoclub.uk (click the link for the old site)

     

    Thanks again, I appreciate your comments - I will defo get a mouseover effect for the navi bar =)

     

    XXXX

  3. Hi all ...

     

    I have nearly completed my first webpage ... was wondering if you would take a look at let me know what you think ...

     

    www.bradleystokejudoclub.co.uk/newindex.php

     

    Things to bear in mind ...

     

    I had to add a page loading script because I am running a SQL query and it made the site slooooow ...

     

    The query is the Latest News section, it displays the newst 5 entries from my database which is currently filled with test data...

     

    Only this page is live at the moment .... so the navigation doesnt work yet

     

    The page isnt completed yet (depending on when you are looking at this post ..) I still have to write more content to fill the white space (training times will go there)

     

    Be mean ... its ok, I've got thick skin ... :)

     

    Thanks xxx

  4. Sure ...

     

    <?php
    $con = mysql_connect(" =) ");
    if (!$con)
    {
        die('Could not connect: ' . mysql_error());
    }
    mysql_select_db("bssql", $con);
    $result = mysql_query("SELECT `title`, `subtitle` FROM `articles` ORDER BY `ID` DESC LIMIT 5") or die(mysql_error());
    while($row = mysql_fetch_assoc($result))
    {
        ?><b><?php echo $row['title'];?></b> 
        <BR><?php echo $row['subtitle']?><BR><?php
    }
    mysql_close($con);
    ?>

  5. Hiya ..

     

    Hopefully just a quick question ..

     

    my new homepage ... www.bradleystokejudoclub.co.uk/newindex.php

    is loading incredibly slow, and I figure it is because of the query that is in the Latest News section ...

     

    Is there a way to load the rest of the page and not have to wait for the query ... maybe some kind of "loading" in the latest news bit whilst its getting there??

     

    Hope that makes sense...

     

    thanks

     

     

  6. Hi guys ... I am very nearly ready to go live with my new very basic cms.

     

    I have one last problem I need to overcome though.

     

    Basically when the admin users enter information into a form, i.e. News Updates ... they are writing it in plain text ... they have no knowledge of HTML ...

     

    So the problem I have is the output comes out without any line break when we press enter on the keyboard ...

     

    I'm not sure that makes sense so heres an example ...

     

    Heres my form ..

     

      <form action="insert.php" method="post">
    Title:
    <BR> <input type="text" name="title" />
    <BR>Description:
    <BR> <input type="text" name="subtitle" />
    <BR>News Update:
    <BR>  <textarea name="article" rows="20" cols="75"> </textarea>
    <BR><input type="submit" />
    </form>

     

    In the textarea ...

     

    I need to be able to write things like

     

    First Line

     

    Second Line

     

    Etc

    Etc

     

    From Gem

     

    But at the moment the output im getting on my webpage is

     

    First Line Second Line Etc Etc From Gem

     

    How do I fix this??

     

    Heres the code that displays the forms information from the database ...

     

    <?php
    $con = mysql_connect("CONNECTION DETAILS");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
    }mysql_select_db("bssql", $con);$result = mysql_query("SELECT * FROM articles ORDER BY ID DESC");while($row = mysql_fetch_array($result))
      {
      ?><H1><?php echo $row['Title']; ?> </H1> 
        <H2><?php echo $row['SubTitle']; ?> </H2>
            <?php echo $row['Article'];
                  echo "<br />";
      }mysql_close($con);
    ?>

    Thanks in advance ..

     

    Gem

     

     

  7. red I copied your code and it didnt like the LIMIT '2' , came back with an error ...

     

    so I did your code with LIMIT 2 .. and I've got a blank again ... this is interesting though, without the LIMIT 2 bit, the original code works fine ... with the LIMIT 2 I get no errors, but also no content ....

     

     

  8.   <?php

    $con = mysql_connect("CONNECTION");

    if (!$con)

      {

      die('Could not connect: ' . mysql_error());

    }mysql_select_db("bssql", $con);$result = mysql_query("SELECT title, subtitle FROM articles ORDER BY ID DESC LIMIT 2");while($row = mysql_fetch_array($result))

      {

        echo $row['Title'];

        echo $row['SubTitle'];

           

      }mysql_close($con);

    ?>

     

    Had to do 2 as theres only 3 records in the table lol ... doesnt do anything though ... all i get is a blank page ... I think I messed up the code ... the query works in SQLyog ...?

  9. Hi

     

    How do I limit the results returned by php from my database??

     

    I.e. I have a table of articles, and I want to display the newest 5 articles on my homepage...

     

    How do I do that?

     

    This is the code I have so far... but this displays every record ...

     

    <?php
    $con = mysql_connect("CONNECTION DETAILS");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
    }mysql_select_db("bssql", $con);$result = mysql_query("SELECT * FROM articles ORDER BY ID DESC");while($row = mysql_fetch_array($result))
      {
       echo $row['Title']; 
       echo $row['SubTitle']; 
       echo "<br />";
      }mysql_close($con);
    ?>

     

    Thanks in advance ..

     

    Gem

     

    PS: Can you tell me exactly where I need to add something if necessary ... I always mess things up otherwise  :)

  10. OK LOL - What did I do wrong?

     

    I just done the index on column "ID" - though I dont really know what that actually means ...

     

    so then I did this...

      }mysql_select_db("bssql", $con);$result = mysql_query("SELECT * FROM articles");while($row = mysql_fetch_array($result) ORDER BY INDEX SORT DESC;)

     

    and got this:

    PHP Parse error: syntax error, unexpected T_STRING in d:\webspace\bradleystokejudoclub.co.uk\wwwroot\news.php on line 17

     

    Help ...  ???  :(

  11. Hiya, I've got this code that displays my articles ... but I need them to be displayed "newest first" ..

     

    Can anyone help me with that?

     

      <?php
    $con = mysql_connect("CONNECTION DETAILS");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }mysql_select_db("DBNAME", $con);$result = mysql_query("SELECT * FROM articles");while($row = mysql_fetch_array($result))
      {
      echo $row['Title'];
      echo "<br />";
      echo $row['SubTitle'];
      echo "<br />";
      echo $row['Article'];
      echo "<br />";
      }mysql_close($con);
    ?>

     

    Also, heres my form ... I cant get the textarea to display properly, it just displays the same as the other fields which is really annoying ... any ideas??

     

      <form action="insert.php" method="post">
    Title: <input type="text" name="title" />
    Description: <input type="text" name="subtitle" />
    News Update:  <input type="textarea" name="article" />
    <input type="submit" />
    </form>

     

    Thanks loads

     

    Gem xxx

  12.  

    Hi all,

     

    Wonder if you can help

     

    I found a tutorial for building a CMS here: http://www.intranetjournal.com

     

    I'm struggling with the conenction parts.

     

    It says to build a system componant .. heres the code:

     

    <?php
    class SystemComponent {
    
    var $settings;
    
    function getSettings() {
    
    // System variables
    $settings['siteDir'] = '';
    
    // Database variables
    $settings['dbhost'] = 'HOST';
    $settings['dbusername'] = 'USER';
    $settings['dbpassword'] = 'PASSWORD';
    $settings['dbname'] = 'DB';
    
    return $settings;
    
    }
    
    }
    ?> 

     

    And this is the error im getting when I try to add an article:

     

    PHP Warning: main(SystemComponent.php) [function.main]: failed to open stream: No such file or directory in d:\webspace\bradleystokejudoclub.co.uk\wwwroot\includes\DbConnector.php on line 6 PHP Fatal error: main() [function.require]: Failed opening required 'SystemComponent.php' (include_path='.;c:\php4\pear') in d:\webspace\bradleystokejudoclub.co.uk\wwwroot\includes\DbConnector.php on line 6

     

    I took a wild guess at the system componant being the problem ... but heres the dbconnector code as well in case its that ...

     

    <?php
    ////////////////////////////////////////////////////////////////////////////////////////
    // Class: DbConnector
    // Purpose: Connect to a database, MySQL version
    ///////////////////////////////////////////////////////////////////////////////////////
    require_once 'SystemComponent.php';
    
    class DbConnector extends SystemComponent {
    
    var $theQuery;
    var $link;
    
    //*** Function: DbConnector, Purpose: Connect to the database ***
    function DbConnector(){
    
    // Load settings from parent class
    $settings = SystemComponent::getSettings();
    
    // Get the main settings from the array we just loaded
    $host = $settings['dbhost'];
    $db = $settings['dbname'];
    $user = $settings['dbusername'];
    $pass = $settings['dbpassword'];
    
    // Connect to the database
    $this->link = mysql_connect($host, $user, $pass);
    mysql_select_db($db);
    register_shutdown_function(array(&$this, 'close'));
    
    }
    
    //*** Function: query, Purpose: Execute a database query ***
    function query($query) {
    
    $this->theQuery = $query;
    return mysql_query($query, $this->link);
    
    }
    
    //*** Function: fetchArray, Purpose: Get array of query results ***
    function fetchArray($result) {
    
    return mysql_fetch_array($result);
    
    }
    
    //*** Function: close, Purpose: Close the connection ***
    function close() {
    
    mysql_close($this->link);
    
    }
    
    
    }
    ?>

     

    I think the problem is with the

    // System variables

    $settings['siteDir'] = '';

     

    But it doesn't tell me what to put here ... I gueesed at http://www.bradleystokejudoclub.co.uk but it didnt like it so I took it out again ..

     

    Any help would be most appreciated

     

    Thanks

     

    Gem

     

    PS: Please excuse any typos ... I'm working with one hand at the moment as I'm recovering from an operation :)

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.