Jump to content

Recommended Posts

Im having trouble with my code, whenever I press the next page (or '2') button on my website i get this error:

 

Notice: Undefined index: board in /users/csdipact2013/rs7/public_html/blogBoard.php on line 30

Notice: Undefined index: board in /users/csdipact2013/rs7/public_html/blogBoard.php on line 97

 

ERROR!

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND m.date = ( SELECT date FROM blogmessages WHERE blogthread_id = t' at line 8

The query was: SELECT t.blogthread_id, t.subject, u.userid, t.date as date1, u.fullname, m.date FROM blogthreads as t INNER JOIN blogmessages as m INNER JOIN fanmembers as u ON t.blogthread_id = m.blogthread_id AND t.userid = u.userid WHERE t.blog_id = AND m.date = ( SELECT date FROM blogmessages WHERE blogthread_id = t.blogthread_id ORDER BY date DESC LIMIT 0,1) ORDER BY m.date DESC LIMIT 2, 2

 

Any help would be greatly appreciated.

 

 
<?php

  //the title that will appear in the Windows window bar

   $pagetitle = 'Tyrconnell Blog: Board';

   //include the standard JEdward page header

   //the menu button that will be highlighted, showing where the user is

   $thispage = 'blog';

   //the standard bar of menu buttons

   include('donegalMenu.php');

   include('donegalHeader.html');

   echo '<body bgcolor="gold">

 </body>';
   /* *********************************************************

      Main content of the page

      *********************************************************

   */
   //check that the session has been properly started by a sign-in

   //if so, sets the $userid variable; otherwise kills the script

   //NOTE: this is replacing the cookie check we did last time

   include_once('SessionCheck.php');

  
  

   //connect to the database        

  $dbc = mysqli_connect('cs1.ucc.ie', 'rs7', 'shainiij', 'csdipact2013_rs7') OR die('Cannot connect'. mysqli_connect_error());
   $query = 'SELECT blog_name

             FROM blog

             WHERE blog_id=' . $_GET['board'];

   $result = mysqli_query($dbc, $query);


   if ($result)

   {

      $row = mysqli_fetch_array($result);

      echo '<p><Strong><font color="yellow" font size="5"> Tyrconnell Blog </strong></font> </p>';

      echo '<p><font color="green">Blog: ' . $row['blog_name'] . '</font></p>';

   if($_SESSION['userid'] == '4')

  // your variable equals 'yes' do something

   {

      echo '<p><a href="blogPost.php?board='

               . $_GET['board']

               . '"><font color="green">New Article</a></font></p>';

      }

      }

     

 

  

  

  

  

   $display = 2;

  

   if (isset($_GET['pages']) && is_numeric($_GET['pages']))

   {

      $pages = $_GET['pages'];

   }

   else //have to obtain the number from the database

   {

      $query = 'SELECT COUNT(f.blogthread_id) FROM blogthreads as f INNER JOIN blogmessages AS u

             ON f.blogthread_id = u.blogthread_id';

      $result = @mysqli_query($dbc, $query);

      $row = @mysqli_fetch_array($result);

      $records = $row[0];

     

      //echo '<p>I think there are ' . $records . ' records</p>';
      //now work out how many pages

      if ($records > $display)

      {

         $pages = ceil($records/$display);

      }

      else

      {

         $pages = 1;

      }

      mysqli_free_result($result);

   }
   if (isset($_GET['start']) && is_numeric($_GET['start']))

   {

      $start = $_GET['start'];

   }

   else

   {

      $start = 0;

   }

 

 

$query = 'SELECT t.blogthread_id, t.subject, u.userid, t.date as date1, u.fullname, m.date

FROM blogthreads as t

INNER JOIN blogmessages as m

INNER JOIN fanmembers as u

ON t.blogthread_id = m.blogthread_id

AND t.userid = u.userid

WHERE t.blog_id =' . $_GET['board'] . '

AND m.date = (

   SELECT date

   FROM blogmessages

   WHERE blogthread_id = t.blogthread_id

   ORDER BY date DESC

   LIMIT 0,1)

ORDER BY m.date DESC

LIMIT ' . $start . ', ' . $display;
$result = mysqli_query($dbc, $query);
   //if we got a non-null result, display the table

   if ($result)

   {

      $number = mysqli_num_rows($result);

      if ($number <1)

      {

         echo '<p>Sorry - no threads have been created on this blog yet</p>';

      }
      echo '<p><table cellpadding="3">

                 <tr>

                    <td><strong><font color="green">Subject</strong></font></td>

                    <td><strong><font color="green">Administrator</strong></font></td>

                    <td><strong><font color="green">Start Date</strong></font></td>

                    <td><strong><font color="green">Last Post</strong></font></td>

                 </tr>';

    

        //if there are any other pages of results, make links to them

 

      //we now want to display each row - we use a while since at this point we

      //dont know how many records we have

      $shade='#ffffff';

      while ($row = mysqli_fetch_array($result))

      {

         if ($shade=='#ffffff')

        {

           $shade='#eeeeee';

        }

        else

        {

           $shade='#ffffff';

        }

         echo '<tr bgcolor="' . $shade . '">

                  <td><font color="green"><a href="blogThread.php?board='

                                     . $_GET['board'] . '&thread='

                                     . $row['blogthread_id'] . '">'

                                     . $row['subject'] . '</a></font></td>

                  <td><font color="green"><a href="blogUserMsg.php?userid='

                                     . $row['userid'] . '">'

                                     . $row['fullname'] . '</a></font></td>

                  <td><font color="green">' . $row['date1'] . '</font></td>

           <td><font color="green">' . $row['date'] . '</font></td>

        </tr>';

      }

      echo '</table></p>';

      //free up the resource used for the query

      mysqli_free_result($result);

   }

   else

   {

      //something went wrong

      echo '<p class="error">ERROR!</p>';
      echo '<p>' . mysqli_error($dbc) . '</p>';

      echo '<p>' . 'The query was: ' . $query . '</p>';

   }
   //close the database

   mysqli_close($dbc);

  

   if ($pages > 1)

   {

      //find the current page

      $current_page = ($start/$display) + 1;
      if ($current_page != 1)

      {

         echo '<a href="blogBoard.php?start='

                           . ($start - $display)

                           . '&pages=' . $pages

                           .  '">Previous</a> ';

      }
      //show a list of all numbered pages

      for ($i=1; $i <= $pages; $i++)

      {

         if ($i != $current_page)

         {

            echo '<a href="blogBoard.php?start='

                            . (($display * ($i - 1)))

       . '&pages=' . $pages

       . '">' . $i . '</a> ';

         }

         else

         {

            echo $i . ' ';

         }

      } 
      //if the current page is not the last, then we need a nextbutton

      if ($current_page != $pages)

      {

         echo '<a href="blogBoard.php?start='

                         . ($start + $display)

                   . '&pages=' . $pages

           . '">Next</a>';

      }
      echo '</p>';

   }  //end if $pages > 1

  

  
   /* *********************************************************

      End of main content of the page

      *********************************************************

   */

  

   //include the standard footer information

   include('donegalFooter.html');

?>
Link to comment
https://forums.phpfreaks.com/topic/276223-fixed-number-of-records-per-page/
Share on other sites

Do you not understand what a $_GET variable is? For you pagination to work the link for the next page button would need to pass the required variables accross with it, in this case 'board',http pages are stateless :

http://www.mypage.com/page?board=12&somethingelse=something

 

if you dont pass that into the page then $_GET['board'] wont be populated

What would I have to do to pass it?

 

You've passed the value in some links (see code at the end). As gristoi mentioned, you just need to do the same for your page links.

 
 
Side note: data being passed through GET variables needs to be validated / sanitized. As far as I can tell, I don't see that happening in the script. Since the information isn't being cleaned, the potential for someone to inject code into your SQL query(ies)...or tamper with your page since the variables are being displayed back to the screen.
 
 

 

echo '<p><a href="blogPost.php?board='
 
               . $_GET['board']
 
               . '"><font color="green">New Article</a></font></p>';
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.