473,788 Members | 2,706 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

I cannot understand why php flags up certain code that used elsewhere is fine

22 New Member
Hi, I am using PHP and mysql to create a website.
I am fairly new to PHP, and thus am grateful to anyone who helps!


Firstly I am running a homepage, that displays additional content if a user has logged in. I set a loggedin session in the log in page, which I have tested and works fine in other scripts.
I am displaying news on the homepage (which is stored in a mysql database), and this works fine when the user accesses the homepage without having logged on.
It displays the date sent, the subject, and who sent it and eventually have a link to a single file to view everything about the message, as well as the message itself.
This works fine when viewed by someone who has not logged in, and displays what it should. However when someone views the page having logged in (the weird thing is that I copied and pasted the code, only changing one filename to avoid requiring two files that declared the same function, escape_data), it displays the following error messages:

Warning: mysql_fetch_arr ay(): supplied argument is not a valid MySQL result resource in C:\Users\Harry\ Documents\Web development\wam p\www\Website\h tml\home.php on line 346

Warning: mysql_fetch_arr ay(): supplied argument is not a valid MySQL result resource in C:\Users\Harry\ Documents\Web development\wam p\www\Website\h tml\home.php on line 518

Warning: mysql_free_resu lt(): supplied argument is not a valid MySQL result resource in C:\Users\Harry\ Documents\Web development\wam p\www\Website\h tml\home.php on line 544

I have been stuck on this for a long time now, as I usually prefer to solve problems myself if I can.

Here is my main code (I have not shown the code for the other files referred to, as I have used them for other things and now that they work):

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3.  
  4. <?php
  5.  
  6.    $page_title = 'Homepage';
  7.    $loggedin = $_SESSION['loggedin'];
  8.    if ($loggedin != NULL) //then run non logged in homepage
  9.    {
  10. include ('./includes/header.html');
  11. ?>
  12.  
  13. <p><h3>News</h3></p> 
  14. <?php
  15.  
  16.  
  17. require_once ('../mysql_connectnews.php'); 
  18. // Number of records to show per page:
  19.  
  20. $display = 7;
  21.  
  22.  
  23. // Determine how many pages there are. 
  24.  
  25.     if (isset($_GET['np'])) 
  26.     { // Already been determined.
  27.  
  28.  
  29.     $num_pages = $_GET['np'];
  30.  
  31.     else { // Need to determine.
  32.  
  33.  
  34.      // Count the number of records
  35.  
  36.     $query = "SELECT COUNT(*) FROM news ORDER BY datesent ASC";
  37.  
  38.     $result = @mysql_query ($query);
  39.  
  40.     $row = mysql_fetch_array ($result, MYSQL_NUM);
  41.  
  42.     $num_records = $row[0];
  43.  
  44.  
  45. // Calculate the number of pages.
  46.  
  47.         if ($num_records > $display)
  48.         { // More than 1 page.
  49.  
  50.         $num_pages = ceil ($num_records/$display);}
  51.  
  52.  
  53.          else {
  54.  
  55.         $num_pages = 1;
  56.     }
  57.  
  58.  
  59.  
  60. } // End of np IF.
  61.  
  62.  
  63. // Determine where in the database to start returning results.
  64.  
  65.  
  66.     if (isset($_GET['s']))
  67.      {
  68.     $start = $_GET['s'];
  69. }
  70.  
  71.      else 
  72.     {
  73.     $start = 0;
  74. }
  75.  
  76.  
  77.  
  78.     // Default column links.
  79.  
  80. $link1 = "{$_SERVER['PHP_SELF']}?sort=lna";
  81.  
  82. $link2 = "{$_SERVER['PHP_SELF']}?sort=fna";
  83.  
  84. $link3 = "{$_SERVER['PHP_SELF']}?sort=dra";
  85.  
  86.  
  87. // Determine the sorting order.
  88.  
  89.  
  90. if (isset($_GET['sort'])) 
  91.     {
  92.  
  93.     // Use existing sorting order.
  94.  
  95.  
  96.     switch ($_GET['sort']) {
  97.  
  98.  
  99.     case 'lna':
  100.  
  101.     $order_by = 'datesent ASC';
  102.  
  103.     $link1 = "{$_SERVER['PHP_SELF']}?sort=lnd";
  104.  
  105.     break;
  106.  
  107.  
  108.     case 'lnd':
  109.  
  110.     $order_by = 'datesent DESC';
  111.  
  112.     $link1 = "{$_SERVER['PHP_SELF']}?sort=lna";
  113.  
  114.     break;
  115.  
  116.  
  117.     case 'fna':
  118.  
  119.     $order_by = 'fromwhom ASC';
  120.  
  121.     $link2 = "{$_SERVER['PHP_SELF']}?sort=fnd";
  122.  
  123.     break;
  124.  
  125.     case 'fnd':
  126.  
  127.     $order_by = 'fromwhom DESC';
  128.  
  129.     $link2 = "{$_SERVER['PHP_SELF']}?sort=fna";
  130.  
  131.     break;
  132.  
  133.  
  134.     case 'dra':
  135.  
  136.     $order_by = 'subject ASC';
  137.  
  138.     $link3 = "{$_SERVER['PHP_SELF']}?sort=drd";
  139.  
  140.     break;
  141.  
  142.  
  143.     case 'drd':
  144.  
  145.     $order_by = 'subject DESC';
  146.  
  147.     $link3 = "{$_SERVER['PHP_SELF']}?sort=dra";
  148.  
  149.     break;
  150.  
  151.     default:
  152.  
  153.     $order_by = 'datesent DESC';
  154.  
  155.     break;
  156.     }
  157.  
  158.  
  159.  
  160.     // $sort will be appended to the pagination links.
  161.  
  162.     $sort = $_GET['sort'];
  163.  
  164.     else { // Use the default sorting order.
  165.  
  166.     $order_by = 'datesent DESC';
  167.  
  168.     $sort = 'drd';
  169. }
  170.  
  171.  
  172.  
  173.  
  174.     // Make the query.
  175.  
  176.     $query = "SELECT datesent, fromwhom, subject AS dr, message FROM users ORDER BY     $order_by LIMIT $start, $display";        
  177.         $result = @mysql_query ($query);
  178.      // Run the query.
  179.  
  180.  
  181.  
  182. // Make the query.
  183.  
  184.     $query = "SELECT datesent, fromwhom, subject AS dr, message FROM news ORDER BY     $order_by LIMIT $start, $display";        
  185.         $result = @mysql_query ($query);
  186.      // Run the query.
  187.  
  188.  
  189.  
  190. //Table header.
  191.  
  192. echo '<table align="center" cellspacing="0" cellpadding="5">
  193. <tr>
  194.  
  195.  
  196.             <td align="left"><b><a href="' . $link1 . '">Date sent</a></b></td>
  197.     <td         align="left"><b><a href="' . $link2 . '">From whom</a></b></td>
  198.     <td         align="left"><b><a href="' . $link3 . '">Subject</a></b></td>
  199.         <td         align="left"><b>Message</b></td>
  200.  
  201. </tr>
  202. ';
  203.  
  204.  
  205.  
  206. // Fetch and print all the records.
  207.  
  208.     $bg = '#eeeeee'; 
  209.     // Set the background color.
  210.  
  211. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
  212.  
  213.         $bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee'); 
  214.         // Switch the background color.
  215.  
  216.         echo '<tr bgcolor="' . 
  217.         $bg . '">
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228.         <td align="left">' . $row['datesent'] . ' </td>
  229.         <td align="left">' . $row['fromwhom'] . '</td>
  230.                 <td align="left">' . $row['dr'] . '</td>
  231.                 <td align="left">//here is where I insert the code for a link to allow someone to view the message stored in the database, it
  232.                 // could be stored in the url I suppose, but then I will need to formulate code which would allow me to read it and create a page displaying from whom
  233.                 // the message was from, the subject, the time sent, and the full message itself
  234.                 </td>
  235.     </tr>
  236.     ';
  237. }
  238.  
  239. echo '</table>';
  240.  
  241. mysql_free_result ($result); // Free up the resources.    
  242.  
  243. mysql_close(); // Close the database connection.
  244.  
  245. // Make the links to other pages, if necessary.
  246. if ($num_pages > 1) {
  247.  
  248.     echo '<br /><p>';
  249.     // Determine what page the script is on.    
  250.     $current_page = ($start/$display) + 1;
  251.  
  252.     // If it's not the first page, make a Previous button.
  253.     if ($current_page != 1) {
  254.         echo '<a href="home.php?s=' . ($start - $display) . '&np=' . $num_pages . '&sort=' . $sort .'">Previous</a> ';
  255.     }
  256.  
  257.     // Make all the numbered pages.
  258.     for ($i = 1; $i <= $num_pages; $i++) {
  259.         if ($i != $current_page) {
  260.             echo '<a href="home.php?s=' . (($display * ($i - 1))) . '&np=' . $num_pages . '&sort=' . $sort .'">' . $i . '</a> ';
  261.         } else {
  262.             echo $i . ' ';
  263.         }
  264.     }
  265.  
  266.     // If it's not the last page, make a Next button.
  267.     if ($current_page != $num_pages) {
  268.         echo '<a href="home.php?s=' . ($start + $display) . '&np=' . $num_pages . '&sort=' . $sort .'">Next</a>';
  269.     }
  270.  
  271.     echo '</p>';
  272.  
  273. } // End of links section.
  274. include ('./includes/footer.html');
  275. } //end of if not logged in
  276.  
  277.  
  278.  
  279.  
  280.  
  281.  
  282. else { //start of else logged in
  283.  
  284.  
  285. $page_title = 'Homepage';
  286.  
  287.  
  288. require_once ('.../mysql_connectusers.php');
  289.  
  290.  
  291. include ('./includes/headerloggedin.html');
  292. $u = $_SESSION['username']; 
  293.  
  294.  
  295.  
  296. $query = "SELECT ID,
  297.      email FROM users WHERE 
  298.     (username='$u')";
  299.  
  300. $result = mysql_query ($query) or 
  301.     trigger_error("Query: $query\n<br />
  302.     MySQL Error: " . mysql_error());
  303.  
  304.  
  305. $row = mysql_fetch_array($result, MYSQL_NUM);
  306.  
  307.         mysql_free_result($result);
  308.  
  309.  
  310.         mysql_close();    
  311.  
  312.  
  313.  
  314. if ($email == NULL) {
  315. echo '<p> You need to set your email address 
  316. <a href="./set_emailloggedin.php">here</a> in order that if you forget your password at some point in the future it can be sent to you.</p>';
  317. }    
  318.  
  319. ?>
  320.  
  321. <p><h3>News</h3></p> 
  322. <?php
  323.  
  324.  
  325. require_once ('../mysql_connectnewswithoutfunction.php'); 
  326. // Number of records to show per page:
  327.  
  328. $display = 7;
  329.  
  330.  
  331. // Determine how many pages there are. 
  332.  
  333.     if (isset($_GET['np'])) 
  334.     { // Already been determined.
  335.  
  336.  
  337.     $num_pages = $_GET['np'];
  338.  
  339.     else { // Need to determine.
  340.  
  341.  
  342.      // Count the number of records
  343.  
  344.     $query = "SELECT COUNT(*) FROM news ORDER BY datesent ASC";
  345.  
  346.     $result = @mysql_query ($query);
  347.  
  348.     $row = mysql_fetch_array ($result, MYSQL_NUM);
  349.  
  350.     $num_records = $row[0];
  351.  
  352.  
  353. // Calculate the number of pages.
  354.  
  355.         if ($num_records > $display)
  356.         { // More than 1 page.
  357.  
  358.         $num_pages = ceil ($num_records/$display);}
  359.  
  360.  
  361.          else {
  362.  
  363.         $num_pages = 1;
  364.     }
  365.  
  366.  
  367.  
  368. } // End of np IF.
  369.  
  370.  
  371. // Determine where in the database to start returning results.
  372.  
  373.  
  374.     if (isset($_GET['s']))
  375.      {
  376.     $start = $_GET['s'];
  377. }
  378.  
  379.      else 
  380.     {
  381.     $start = 0;
  382. }
  383.  
  384.  
  385.  
  386.     // Default column links.
  387.  
  388. $link1 = "{$_SERVER['PHP_SELF']}?sort=lna";
  389.  
  390. $link2 = "{$_SERVER['PHP_SELF']}?sort=fna";
  391.  
  392. $link3 = "{$_SERVER['PHP_SELF']}?sort=dra";
  393.  
  394.  
  395. // Determine the sorting order.
  396.  
  397.  
  398. if (isset($_GET['sort'])) 
  399.     {
  400.  
  401.     // Use existing sorting order.
  402.  
  403.  
  404.     switch ($_GET['sort']) {
  405.  
  406.  
  407.     case 'lna':
  408.  
  409.     $order_by = 'datesent ASC';
  410.  
  411.     $link1 = "{$_SERVER['PHP_SELF']}?sort=lnd";
  412.  
  413.     break;
  414.  
  415.  
  416.     case 'lnd':
  417.  
  418.     $order_by = 'datesent DESC';
  419.  
  420.     $link1 = "{$_SERVER['PHP_SELF']}?sort=lna";
  421.  
  422.     break;
  423.  
  424.  
  425.     case 'fna':
  426.  
  427.     $order_by = 'fromwhom ASC';
  428.  
  429.     $link2 = "{$_SERVER['PHP_SELF']}?sort=fnd";
  430.  
  431.     break;
  432.  
  433.     case 'fnd':
  434.  
  435.     $order_by = 'fromwhom DESC';
  436.  
  437.     $link2 = "{$_SERVER['PHP_SELF']}?sort=fna";
  438.  
  439.     break;
  440.  
  441.  
  442.     case 'dra':
  443.  
  444.     $order_by = 'subject ASC';
  445.  
  446.     $link3 = "{$_SERVER['PHP_SELF']}?sort=drd";
  447.  
  448.     break;
  449.  
  450.  
  451.     case 'drd':
  452.  
  453.     $order_by = 'subject DESC';
  454.  
  455.     $link3 = "{$_SERVER['PHP_SELF']}?sort=dra";
  456.  
  457.     break;
  458.  
  459.     default:
  460.  
  461.     $order_by = 'datesent DESC';
  462.  
  463.     break;
  464.     }
  465.  
  466.  
  467.  
  468.     // $sort will be appended to the pagination links.
  469.  
  470.     $sort = $_GET['sort'];
  471.  
  472.     else { // Use the default sorting order.
  473.  
  474.     $order_by = 'datesent DESC';
  475.  
  476.     $sort = 'drd';
  477. }
  478.  
  479.  
  480.  
  481.  
  482.     // Make the query.
  483.  
  484.     $query = "SELECT datesent, fromwhom, subject AS dr, message FROM users ORDER BY     $order_by LIMIT $start, $display";        
  485.         $result = @mysql_query ($query);
  486.      // Run the query.
  487.  
  488.  
  489.  
  490. // Make the query.
  491.  
  492.     $query = "SELECT datesent, fromwhom, subject AS dr, message FROM news ORDER BY     $order_by LIMIT $start, $display";        
  493.         $result = @mysql_query ($query);
  494.      // Run the query.
  495.  
  496.  
  497.  
  498. //Table header.
  499.  
  500. echo '<table align="center" cellspacing="0" cellpadding="5">
  501. <tr>
  502.  
  503.  
  504.             <td align="left"><b><a href="' . $link1 . '">Date sent</a></b></td>
  505.     <td         align="left"><b><a href="' . $link2 . '">From whom</a></b></td>
  506.     <td         align="left"><b><a href="' . $link3 . '">Subject</a></b></td>
  507.         <td         align="left"><b>Message</b></td>
  508.  
  509. </tr>
  510. ';
  511.  
  512.  
  513.  
  514. // Fetch and print all the records.
  515.  
  516.     $bg = '#eeeeee'; 
  517.     // Set the background color.
  518.  
  519. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
  520.  
  521.         $bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee'); 
  522.         // Switch the background color.
  523.  
  524.         echo '<tr bgcolor="' . 
  525.         $bg . '">
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.  
  533.  
  534.  
  535.  
  536.         <td align="left">' . $row['datesent'] . ' </td>
  537.         <td align="left">' . $row['fromwhom'] . '</td>
  538.                 <td align="left">' . $row['dr'] . '</td>
  539.                 <td align="left">
  540.                 </td>//here is where I insert the code for a link to allow someone to view the message stored in the database, it
  541.                 // could be stored in the url I suppose, but then I will need to formulate code which would allow me to read it and create a page displaying from whom
  542.                 // the message was from, the subject, the time sent, and the full message itself
  543.                 </td>
  544.     </tr>
  545.     ';
  546. }
  547.  
  548. echo '</table>';
  549.  
  550. mysql_free_result ($result); // Free up the resources.    
  551.  
  552. mysql_close(); // Close the database connection.
  553.  
  554. // Make the links to other pages, if necessary.
  555. if ($num_pages > 1) {
  556.  
  557.     echo '<br /><p>';
  558.     // Determine what page the script is on.    
  559.     $current_page = ($start/$display) + 1;
  560.  
  561.     // If it's not the first page, make a Previous button.
  562.     if ($current_page != 1) {
  563.         echo '<a href="home.php?s=' . ($start - $display) . '&np=' . $num_pages . '&sort=' . $sort .'">Previous</a> ';
  564.     }
  565.  
  566.     // Make all the numbered pages.
  567.     for ($i = 1; $i <= $num_pages; $i++) {
  568.         if ($i != $current_page) {
  569.             echo '<a href="home.php?s=' . (($display * ($i - 1))) . '&np=' . $num_pages . '&sort=' . $sort .'">' . $i . '</a> ';
  570.         } else {
  571.             echo $i . ' ';
  572.         }
  573.     }
  574.  
  575.     // If it's not the last page, make a Next button.
  576.     if ($current_page != $num_pages) {
  577.         echo '<a href="home.php?s=' . ($start + $display) . '&np=' . $num_pages . '&sort=' . $sort .'">Next</a>';
  578.     }
  579.  
  580.     echo '</p>';
  581.  
  582. } // End of links section.
  583.  
  584.  
  585. // Include the HTML footer file.
  586.  
  587. include ('./includes/footer.html');
  588.  
  589.  
  590. } //end of else logged in
  591. ?>
  592.  
Thanks to anyone who helps,
Harry
Dec 14 '07 #1
3 1949
Hazza
22 New Member
I have updated the code slightly (adding in a line for the table, and adding to the queries) which shouldn't affect the rest of the script, however now I get the error messages displayed before just when logged in (see previous post)!

Here is the new code
Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. <?php
  4.  
  5.    $page_title = 'Homepage';
  6.    $loggedin = $_SESSION['loggedin'];
  7.    if ($loggedin != NULL) //then run non logged in homepage
  8.    {
  9. include ('./includes/header.html');
  10. ?>
  11.  
  12. <p><h3>News</h3></p> 
  13. <?php
  14.  
  15.  
  16. require_once ('../mysql_connectnews.php'); 
  17. // Number of records to show per page:
  18.  
  19. $display = 7;
  20.  
  21.  
  22. // Determine how many pages there are. 
  23.  
  24.     if (isset($_GET['np'])) 
  25.     { // Already been determined.
  26.  
  27.  
  28.     $num_pages = $_GET['np'];
  29.  
  30.     else { // Need to determine.
  31.  
  32.  
  33.      // Count the number of records
  34.  
  35.     $query = "SELECT COUNT(*) FROM news ORDER BY datesent ASC";
  36.  
  37.     $result = @mysql_query ($query);
  38.  
  39.     $row = mysql_fetch_array ($result, MYSQL_NUM);
  40.  
  41.     $num_records = $row[0];
  42.  
  43.  
  44. // Calculate the number of pages.
  45.  
  46.         if ($num_records > $display)
  47.         { // More than 1 page.
  48.  
  49.         $num_pages = ceil ($num_records/$display);}
  50.  
  51.  
  52.          else {
  53.  
  54.         $num_pages = 1;
  55.     }
  56.  
  57.  
  58.  
  59. } // End of np IF.
  60.  
  61.  
  62. // Determine where in the database to start returning results.
  63.  
  64.  
  65.     if (isset($_GET['s']))
  66.      {
  67.     $start = $_GET['s'];
  68. }
  69.  
  70.      else 
  71.     {
  72.     $start = 0;
  73. }
  74.  
  75.  
  76.  
  77.     // Default column links.
  78.  
  79. $link1 = "{$_SERVER['PHP_SELF']}?sort=lna";
  80.  
  81. $link2 = "{$_SERVER['PHP_SELF']}?sort=fna";
  82.  
  83. $link3 = "{$_SERVER['PHP_SELF']}?sort=dra";
  84.  
  85.  
  86. // Determine the sorting order.
  87.  
  88.  
  89. if (isset($_GET['sort'])) 
  90.     {
  91.  
  92.     // Use existing sorting order.
  93.  
  94.  
  95.     switch ($_GET['sort']) {
  96.  
  97.  
  98.     case 'lna':
  99.  
  100.     $order_by = 'datesent ASC';
  101.  
  102.     $link1 = "{$_SERVER['PHP_SELF']}?sort=lnd";
  103.  
  104.     break;
  105.  
  106.  
  107.     case 'lnd':
  108.  
  109.     $order_by = 'datesent DESC';
  110.  
  111.     $link1 = "{$_SERVER['PHP_SELF']}?sort=lna";
  112.  
  113.     break;
  114.  
  115.  
  116.     case 'fna':
  117.  
  118.     $order_by = 'fromwhom ASC';
  119.  
  120.     $link2 = "{$_SERVER['PHP_SELF']}?sort=fnd";
  121.  
  122.     break;
  123.  
  124.     case 'fnd':
  125.  
  126.     $order_by = 'fromwhom DESC';
  127.  
  128.     $link2 = "{$_SERVER['PHP_SELF']}?sort=fna";
  129.  
  130.     break;
  131.  
  132.  
  133.     case 'dra':
  134.  
  135.     $order_by = 'subject ASC';
  136.  
  137.     $link3 = "{$_SERVER['PHP_SELF']}?sort=drd";
  138.  
  139.     break;
  140.  
  141.  
  142.     case 'drd':
  143.  
  144.     $order_by = 'subject DESC';
  145.  
  146.     $link3 = "{$_SERVER['PHP_SELF']}?sort=dra";
  147.  
  148.     break;
  149.  
  150.     default:
  151.  
  152.     $order_by = 'datesent DESC';
  153.  
  154.     break;
  155.     }
  156.  
  157.  
  158.  
  159.     // $sort will be appended to the pagination links.
  160.  
  161.     $sort = $_GET['sort'];
  162.  
  163.     else { // Use the default sorting order.
  164.  
  165.     $order_by = 'datesent DESC';
  166.  
  167.     $sort = 'drd';
  168. }
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177. // Make the query.
  178.  
  179.     $query = "SELECT datesent, fromwhom, subject AS dr, message, newsid FROM news ORDER BY $order_by LIMIT $start, $display";        
  180.         $result = @mysql_query ($query);
  181.      // Run the query.
  182.  
  183.  
  184.  
  185. //Table header.
  186.  
  187. echo '<table align="center" cellspacing="0" cellpadding="5">
  188. <tr>
  189.  
  190.  
  191.             <td align="left"><b><a href="' . $link1 . '">Date sent</a></b></td>
  192.     <td         align="left"><b><a href="' . $link2 . '">From whom</a></b></td>
  193.     <td         align="left"><b><a href="' . $link3 . '">Subject</a></b></td>
  194.         <td         align="left"><b>Message</b></td>
  195.  
  196. </tr>
  197. ';
  198.  
  199.  
  200.  
  201. // Fetch and print all the records.
  202.  
  203.     $bg = '#eeeeee'; 
  204.     // Set the background color.
  205.  
  206. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
  207.  
  208.         $bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee'); 
  209.         // Switch the background color.
  210.  
  211.         echo '<tr bgcolor="' . 
  212.         $bg . '">
  213.  
  214.  
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221.  
  222.  
  223.         <td align="left">' . $row['datesent'] . ' </td>
  224.         <td align="left">' . $row['fromwhom'] . '</td>
  225.                 <td align="left">' . $row['dr'] . '</td>
  226.                 <td align="left">//here is where I insert the code for a link to allow someone to view the message stored in the database, it
  227.                 // could be stored in the url I suppose, but then I will need to formulate code which would allow me to read it and create a page displaying from whom
  228.                 // the message was from, the subject, the time sent, and the full message itself
  229.  
  230.                 <a href="viewmessage.php?id=' . $row['newsid'] . '">View news item</a>
  231.  
  232.  
  233.                 </td>
  234.     </tr>
  235.     ';
  236. }
  237.  
  238. echo '</table>';
  239.  
  240. mysql_free_result ($result); // Free up the resources.    
  241.  
  242. mysql_close(); // Close the database connection.
  243.  
  244. // Make the links to other pages, if necessary.
  245. if ($num_pages > 1) {
  246.  
  247.     echo '<br /><p>';
  248.     // Determine what page the script is on.    
  249.     $current_page = ($start/$display) + 1;
  250.  
  251.     // If it's not the first page, make a Previous button.
  252.     if ($current_page != 1) {
  253.         echo '<a href="home.php?s=' . ($start - $display) . '&np=' . $num_pages . '&sort=' . $sort .'">Previous</a> ';
  254.     }
  255.  
  256.     // Make all the numbered pages.
  257.     for ($i = 1; $i <= $num_pages; $i++) {
  258.         if ($i != $current_page) {
  259.             echo '<a href="home.php?s=' . (($display * ($i - 1))) . '&np=' . $num_pages . '&sort=' . $sort .'">' . $i . '</a> ';
  260.         } else {
  261.             echo $i . ' ';
  262.         }
  263.     }
  264.  
  265.     // If it's not the last page, make a Next button.
  266.     if ($current_page != $num_pages) {
  267.         echo '<a href="home.php?s=' . ($start + $display) . '&np=' . $num_pages . '&sort=' . $sort .'">Next</a>';
  268.     }
  269.  
  270.     echo '</p>';
  271.  
  272. } // End of links section.
  273. include ('./includes/footer.html');
  274. } //end of if not logged in
  275.  
  276.  
  277.  
  278.  
  279.  
  280.  
  281. else { //start of else logged in
  282.  
  283.  
  284. $page_title = 'Homepage';
  285.  
  286.  
  287. require_once ('.../mysql_connectusers.php');
  288.  
  289.  
  290. include ('./includes/headerloggedin.html');
  291. $u = $_SESSION['username']; 
  292.  
  293.  
  294.  
  295. $query = "SELECT ID,
  296.      email FROM users WHERE 
  297.     (username='$u')";
  298.  
  299. $result = mysql_query ($query) or 
  300.     trigger_error("Query: $query\n<br />
  301.     MySQL Error: " . mysql_error());
  302.  
  303.  
  304. $row = mysql_fetch_array($result, MYSQL_NUM);
  305.  
  306.         mysql_free_result($result);
  307.  
  308.  
  309.         mysql_close();    
  310.  
  311.  
  312.  
  313. if ($email == NULL) {
  314. echo '<p> You need to set your email address 
  315. <a href="./set_emailloggedin.php">here</a> in order that if you forget your password at some point in the future it can be sent to you.</p>';
  316. }    
  317.  
  318. ?>
  319.  
  320. <p><h3>News</h3></p> 
  321. <?php
  322.  
  323.  
  324. require_once ('../mysql_connectnewswithoutfunction.php'); 
  325. // Number of records to show per page:
  326.  
  327. $display = 7;
  328.  
  329.  
  330. // Determine how many pages there are. 
  331.  
  332.     if (isset($_GET['np'])) 
  333.     { // Already been determined.
  334.  
  335.  
  336.     $num_pages = $_GET['np'];
  337.  
  338.     else { // Need to determine.
  339.  
  340.  
  341.      // Count the number of records
  342.  
  343.     $query = "SELECT COUNT(*) FROM news ORDER BY datesent ASC";
  344.  
  345.     $result = @mysql_query ($query);
  346.  
  347.     $row = mysql_fetch_array ($result, MYSQL_NUM);
  348.  
  349.     $num_records = $row[0];
  350.  
  351.  
  352. // Calculate the number of pages.
  353.  
  354.         if ($num_records > $display)
  355.         { // More than 1 page.
  356.  
  357.         $num_pages = ceil ($num_records/$display);}
  358.  
  359.  
  360.          else {
  361.  
  362.         $num_pages = 1;
  363.     }
  364.  
  365.  
  366.  
  367. } // End of np IF.
  368.  
  369.  
  370. // Determine where in the database to start returning results.
  371.  
  372.  
  373.     if (isset($_GET['s']))
  374.      {
  375.     $start = $_GET['s'];
  376. }
  377.  
  378.      else 
  379.     {
  380.     $start = 0;
  381. }
  382.  
  383.  
  384.  
  385.     // Default column links.
  386.  
  387. $link1 = "{$_SERVER['PHP_SELF']}?sort=lna";
  388.  
  389. $link2 = "{$_SERVER['PHP_SELF']}?sort=fna";
  390.  
  391. $link3 = "{$_SERVER['PHP_SELF']}?sort=dra";
  392.  
  393.  
  394. // Determine the sorting order.
  395.  
  396.  
  397. if (isset($_GET['sort'])) 
  398.     {
  399.  
  400.     // Use existing sorting order.
  401.  
  402.  
  403.     switch ($_GET['sort']) {
  404.  
  405.  
  406.     case 'lna':
  407.  
  408.     $order_by = 'datesent ASC';
  409.  
  410.     $link1 = "{$_SERVER['PHP_SELF']}?sort=lnd";
  411.  
  412.     break;
  413.  
  414.  
  415.     case 'lnd':
  416.  
  417.     $order_by = 'datesent DESC';
  418.  
  419.     $link1 = "{$_SERVER['PHP_SELF']}?sort=lna";
  420.  
  421.     break;
  422.  
  423.  
  424.     case 'fna':
  425.  
  426.     $order_by = 'fromwhom ASC';
  427.  
  428.     $link2 = "{$_SERVER['PHP_SELF']}?sort=fnd";
  429.  
  430.     break;
  431.  
  432.     case 'fnd':
  433.  
  434.     $order_by = 'fromwhom DESC';
  435.  
  436.     $link2 = "{$_SERVER['PHP_SELF']}?sort=fna";
  437.  
  438.     break;
  439.  
  440.  
  441.     case 'dra':
  442.  
  443.     $order_by = 'subject ASC';
  444.  
  445.     $link3 = "{$_SERVER['PHP_SELF']}?sort=drd";
  446.  
  447.     break;
  448.  
  449.  
  450.     case 'drd':
  451.  
  452.     $order_by = 'subject DESC';
  453.  
  454.     $link3 = "{$_SERVER['PHP_SELF']}?sort=dra";
  455.  
  456.     break;
  457.  
  458.     default:
  459.  
  460.     $order_by = 'datesent DESC';
  461.  
  462.     break;
  463.     }
  464.  
  465.  
  466.  
  467.     // $sort will be appended to the pagination links.
  468.  
  469.     $sort = $_GET['sort'];
  470.  
  471.     else { // Use the default sorting order.
  472.  
  473.     $order_by = 'datesent DESC';
  474.  
  475.     $sort = 'drd';
  476. }
  477.  
  478.  
  479.  
  480.  
  481.  
  482.  
  483.  
  484.  
  485. // Make the query.
  486.  
  487.     $query = "SELECT datesent, fromwhom, subject AS dr, message, newsid FROM news ORDER BY $order_by LIMIT $start, $display";        
  488.         $result = @mysql_query ($query);
  489.      // Run the query.
  490.  
  491.  
  492.  
  493. //Table header.
  494.  
  495. echo '<table align="center" cellspacing="0" cellpadding="5">
  496. <tr>
  497.  
  498.  
  499.             <td align="left"><b><a href="' . $link1 . '">Date sent</a></b></td>
  500.     <td         align="left"><b><a href="' . $link2 . '">From whom</a></b></td>
  501.     <td         align="left"><b><a href="' . $link3 . '">Subject</a></b></td>
  502.         <td         align="left"><b>Message</b></td>
  503.  
  504. </tr>
  505. ';
  506.  
  507.  
  508.  
  509. // Fetch and print all the records.
  510.  
  511.     $bg = '#eeeeee'; 
  512.     // Set the background color.
  513.  
  514. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
  515.  
  516.         $bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee'); 
  517.         // Switch the background color.
  518.  
  519.         echo '<tr bgcolor="' . 
  520.         $bg . '">
  521.  
  522.  
  523.  
  524.  
  525.  
  526.  
  527.  
  528.  
  529.  
  530.  
  531.         <td align="left">' . $row['datesent'] . ' </td>
  532.         <td align="left">' . $row['fromwhom'] . '</td>
  533.                 <td align="left">' . $row['dr'] . '</td>
  534.                 <td align="left">
  535.                 </td>//here is where I insert the code for a link to allow someone to view the message stored in the database, it
  536.                 // could be stored in the url I suppose, but then I will need to formulate code which would allow me to read it and create a page displaying from whom
  537.                 // the message was from, the subject, the time sent, and the full message itself
  538.  
  539.  
  540.                 <a href="viewmessage.php?id=' . $row['newsid'] . '">View news item</a>
  541.                 </td>
  542.     </tr>
  543.     ';
  544. }
  545.  
  546. echo '</table>';
  547.  
  548. mysql_free_result ($result); // Free up the resources.    
  549.  
  550. mysql_close(); // Close the database connection.
  551.  
  552. // Make the links to other pages, if necessary.
  553. if ($num_pages > 1) {
  554.  
  555.     echo '<br /><p>';
  556.     // Determine what page the script is on.    
  557.     $current_page = ($start/$display) + 1;
  558.  
  559.     // If it's not the first page, make a Previous button.
  560.     if ($current_page != 1) {
  561.         echo '<a href="home.php?s=' . ($start - $display) . '&np=' . $num_pages . '&sort=' . $sort .'">Previous</a> ';
  562.     }
  563.  
  564.     // Make all the numbered pages.
  565.     for ($i = 1; $i <= $num_pages; $i++) {
  566.         if ($i != $current_page) {
  567.             echo '<a href="home.php?s=' . (($display * ($i - 1))) . '&np=' . $num_pages . '&sort=' . $sort .'">' . $i . '</a> ';
  568.         } else {
  569.             echo $i . ' ';
  570.         }
  571.     }
  572.  
  573.     // If it's not the last page, make a Next button.
  574.     if ($current_page != $num_pages) {
  575.         echo '<a href="home.php?s=' . ($start + $display) . '&np=' . $num_pages . '&sort=' . $sort .'">Next</a>';
  576.     }
  577.  
  578.     echo '</p>';
  579.  
  580. } // End of links section.
  581.  
  582.  
  583. // Include the HTML footer file.
  584.  
  585. include ('./includes/footer.html');
  586.  
  587.  
  588. } //end of else logged in
  589. ?>
  590.  
Thanks to anyone who helps,
Harry
Dec 14 '07 #2
Hazza
22 New Member
I have further edited the code, and it is back to the state (error wise) of the first script.

Here it is
Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. <?php
  4.  
  5.    $page_title = 'Homepage';
  6.    $loggedin = $_SESSION['loggedin'];
  7.    if ($_SESSION['ID'] >= 1) //then run non logged in homepage
  8.    {
  9. include ('./includes/header.html');
  10. ?>
  11.  
  12. <p><h3>News</h3></p> 
  13. <?php
  14.  
  15.  
  16. require_once ('../mysql_connectnews.php'); 
  17. // Number of records to show per page:
  18.  
  19. $display = 7;
  20.  
  21.  
  22. // Determine how many pages there are. 
  23.  
  24.     if (isset($_GET['np'])) 
  25.     { // Already been determined.
  26.  
  27.  
  28.     $num_pages = $_GET['np'];
  29.  
  30.     else { // Need to determine.
  31.  
  32.  
  33.      // Count the number of records
  34.  
  35.     $query = "SELECT COUNT(*) FROM news ORDER BY datesent ASC";
  36.  
  37.     $result = @mysql_query ($query);
  38.  
  39.     $row = mysql_fetch_array ($result, MYSQL_NUM);
  40.  
  41.     $num_records = $row[0];
  42.  
  43.  
  44. // Calculate the number of pages.
  45.  
  46.         if ($num_records > $display)
  47.         { // More than 1 page.
  48.  
  49.         $num_pages = ceil ($num_records/$display);}
  50.  
  51.  
  52.          else {
  53.  
  54.         $num_pages = 1;
  55.     }
  56.  
  57.  
  58.  
  59. } // End of np IF.
  60.  
  61.  
  62. // Determine where in the database to start returning results.
  63.  
  64.  
  65.     if (isset($_GET['s']))
  66.      {
  67.     $start = $_GET['s'];
  68. }
  69.  
  70.      else 
  71.     {
  72.     $start = 0;
  73. }
  74.  
  75.  
  76.  
  77.     // Default column links.
  78.  
  79. $link1 = "{$_SERVER['PHP_SELF']}?sort=lna";
  80.  
  81. $link2 = "{$_SERVER['PHP_SELF']}?sort=fna";
  82.  
  83. $link3 = "{$_SERVER['PHP_SELF']}?sort=dra";
  84.  
  85.  
  86. // Determine the sorting order.
  87.  
  88.  
  89. if (isset($_GET['sort'])) 
  90.     {
  91.  
  92.     // Use existing sorting order.
  93.  
  94.  
  95.     switch ($_GET['sort']) {
  96.  
  97.  
  98.     case 'lna':
  99.  
  100.     $order_by = 'datesent ASC';
  101.  
  102.     $link1 = "{$_SERVER['PHP_SELF']}?sort=lnd";
  103.  
  104.     break;
  105.  
  106.  
  107.     case 'lnd':
  108.  
  109.     $order_by = 'datesent DESC';
  110.  
  111.     $link1 = "{$_SERVER['PHP_SELF']}?sort=lna";
  112.  
  113.     break;
  114.  
  115.  
  116.     case 'fna':
  117.  
  118.     $order_by = 'fromwhom ASC';
  119.  
  120.     $link2 = "{$_SERVER['PHP_SELF']}?sort=fnd";
  121.  
  122.     break;
  123.  
  124.     case 'fnd':
  125.  
  126.     $order_by = 'fromwhom DESC';
  127.  
  128.     $link2 = "{$_SERVER['PHP_SELF']}?sort=fna";
  129.  
  130.     break;
  131.  
  132.  
  133.     case 'dra':
  134.  
  135.     $order_by = 'subject ASC';
  136.  
  137.     $link3 = "{$_SERVER['PHP_SELF']}?sort=drd";
  138.  
  139.     break;
  140.  
  141.  
  142.     case 'drd':
  143.  
  144.     $order_by = 'subject DESC';
  145.  
  146.     $link3 = "{$_SERVER['PHP_SELF']}?sort=dra";
  147.  
  148.     break;
  149.  
  150.     default:
  151.  
  152.     $order_by = 'datesent DESC';
  153.  
  154.     break;
  155.     }
  156.  
  157.  
  158.  
  159.     // $sort will be appended to the pagination links.
  160.  
  161.     $sort = $_GET['sort'];
  162.  
  163.     else { // Use the default sorting order.
  164.  
  165.     $order_by = 'datesent DESC';
  166.  
  167.     $sort = 'drd';
  168. }
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177. // Make the query.
  178.  
  179.     $query = "SELECT datesent, fromwhom, subject AS dr, message, newsid FROM news ORDER BY $order_by LIMIT $start, $display";        
  180.         $result = @mysql_query ($query);
  181.      // Run the query.
  182.  
  183.  
  184.  
  185. //Table header.
  186.  
  187. echo '<table align="center" cellspacing="0" cellpadding="5">
  188. <tr>
  189.  
  190.  
  191.             <td align="left"><b><a href="' . $link1 . '">Date sent</a></b></td>
  192.     <td         align="left"><b><a href="' . $link2 . '">From whom</a></b></td>
  193.     <td         align="left"><b><a href="' . $link3 . '">Subject</a></b></td>
  194.         <td         align="left"><b>Message</b></td>
  195.  
  196. </tr>
  197. ';
  198.  
  199.  
  200.  
  201. // Fetch and print all the records.
  202.  
  203.     $bg = '#eeeeee'; 
  204.     // Set the background color.
  205.  
  206. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
  207.  
  208.         $bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee'); 
  209.         // Switch the background color.
  210.  
  211.         echo '<tr bgcolor="' . 
  212.         $bg . '">
  213.  
  214.  
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221.  
  222.  
  223.         <td align="left">' . $row['datesent'] . ' </td>
  224.         <td align="left">' . $row['fromwhom'] . '</td>
  225.                 <td align="left">' . $row['dr'] . '</td>
  226.                 <td align="left">' . $row['message'] . ' 
  227.  
  228.  
  229.  
  230.                 </td>
  231.     </tr>
  232.     ';
  233. }
  234.  
  235. echo '</table>';
  236.  
  237. mysql_free_result ($result); // Free up the resources.    
  238.  
  239. mysql_close(); // Close the database connection.
  240.  
  241. // Make the links to other pages, if necessary.
  242. if ($num_pages > 1) {
  243.  
  244.     echo '<br /><p>';
  245.     // Determine what page the script is on.    
  246.     $current_page = ($start/$display) + 1;
  247.  
  248.     // If it's not the first page, make a Previous button.
  249.     if ($current_page != 1) {
  250.         echo '<a href="home.php?s=' . ($start - $display) . '&np=' . $num_pages . '&sort=' . $sort .'">Previous</a> ';
  251.     }
  252.  
  253.     // Make all the numbered pages.
  254.     for ($i = 1; $i <= $num_pages; $i++) {
  255.         if ($i != $current_page) {
  256.             echo '<a href="home.php?s=' . (($display * ($i - 1))) . '&np=' . $num_pages . '&sort=' . $sort .'">' . $i . '</a> ';
  257.         } else {
  258.             echo $i . ' ';
  259.         }
  260.     }
  261.  
  262.     // If it's not the last page, make a Next button.
  263.     if ($current_page != $num_pages) {
  264.         echo '<a href="home.php?s=' . ($start + $display) . '&np=' . $num_pages . '&sort=' . $sort .'">Next</a>';
  265.     }
  266.  
  267.     echo '</p>';
  268.  
  269. } // End of links section.
  270. include ('./includes/footer.html');
  271. } //end of if not logged in
  272.  
  273.  
  274.  
  275.  
  276.  
  277.  
  278. else { //start of else logged in
  279.  
  280.  
  281. $page_title = 'Homepage';
  282.  
  283.  
  284. require_once ('.../mysql_connectusers.php');
  285.  
  286.  
  287. include ('./includes/headerloggedin.html');
  288. $u = $_SESSION['username']; 
  289.  
  290.  
  291.  
  292. $query = "SELECT ID,
  293.      email FROM users WHERE 
  294.     (username='$u')";
  295.  
  296. $result = mysql_query ($query) or 
  297.     trigger_error("Query: $query\n<br />
  298.     MySQL Error: " . mysql_error());
  299.  
  300.  
  301. $row = mysql_fetch_array($result, MYSQL_NUM);
  302.  
  303.         mysql_free_result($result);
  304.  
  305.  
  306.         mysql_close();    
  307.  
  308.  
  309.  
  310. if ($email == NULL) {
  311. echo '<p> You need to set your email address 
  312. <a href="./set_emailloggedin.php">here</a> in order that if you forget your password at some point in the future it can be sent to you.</p>';
  313. }    
  314.  
  315. ?>
  316.  
  317. <p><h3>News</h3></p> 
  318. <?php
  319.  
  320.  
  321. require_once ('../mysql_connectnewswithoutfunction.php'); 
  322. // Number of records to show per page:
  323.  
  324. $display = 7;
  325.  
  326.  
  327. // Determine how many pages there are. 
  328.  
  329.     if (isset($_GET['np'])) 
  330.     { // Already been determined.
  331.  
  332.  
  333.     $num_pages = $_GET['np'];
  334.  
  335.     else { // Need to determine.
  336.  
  337.  
  338.      // Count the number of records
  339.  
  340.     $query = "SELECT COUNT(*) FROM news ORDER BY datesent ASC";
  341.  
  342.     $result = @mysql_query ($query);
  343.  
  344.     $row = mysql_fetch_array ($result, MYSQL_NUM);
  345.  
  346.     $num_records = $row[0];
  347.  
  348.  
  349. // Calculate the number of pages.
  350.  
  351.         if ($num_records > $display)
  352.         { // More than 1 page.
  353.  
  354.         $num_pages = ceil ($num_records/$display);}
  355.  
  356.  
  357.          else {
  358.  
  359.         $num_pages = 1;
  360.     }
  361.  
  362.  
  363.  
  364. } // End of np IF.
  365.  
  366.  
  367. // Determine where in the database to start returning results.
  368.  
  369.  
  370.     if (isset($_GET['s']))
  371.      {
  372.     $start = $_GET['s'];
  373. }
  374.  
  375.      else 
  376.     {
  377.     $start = 0;
  378. }
  379.  
  380.  
  381.  
  382.     // Default column links.
  383.  
  384. $link1 = "{$_SERVER['PHP_SELF']}?sort=lna";
  385.  
  386. $link2 = "{$_SERVER['PHP_SELF']}?sort=fna";
  387.  
  388. $link3 = "{$_SERVER['PHP_SELF']}?sort=dra";
  389.  
  390.  
  391. // Determine the sorting order.
  392.  
  393.  
  394. if (isset($_GET['sort'])) 
  395.     {
  396.  
  397.     // Use existing sorting order.
  398.  
  399.  
  400.     switch ($_GET['sort']) {
  401.  
  402.  
  403.     case 'lna':
  404.  
  405.     $order_by = 'datesent ASC';
  406.  
  407.     $link1 = "{$_SERVER['PHP_SELF']}?sort=lnd";
  408.  
  409.     break;
  410.  
  411.  
  412.     case 'lnd':
  413.  
  414.     $order_by = 'datesent DESC';
  415.  
  416.     $link1 = "{$_SERVER['PHP_SELF']}?sort=lna";
  417.  
  418.     break;
  419.  
  420.  
  421.     case 'fna':
  422.  
  423.     $order_by = 'fromwhom ASC';
  424.  
  425.     $link2 = "{$_SERVER['PHP_SELF']}?sort=fnd";
  426.  
  427.     break;
  428.  
  429.     case 'fnd':
  430.  
  431.     $order_by = 'fromwhom DESC';
  432.  
  433.     $link2 = "{$_SERVER['PHP_SELF']}?sort=fna";
  434.  
  435.     break;
  436.  
  437.  
  438.     case 'dra':
  439.  
  440.     $order_by = 'subject ASC';
  441.  
  442.     $link3 = "{$_SERVER['PHP_SELF']}?sort=drd";
  443.  
  444.     break;
  445.  
  446.  
  447.     case 'drd':
  448.  
  449.     $order_by = 'subject DESC';
  450.  
  451.     $link3 = "{$_SERVER['PHP_SELF']}?sort=dra";
  452.  
  453.     break;
  454.  
  455.     default:
  456.  
  457.     $order_by = 'datesent DESC';
  458.  
  459.     break;
  460.     }
  461.  
  462.  
  463.  
  464.     // $sort will be appended to the pagination links.
  465.  
  466.     $sort = $_GET['sort'];
  467.  
  468.     else { // Use the default sorting order.
  469.  
  470.     $order_by = 'datesent DESC';
  471.  
  472.     $sort = 'drd';
  473. }
  474.  
  475.  
  476.  
  477.  
  478.  
  479.  
  480.  
  481.  
  482. // Make the query.
  483.  
  484.     $query = "SELECT datesent, fromwhom, subject AS dr, message, newsid FROM news ORDER BY $order_by LIMIT $start, $display";        
  485.         $result = @mysql_query ($query);
  486.      // Run the query.
  487.  
  488.  
  489.  
  490. //Table header.
  491.  
  492. echo '<table align="center" cellspacing="0" cellpadding="5">
  493. <tr>';
  494.  
  495. echo'';
  496.  
  497.  
  498.             echo '<td align="left"><b><a href="' . $link1 . '">Date sent</a></b></td>
  499.     <td         align="left"><b><a href="' . $link2 . '">From whom</a></b></td>
  500.     <td         align="left"><b><a href="' . $link3 . '">Subject</a></b></td>
  501.         <td         align="left"><b>Message</b></td>
  502.  
  503. </tr>
  504. ';
  505.  
  506.  
  507.  
  508. // Fetch and print all the records.
  509.  
  510.     $bg = '#eeeeee'; 
  511.     // Set the background color.
  512.  
  513. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
  514.  
  515.         $bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee'); 
  516.         // Switch the background color.
  517.  
  518.         echo '<tr bgcolor="' . 
  519.         $bg . '">
  520.  
  521.  
  522.  
  523.  
  524.  
  525.  
  526.  
  527.  
  528.  
  529.  
  530.         <td align="left">' . $row['datesent'] . ' </td>
  531.         <td align="left">' . $row['fromwhom'] . '</td>
  532.                 <td align="left">' . $row['dr'] . '</td>
  533.                 <td align="left">
  534.                  <td align="left">' . $row['message'] . ' 
  535.  
  536.  
  537.  
  538.  
  539.                 </td>
  540.     </tr>
  541.     ';
  542. }
  543.  
  544. echo '</table>';
  545.  
  546. mysql_free_result ($result); // Free up the resources.    
  547.  
  548. mysql_close(); // Close the database connection.
  549.  
  550. // Make the links to other pages, if necessary.
  551. if ($num_pages > 1) {
  552.  
  553.     echo '<br /><p>';
  554.     // Determine what page the script is on.    
  555.     $current_page = ($start/$display) + 1;
  556.  
  557.     // If it's not the first page, make a Previous button.
  558.     if ($current_page != 1) {
  559.         echo '<a href="home.php?s=' . ($start - $display) . '&np=' . $num_pages . '&sort=' . $sort .'">Previous</a> ';
  560.     }
  561.  
  562.     // Make all the numbered pages.
  563.     for ($i = 1; $i <= $num_pages; $i++) {
  564.         if ($i != $current_page) {
  565.             echo '<a href="home.php?s=' . (($display * ($i - 1))) . '&np=' . $num_pages . '&sort=' . $sort .'">' . $i . '</a> ';
  566.         } else {
  567.             echo $i . ' ';
  568.         }
  569.     }
  570.  
  571.     // If it's not the last page, make a Next button.
  572.     if ($current_page != $num_pages) {
  573.         echo '<a href="home.php?s=' . ($start + $display) . '&np=' . $num_pages . '&sort=' . $sort .'">Next</a>';
  574.     }
  575.  
  576.     echo '</p>';
  577.  
  578. } // End of links section.
  579.  
  580.  
  581. // Include the HTML footer file.
  582.  
  583. include ('./includes/footer.html');
  584.  
  585.  
  586. } //end of else logged in
  587. ?>
  588.  
Dec 14 '07 #3
Markus
6,050 Recognized Expert Expert
mmmm strange post.

I've seen this happen a few times.
Dec 15 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
2521
by: SAN CAZIANO | last post by:
can you help me please because I can't understand why the code doesn't seems to function very well: in onkeypress it must verify if insert number or string value in the fiels, but it doesn't seems to function very well (in frontpage it works but here it doesn't) PROGRAMMA IN FRONTPAGE <form method="get" name="f">
1
1825
by: Avi | last post by:
Hi All. This code works very fine in Firefox but not in I.E. Can anybody help me out? it gives ... "Unknown Runtime Error" in I.E. This code ... Stores N*2 Matrix at Client Side & provide the mean to send the matrix to server side. =======================================================
4
1537
by: Danny | last post by:
I have this bit of code: SELECT itemcode, min(Price) AS minprice FROM itemlist GROUP BY itemcode; it lists the minimum price for each itemcode group. It works fine. But when I want to see the last name of the person who bought this item, it give me that aggregate error saying the lastname is not part of the aggregate function.
7
7417
by: tuchka | last post by:
Hi, guys! I am very new here and just started to learn C. I have previous java exp. however. I'm abs. stuck on pointers and i'm unable comprehend algorithm of simple program that reverses chars in string no matter how long I'm staring at it. This is the method(I printed out some lines for better understanding(by me)):
5
2829
by: Janiv Ratson | last post by:
Hi, Some how I cannot step into MFC code, it used to worked till last week. What is the reason? What is the solution ? 10x, J.
1
959
by: John Dalberg | last post by:
I am developing an app for a web hosting hosting company and placed in sites folders. The app will be used by the sites and accessible to webmasters using ftp. What options do I have to protect the app from being copied and used elsewhere? J. Dalberg
17
2144
by: Gladiator | last post by:
When I am trying to execute a program from "The C Programming Language" by Dennis Ritchie, I tried to run the following program.I am using Dev++ as a compiler software. The Program is presented below. #include <stdio.h> main() { long nc;
6
1552
by: B. | last post by:
my small project has two files, umg.cpp (unmanaged c++) and mged.cpp (MC++), and unmanged code will call managed code. However, I cannot debug from unmanged code into managed code. Can anyone help me to solve the problem?
2
1405
by: Ming | last post by:
I do not understand the sample code on php.net for curl_multi_exec. Any help? Many thanks! <?php // create both cURL resources $ch1 = curl_init(); $ch2 = curl_init(); // set URL and other appropriate options curl_setopt($ch1, CURLOPT_URL, "http://www.example.com/");
1
6049
by: duckie | last post by:
I was sent a code made in Microsoft Visual C++ 2005, and when I run it in 2008, i get this: error C4335: Mac file format detected: please convert the source file to either DOS or UNIX format warning C4067: unexpected tokens following preprocessor directive - expected a newline Is there a problem with the two programs compatibility? I didn't see anything obviously wrong with the code, and this is part of a class, so I would expect the...
0
9656
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10370
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10113
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8995
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7519
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5402
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4074
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2896
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.