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): -
-
-
-
<?php
-
-
$page_title = 'Homepage';
-
$loggedin = $_SESSION['loggedin'];
-
if ($loggedin != NULL) //then run non logged in homepage
-
{
-
include ('./includes/header.html');
-
?>
-
-
<p><h3>News</h3></p>
-
<?php
-
-
-
require_once ('../mysql_connectnews.php');
-
// Number of records to show per page:
-
-
$display = 7;
-
-
-
// Determine how many pages there are.
-
-
if (isset($_GET['np']))
-
{ // Already been determined.
-
-
-
$num_pages = $_GET['np'];
-
}
-
-
else { // Need to determine.
-
-
-
// Count the number of records
-
-
$query = "SELECT COUNT(*) FROM news ORDER BY datesent ASC";
-
-
$result = @mysql_query ($query);
-
-
$row = mysql_fetch_array ($result, MYSQL_NUM);
-
-
$num_records = $row[0];
-
-
-
// Calculate the number of pages.
-
-
if ($num_records > $display)
-
{ // More than 1 page.
-
-
$num_pages = ceil ($num_records/$display);}
-
-
-
else {
-
-
$num_pages = 1;
-
}
-
-
-
-
} // End of np IF.
-
-
-
// Determine where in the database to start returning results.
-
-
-
if (isset($_GET['s']))
-
{
-
$start = $_GET['s'];
-
}
-
-
else
-
{
-
$start = 0;
-
}
-
-
-
-
// Default column links.
-
-
$link1 = "{$_SERVER['PHP_SELF']}?sort=lna";
-
-
$link2 = "{$_SERVER['PHP_SELF']}?sort=fna";
-
-
$link3 = "{$_SERVER['PHP_SELF']}?sort=dra";
-
-
-
// Determine the sorting order.
-
-
-
if (isset($_GET['sort']))
-
{
-
-
// Use existing sorting order.
-
-
-
switch ($_GET['sort']) {
-
-
-
case 'lna':
-
-
$order_by = 'datesent ASC';
-
-
$link1 = "{$_SERVER['PHP_SELF']}?sort=lnd";
-
-
break;
-
-
-
case 'lnd':
-
-
$order_by = 'datesent DESC';
-
-
$link1 = "{$_SERVER['PHP_SELF']}?sort=lna";
-
-
break;
-
-
-
case 'fna':
-
-
$order_by = 'fromwhom ASC';
-
-
$link2 = "{$_SERVER['PHP_SELF']}?sort=fnd";
-
-
break;
-
-
case 'fnd':
-
-
$order_by = 'fromwhom DESC';
-
-
$link2 = "{$_SERVER['PHP_SELF']}?sort=fna";
-
-
break;
-
-
-
case 'dra':
-
-
$order_by = 'subject ASC';
-
-
$link3 = "{$_SERVER['PHP_SELF']}?sort=drd";
-
-
break;
-
-
-
case 'drd':
-
-
$order_by = 'subject DESC';
-
-
$link3 = "{$_SERVER['PHP_SELF']}?sort=dra";
-
-
break;
-
-
default:
-
-
$order_by = 'datesent DESC';
-
-
break;
-
}
-
-
-
-
// $sort will be appended to the pagination links.
-
-
$sort = $_GET['sort'];
-
-
}
-
else { // Use the default sorting order.
-
-
$order_by = 'datesent DESC';
-
-
$sort = 'drd';
-
}
-
-
-
-
-
// Make the query.
-
-
$query = "SELECT datesent, fromwhom, subject AS dr, message FROM users ORDER BY $order_by LIMIT $start, $display";
-
$result = @mysql_query ($query);
-
// Run the query.
-
-
-
-
// Make the query.
-
-
$query = "SELECT datesent, fromwhom, subject AS dr, message FROM news ORDER BY $order_by LIMIT $start, $display";
-
$result = @mysql_query ($query);
-
// Run the query.
-
-
-
-
//Table header.
-
-
echo '<table align="center" cellspacing="0" cellpadding="5">
-
<tr>
-
-
-
<td align="left"><b><a href="' . $link1 . '">Date sent</a></b></td>
-
<td align="left"><b><a href="' . $link2 . '">From whom</a></b></td>
-
<td align="left"><b><a href="' . $link3 . '">Subject</a></b></td>
-
<td align="left"><b>Message</b></td>
-
-
</tr>
-
';
-
-
-
-
// Fetch and print all the records.
-
-
$bg = '#eeeeee';
-
// Set the background color.
-
-
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
-
-
$bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee');
-
// Switch the background color.
-
-
echo '<tr bgcolor="' .
-
$bg . '">
-
-
-
-
-
-
-
-
-
-
-
<td align="left">' . $row['datesent'] . ' </td>
-
<td align="left">' . $row['fromwhom'] . '</td>
-
<td align="left">' . $row['dr'] . '</td>
-
<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
-
// 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
-
// the message was from, the subject, the time sent, and the full message itself
-
</td>
-
</tr>
-
';
-
}
-
-
echo '</table>';
-
-
mysql_free_result ($result); // Free up the resources.
-
-
mysql_close(); // Close the database connection.
-
-
// Make the links to other pages, if necessary.
-
if ($num_pages > 1) {
-
-
echo '<br /><p>';
-
// Determine what page the script is on.
-
$current_page = ($start/$display) + 1;
-
-
// If it's not the first page, make a Previous button.
-
if ($current_page != 1) {
-
echo '<a href="home.php?s=' . ($start - $display) . '&np=' . $num_pages . '&sort=' . $sort .'">Previous</a> ';
-
}
-
-
// Make all the numbered pages.
-
for ($i = 1; $i <= $num_pages; $i++) {
-
if ($i != $current_page) {
-
echo '<a href="home.php?s=' . (($display * ($i - 1))) . '&np=' . $num_pages . '&sort=' . $sort .'">' . $i . '</a> ';
-
} else {
-
echo $i . ' ';
-
}
-
}
-
-
// If it's not the last page, make a Next button.
-
if ($current_page != $num_pages) {
-
echo '<a href="home.php?s=' . ($start + $display) . '&np=' . $num_pages . '&sort=' . $sort .'">Next</a>';
-
}
-
-
echo '</p>';
-
-
} // End of links section.
-
include ('./includes/footer.html');
-
} //end of if not logged in
-
-
-
-
-
-
-
else { //start of else logged in
-
-
-
$page_title = 'Homepage';
-
-
-
require_once ('.../mysql_connectusers.php');
-
-
-
include ('./includes/headerloggedin.html');
-
$u = $_SESSION['username'];
-
-
-
-
$query = "SELECT ID,
-
email FROM users WHERE
-
(username='$u')";
-
-
$result = mysql_query ($query) or
-
trigger_error("Query: $query\n<br />
-
MySQL Error: " . mysql_error());
-
-
-
$row = mysql_fetch_array($result, MYSQL_NUM);
-
-
mysql_free_result($result);
-
-
-
mysql_close();
-
-
-
-
if ($email == NULL) {
-
echo '<p> You need to set your email address
-
<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>';
-
}
-
-
?>
-
-
<p><h3>News</h3></p>
-
<?php
-
-
-
require_once ('../mysql_connectnewswithoutfunction.php');
-
// Number of records to show per page:
-
-
$display = 7;
-
-
-
// Determine how many pages there are.
-
-
if (isset($_GET['np']))
-
{ // Already been determined.
-
-
-
$num_pages = $_GET['np'];
-
}
-
-
else { // Need to determine.
-
-
-
// Count the number of records
-
-
$query = "SELECT COUNT(*) FROM news ORDER BY datesent ASC";
-
-
$result = @mysql_query ($query);
-
-
$row = mysql_fetch_array ($result, MYSQL_NUM);
-
-
$num_records = $row[0];
-
-
-
// Calculate the number of pages.
-
-
if ($num_records > $display)
-
{ // More than 1 page.
-
-
$num_pages = ceil ($num_records/$display);}
-
-
-
else {
-
-
$num_pages = 1;
-
}
-
-
-
-
} // End of np IF.
-
-
-
// Determine where in the database to start returning results.
-
-
-
if (isset($_GET['s']))
-
{
-
$start = $_GET['s'];
-
}
-
-
else
-
{
-
$start = 0;
-
}
-
-
-
-
// Default column links.
-
-
$link1 = "{$_SERVER['PHP_SELF']}?sort=lna";
-
-
$link2 = "{$_SERVER['PHP_SELF']}?sort=fna";
-
-
$link3 = "{$_SERVER['PHP_SELF']}?sort=dra";
-
-
-
// Determine the sorting order.
-
-
-
if (isset($_GET['sort']))
-
{
-
-
// Use existing sorting order.
-
-
-
switch ($_GET['sort']) {
-
-
-
case 'lna':
-
-
$order_by = 'datesent ASC';
-
-
$link1 = "{$_SERVER['PHP_SELF']}?sort=lnd";
-
-
break;
-
-
-
case 'lnd':
-
-
$order_by = 'datesent DESC';
-
-
$link1 = "{$_SERVER['PHP_SELF']}?sort=lna";
-
-
break;
-
-
-
case 'fna':
-
-
$order_by = 'fromwhom ASC';
-
-
$link2 = "{$_SERVER['PHP_SELF']}?sort=fnd";
-
-
break;
-
-
case 'fnd':
-
-
$order_by = 'fromwhom DESC';
-
-
$link2 = "{$_SERVER['PHP_SELF']}?sort=fna";
-
-
break;
-
-
-
case 'dra':
-
-
$order_by = 'subject ASC';
-
-
$link3 = "{$_SERVER['PHP_SELF']}?sort=drd";
-
-
break;
-
-
-
case 'drd':
-
-
$order_by = 'subject DESC';
-
-
$link3 = "{$_SERVER['PHP_SELF']}?sort=dra";
-
-
break;
-
-
default:
-
-
$order_by = 'datesent DESC';
-
-
break;
-
}
-
-
-
-
// $sort will be appended to the pagination links.
-
-
$sort = $_GET['sort'];
-
-
}
-
else { // Use the default sorting order.
-
-
$order_by = 'datesent DESC';
-
-
$sort = 'drd';
-
}
-
-
-
-
-
// Make the query.
-
-
$query = "SELECT datesent, fromwhom, subject AS dr, message FROM users ORDER BY $order_by LIMIT $start, $display";
-
$result = @mysql_query ($query);
-
// Run the query.
-
-
-
-
// Make the query.
-
-
$query = "SELECT datesent, fromwhom, subject AS dr, message FROM news ORDER BY $order_by LIMIT $start, $display";
-
$result = @mysql_query ($query);
-
// Run the query.
-
-
-
-
//Table header.
-
-
echo '<table align="center" cellspacing="0" cellpadding="5">
-
<tr>
-
-
-
<td align="left"><b><a href="' . $link1 . '">Date sent</a></b></td>
-
<td align="left"><b><a href="' . $link2 . '">From whom</a></b></td>
-
<td align="left"><b><a href="' . $link3 . '">Subject</a></b></td>
-
<td align="left"><b>Message</b></td>
-
-
</tr>
-
';
-
-
-
-
// Fetch and print all the records.
-
-
$bg = '#eeeeee';
-
// Set the background color.
-
-
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
-
-
$bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee');
-
// Switch the background color.
-
-
echo '<tr bgcolor="' .
-
$bg . '">
-
-
-
-
-
-
-
-
-
-
-
<td align="left">' . $row['datesent'] . ' </td>
-
<td align="left">' . $row['fromwhom'] . '</td>
-
<td align="left">' . $row['dr'] . '</td>
-
<td align="left">
-
</td>//here is where I insert the code for a link to allow someone to view the message stored in the database, it
-
// 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
-
// the message was from, the subject, the time sent, and the full message itself
-
</td>
-
</tr>
-
';
-
}
-
-
echo '</table>';
-
-
mysql_free_result ($result); // Free up the resources.
-
-
mysql_close(); // Close the database connection.
-
-
// Make the links to other pages, if necessary.
-
if ($num_pages > 1) {
-
-
echo '<br /><p>';
-
// Determine what page the script is on.
-
$current_page = ($start/$display) + 1;
-
-
// If it's not the first page, make a Previous button.
-
if ($current_page != 1) {
-
echo '<a href="home.php?s=' . ($start - $display) . '&np=' . $num_pages . '&sort=' . $sort .'">Previous</a> ';
-
}
-
-
// Make all the numbered pages.
-
for ($i = 1; $i <= $num_pages; $i++) {
-
if ($i != $current_page) {
-
echo '<a href="home.php?s=' . (($display * ($i - 1))) . '&np=' . $num_pages . '&sort=' . $sort .'">' . $i . '</a> ';
-
} else {
-
echo $i . ' ';
-
}
-
}
-
-
// If it's not the last page, make a Next button.
-
if ($current_page != $num_pages) {
-
echo '<a href="home.php?s=' . ($start + $display) . '&np=' . $num_pages . '&sort=' . $sort .'">Next</a>';
-
}
-
-
echo '</p>';
-
-
} // End of links section.
-
-
-
// Include the HTML footer file.
-
-
include ('./includes/footer.html');
-
-
-
} //end of else logged in
-
?>
-
Thanks to anyone who helps,
Harry
3 1949
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 -
-
-
<?php
-
-
$page_title = 'Homepage';
-
$loggedin = $_SESSION['loggedin'];
-
if ($loggedin != NULL) //then run non logged in homepage
-
{
-
include ('./includes/header.html');
-
?>
-
-
<p><h3>News</h3></p>
-
<?php
-
-
-
require_once ('../mysql_connectnews.php');
-
// Number of records to show per page:
-
-
$display = 7;
-
-
-
// Determine how many pages there are.
-
-
if (isset($_GET['np']))
-
{ // Already been determined.
-
-
-
$num_pages = $_GET['np'];
-
}
-
-
else { // Need to determine.
-
-
-
// Count the number of records
-
-
$query = "SELECT COUNT(*) FROM news ORDER BY datesent ASC";
-
-
$result = @mysql_query ($query);
-
-
$row = mysql_fetch_array ($result, MYSQL_NUM);
-
-
$num_records = $row[0];
-
-
-
// Calculate the number of pages.
-
-
if ($num_records > $display)
-
{ // More than 1 page.
-
-
$num_pages = ceil ($num_records/$display);}
-
-
-
else {
-
-
$num_pages = 1;
-
}
-
-
-
-
} // End of np IF.
-
-
-
// Determine where in the database to start returning results.
-
-
-
if (isset($_GET['s']))
-
{
-
$start = $_GET['s'];
-
}
-
-
else
-
{
-
$start = 0;
-
}
-
-
-
-
// Default column links.
-
-
$link1 = "{$_SERVER['PHP_SELF']}?sort=lna";
-
-
$link2 = "{$_SERVER['PHP_SELF']}?sort=fna";
-
-
$link3 = "{$_SERVER['PHP_SELF']}?sort=dra";
-
-
-
// Determine the sorting order.
-
-
-
if (isset($_GET['sort']))
-
{
-
-
// Use existing sorting order.
-
-
-
switch ($_GET['sort']) {
-
-
-
case 'lna':
-
-
$order_by = 'datesent ASC';
-
-
$link1 = "{$_SERVER['PHP_SELF']}?sort=lnd";
-
-
break;
-
-
-
case 'lnd':
-
-
$order_by = 'datesent DESC';
-
-
$link1 = "{$_SERVER['PHP_SELF']}?sort=lna";
-
-
break;
-
-
-
case 'fna':
-
-
$order_by = 'fromwhom ASC';
-
-
$link2 = "{$_SERVER['PHP_SELF']}?sort=fnd";
-
-
break;
-
-
case 'fnd':
-
-
$order_by = 'fromwhom DESC';
-
-
$link2 = "{$_SERVER['PHP_SELF']}?sort=fna";
-
-
break;
-
-
-
case 'dra':
-
-
$order_by = 'subject ASC';
-
-
$link3 = "{$_SERVER['PHP_SELF']}?sort=drd";
-
-
break;
-
-
-
case 'drd':
-
-
$order_by = 'subject DESC';
-
-
$link3 = "{$_SERVER['PHP_SELF']}?sort=dra";
-
-
break;
-
-
default:
-
-
$order_by = 'datesent DESC';
-
-
break;
-
}
-
-
-
-
// $sort will be appended to the pagination links.
-
-
$sort = $_GET['sort'];
-
-
}
-
else { // Use the default sorting order.
-
-
$order_by = 'datesent DESC';
-
-
$sort = 'drd';
-
}
-
-
-
-
-
-
-
-
-
// Make the query.
-
-
$query = "SELECT datesent, fromwhom, subject AS dr, message, newsid FROM news ORDER BY $order_by LIMIT $start, $display";
-
$result = @mysql_query ($query);
-
// Run the query.
-
-
-
-
//Table header.
-
-
echo '<table align="center" cellspacing="0" cellpadding="5">
-
<tr>
-
-
-
<td align="left"><b><a href="' . $link1 . '">Date sent</a></b></td>
-
<td align="left"><b><a href="' . $link2 . '">From whom</a></b></td>
-
<td align="left"><b><a href="' . $link3 . '">Subject</a></b></td>
-
<td align="left"><b>Message</b></td>
-
-
</tr>
-
';
-
-
-
-
// Fetch and print all the records.
-
-
$bg = '#eeeeee';
-
// Set the background color.
-
-
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
-
-
$bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee');
-
// Switch the background color.
-
-
echo '<tr bgcolor="' .
-
$bg . '">
-
-
-
-
-
-
-
-
-
-
-
<td align="left">' . $row['datesent'] . ' </td>
-
<td align="left">' . $row['fromwhom'] . '</td>
-
<td align="left">' . $row['dr'] . '</td>
-
<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
-
// 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
-
// the message was from, the subject, the time sent, and the full message itself
-
-
<a href="viewmessage.php?id=' . $row['newsid'] . '">View news item</a>
-
-
-
</td>
-
</tr>
-
';
-
}
-
-
echo '</table>';
-
-
mysql_free_result ($result); // Free up the resources.
-
-
mysql_close(); // Close the database connection.
-
-
// Make the links to other pages, if necessary.
-
if ($num_pages > 1) {
-
-
echo '<br /><p>';
-
// Determine what page the script is on.
-
$current_page = ($start/$display) + 1;
-
-
// If it's not the first page, make a Previous button.
-
if ($current_page != 1) {
-
echo '<a href="home.php?s=' . ($start - $display) . '&np=' . $num_pages . '&sort=' . $sort .'">Previous</a> ';
-
}
-
-
// Make all the numbered pages.
-
for ($i = 1; $i <= $num_pages; $i++) {
-
if ($i != $current_page) {
-
echo '<a href="home.php?s=' . (($display * ($i - 1))) . '&np=' . $num_pages . '&sort=' . $sort .'">' . $i . '</a> ';
-
} else {
-
echo $i . ' ';
-
}
-
}
-
-
// If it's not the last page, make a Next button.
-
if ($current_page != $num_pages) {
-
echo '<a href="home.php?s=' . ($start + $display) . '&np=' . $num_pages . '&sort=' . $sort .'">Next</a>';
-
}
-
-
echo '</p>';
-
-
} // End of links section.
-
include ('./includes/footer.html');
-
} //end of if not logged in
-
-
-
-
-
-
-
else { //start of else logged in
-
-
-
$page_title = 'Homepage';
-
-
-
require_once ('.../mysql_connectusers.php');
-
-
-
include ('./includes/headerloggedin.html');
-
$u = $_SESSION['username'];
-
-
-
-
$query = "SELECT ID,
-
email FROM users WHERE
-
(username='$u')";
-
-
$result = mysql_query ($query) or
-
trigger_error("Query: $query\n<br />
-
MySQL Error: " . mysql_error());
-
-
-
$row = mysql_fetch_array($result, MYSQL_NUM);
-
-
mysql_free_result($result);
-
-
-
mysql_close();
-
-
-
-
if ($email == NULL) {
-
echo '<p> You need to set your email address
-
<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>';
-
}
-
-
?>
-
-
<p><h3>News</h3></p>
-
<?php
-
-
-
require_once ('../mysql_connectnewswithoutfunction.php');
-
// Number of records to show per page:
-
-
$display = 7;
-
-
-
// Determine how many pages there are.
-
-
if (isset($_GET['np']))
-
{ // Already been determined.
-
-
-
$num_pages = $_GET['np'];
-
}
-
-
else { // Need to determine.
-
-
-
// Count the number of records
-
-
$query = "SELECT COUNT(*) FROM news ORDER BY datesent ASC";
-
-
$result = @mysql_query ($query);
-
-
$row = mysql_fetch_array ($result, MYSQL_NUM);
-
-
$num_records = $row[0];
-
-
-
// Calculate the number of pages.
-
-
if ($num_records > $display)
-
{ // More than 1 page.
-
-
$num_pages = ceil ($num_records/$display);}
-
-
-
else {
-
-
$num_pages = 1;
-
}
-
-
-
-
} // End of np IF.
-
-
-
// Determine where in the database to start returning results.
-
-
-
if (isset($_GET['s']))
-
{
-
$start = $_GET['s'];
-
}
-
-
else
-
{
-
$start = 0;
-
}
-
-
-
-
// Default column links.
-
-
$link1 = "{$_SERVER['PHP_SELF']}?sort=lna";
-
-
$link2 = "{$_SERVER['PHP_SELF']}?sort=fna";
-
-
$link3 = "{$_SERVER['PHP_SELF']}?sort=dra";
-
-
-
// Determine the sorting order.
-
-
-
if (isset($_GET['sort']))
-
{
-
-
// Use existing sorting order.
-
-
-
switch ($_GET['sort']) {
-
-
-
case 'lna':
-
-
$order_by = 'datesent ASC';
-
-
$link1 = "{$_SERVER['PHP_SELF']}?sort=lnd";
-
-
break;
-
-
-
case 'lnd':
-
-
$order_by = 'datesent DESC';
-
-
$link1 = "{$_SERVER['PHP_SELF']}?sort=lna";
-
-
break;
-
-
-
case 'fna':
-
-
$order_by = 'fromwhom ASC';
-
-
$link2 = "{$_SERVER['PHP_SELF']}?sort=fnd";
-
-
break;
-
-
case 'fnd':
-
-
$order_by = 'fromwhom DESC';
-
-
$link2 = "{$_SERVER['PHP_SELF']}?sort=fna";
-
-
break;
-
-
-
case 'dra':
-
-
$order_by = 'subject ASC';
-
-
$link3 = "{$_SERVER['PHP_SELF']}?sort=drd";
-
-
break;
-
-
-
case 'drd':
-
-
$order_by = 'subject DESC';
-
-
$link3 = "{$_SERVER['PHP_SELF']}?sort=dra";
-
-
break;
-
-
default:
-
-
$order_by = 'datesent DESC';
-
-
break;
-
}
-
-
-
-
// $sort will be appended to the pagination links.
-
-
$sort = $_GET['sort'];
-
-
}
-
else { // Use the default sorting order.
-
-
$order_by = 'datesent DESC';
-
-
$sort = 'drd';
-
}
-
-
-
-
-
-
-
-
-
// Make the query.
-
-
$query = "SELECT datesent, fromwhom, subject AS dr, message, newsid FROM news ORDER BY $order_by LIMIT $start, $display";
-
$result = @mysql_query ($query);
-
// Run the query.
-
-
-
-
//Table header.
-
-
echo '<table align="center" cellspacing="0" cellpadding="5">
-
<tr>
-
-
-
<td align="left"><b><a href="' . $link1 . '">Date sent</a></b></td>
-
<td align="left"><b><a href="' . $link2 . '">From whom</a></b></td>
-
<td align="left"><b><a href="' . $link3 . '">Subject</a></b></td>
-
<td align="left"><b>Message</b></td>
-
-
</tr>
-
';
-
-
-
-
// Fetch and print all the records.
-
-
$bg = '#eeeeee';
-
// Set the background color.
-
-
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
-
-
$bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee');
-
// Switch the background color.
-
-
echo '<tr bgcolor="' .
-
$bg . '">
-
-
-
-
-
-
-
-
-
-
-
<td align="left">' . $row['datesent'] . ' </td>
-
<td align="left">' . $row['fromwhom'] . '</td>
-
<td align="left">' . $row['dr'] . '</td>
-
<td align="left">
-
</td>//here is where I insert the code for a link to allow someone to view the message stored in the database, it
-
// 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
-
// the message was from, the subject, the time sent, and the full message itself
-
-
-
<a href="viewmessage.php?id=' . $row['newsid'] . '">View news item</a>
-
</td>
-
</tr>
-
';
-
}
-
-
echo '</table>';
-
-
mysql_free_result ($result); // Free up the resources.
-
-
mysql_close(); // Close the database connection.
-
-
// Make the links to other pages, if necessary.
-
if ($num_pages > 1) {
-
-
echo '<br /><p>';
-
// Determine what page the script is on.
-
$current_page = ($start/$display) + 1;
-
-
// If it's not the first page, make a Previous button.
-
if ($current_page != 1) {
-
echo '<a href="home.php?s=' . ($start - $display) . '&np=' . $num_pages . '&sort=' . $sort .'">Previous</a> ';
-
}
-
-
// Make all the numbered pages.
-
for ($i = 1; $i <= $num_pages; $i++) {
-
if ($i != $current_page) {
-
echo '<a href="home.php?s=' . (($display * ($i - 1))) . '&np=' . $num_pages . '&sort=' . $sort .'">' . $i . '</a> ';
-
} else {
-
echo $i . ' ';
-
}
-
}
-
-
// If it's not the last page, make a Next button.
-
if ($current_page != $num_pages) {
-
echo '<a href="home.php?s=' . ($start + $display) . '&np=' . $num_pages . '&sort=' . $sort .'">Next</a>';
-
}
-
-
echo '</p>';
-
-
} // End of links section.
-
-
-
// Include the HTML footer file.
-
-
include ('./includes/footer.html');
-
-
-
} //end of else logged in
-
?>
-
Thanks to anyone who helps,
Harry
I have further edited the code, and it is back to the state (error wise) of the first script.
Here it is -
-
-
<?php
-
-
$page_title = 'Homepage';
-
$loggedin = $_SESSION['loggedin'];
-
if ($_SESSION['ID'] >= 1) //then run non logged in homepage
-
{
-
include ('./includes/header.html');
-
?>
-
-
<p><h3>News</h3></p>
-
<?php
-
-
-
require_once ('../mysql_connectnews.php');
-
// Number of records to show per page:
-
-
$display = 7;
-
-
-
// Determine how many pages there are.
-
-
if (isset($_GET['np']))
-
{ // Already been determined.
-
-
-
$num_pages = $_GET['np'];
-
}
-
-
else { // Need to determine.
-
-
-
// Count the number of records
-
-
$query = "SELECT COUNT(*) FROM news ORDER BY datesent ASC";
-
-
$result = @mysql_query ($query);
-
-
$row = mysql_fetch_array ($result, MYSQL_NUM);
-
-
$num_records = $row[0];
-
-
-
// Calculate the number of pages.
-
-
if ($num_records > $display)
-
{ // More than 1 page.
-
-
$num_pages = ceil ($num_records/$display);}
-
-
-
else {
-
-
$num_pages = 1;
-
}
-
-
-
-
} // End of np IF.
-
-
-
// Determine where in the database to start returning results.
-
-
-
if (isset($_GET['s']))
-
{
-
$start = $_GET['s'];
-
}
-
-
else
-
{
-
$start = 0;
-
}
-
-
-
-
// Default column links.
-
-
$link1 = "{$_SERVER['PHP_SELF']}?sort=lna";
-
-
$link2 = "{$_SERVER['PHP_SELF']}?sort=fna";
-
-
$link3 = "{$_SERVER['PHP_SELF']}?sort=dra";
-
-
-
// Determine the sorting order.
-
-
-
if (isset($_GET['sort']))
-
{
-
-
// Use existing sorting order.
-
-
-
switch ($_GET['sort']) {
-
-
-
case 'lna':
-
-
$order_by = 'datesent ASC';
-
-
$link1 = "{$_SERVER['PHP_SELF']}?sort=lnd";
-
-
break;
-
-
-
case 'lnd':
-
-
$order_by = 'datesent DESC';
-
-
$link1 = "{$_SERVER['PHP_SELF']}?sort=lna";
-
-
break;
-
-
-
case 'fna':
-
-
$order_by = 'fromwhom ASC';
-
-
$link2 = "{$_SERVER['PHP_SELF']}?sort=fnd";
-
-
break;
-
-
case 'fnd':
-
-
$order_by = 'fromwhom DESC';
-
-
$link2 = "{$_SERVER['PHP_SELF']}?sort=fna";
-
-
break;
-
-
-
case 'dra':
-
-
$order_by = 'subject ASC';
-
-
$link3 = "{$_SERVER['PHP_SELF']}?sort=drd";
-
-
break;
-
-
-
case 'drd':
-
-
$order_by = 'subject DESC';
-
-
$link3 = "{$_SERVER['PHP_SELF']}?sort=dra";
-
-
break;
-
-
default:
-
-
$order_by = 'datesent DESC';
-
-
break;
-
}
-
-
-
-
// $sort will be appended to the pagination links.
-
-
$sort = $_GET['sort'];
-
-
}
-
else { // Use the default sorting order.
-
-
$order_by = 'datesent DESC';
-
-
$sort = 'drd';
-
}
-
-
-
-
-
-
-
-
-
// Make the query.
-
-
$query = "SELECT datesent, fromwhom, subject AS dr, message, newsid FROM news ORDER BY $order_by LIMIT $start, $display";
-
$result = @mysql_query ($query);
-
// Run the query.
-
-
-
-
//Table header.
-
-
echo '<table align="center" cellspacing="0" cellpadding="5">
-
<tr>
-
-
-
<td align="left"><b><a href="' . $link1 . '">Date sent</a></b></td>
-
<td align="left"><b><a href="' . $link2 . '">From whom</a></b></td>
-
<td align="left"><b><a href="' . $link3 . '">Subject</a></b></td>
-
<td align="left"><b>Message</b></td>
-
-
</tr>
-
';
-
-
-
-
// Fetch and print all the records.
-
-
$bg = '#eeeeee';
-
// Set the background color.
-
-
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
-
-
$bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee');
-
// Switch the background color.
-
-
echo '<tr bgcolor="' .
-
$bg . '">
-
-
-
-
-
-
-
-
-
-
-
<td align="left">' . $row['datesent'] . ' </td>
-
<td align="left">' . $row['fromwhom'] . '</td>
-
<td align="left">' . $row['dr'] . '</td>
-
<td align="left">' . $row['message'] . '
-
-
-
-
</td>
-
</tr>
-
';
-
}
-
-
echo '</table>';
-
-
mysql_free_result ($result); // Free up the resources.
-
-
mysql_close(); // Close the database connection.
-
-
// Make the links to other pages, if necessary.
-
if ($num_pages > 1) {
-
-
echo '<br /><p>';
-
// Determine what page the script is on.
-
$current_page = ($start/$display) + 1;
-
-
// If it's not the first page, make a Previous button.
-
if ($current_page != 1) {
-
echo '<a href="home.php?s=' . ($start - $display) . '&np=' . $num_pages . '&sort=' . $sort .'">Previous</a> ';
-
}
-
-
// Make all the numbered pages.
-
for ($i = 1; $i <= $num_pages; $i++) {
-
if ($i != $current_page) {
-
echo '<a href="home.php?s=' . (($display * ($i - 1))) . '&np=' . $num_pages . '&sort=' . $sort .'">' . $i . '</a> ';
-
} else {
-
echo $i . ' ';
-
}
-
}
-
-
// If it's not the last page, make a Next button.
-
if ($current_page != $num_pages) {
-
echo '<a href="home.php?s=' . ($start + $display) . '&np=' . $num_pages . '&sort=' . $sort .'">Next</a>';
-
}
-
-
echo '</p>';
-
-
} // End of links section.
-
include ('./includes/footer.html');
-
} //end of if not logged in
-
-
-
-
-
-
-
else { //start of else logged in
-
-
-
$page_title = 'Homepage';
-
-
-
require_once ('.../mysql_connectusers.php');
-
-
-
include ('./includes/headerloggedin.html');
-
$u = $_SESSION['username'];
-
-
-
-
$query = "SELECT ID,
-
email FROM users WHERE
-
(username='$u')";
-
-
$result = mysql_query ($query) or
-
trigger_error("Query: $query\n<br />
-
MySQL Error: " . mysql_error());
-
-
-
$row = mysql_fetch_array($result, MYSQL_NUM);
-
-
mysql_free_result($result);
-
-
-
mysql_close();
-
-
-
-
if ($email == NULL) {
-
echo '<p> You need to set your email address
-
<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>';
-
}
-
-
?>
-
-
<p><h3>News</h3></p>
-
<?php
-
-
-
require_once ('../mysql_connectnewswithoutfunction.php');
-
// Number of records to show per page:
-
-
$display = 7;
-
-
-
// Determine how many pages there are.
-
-
if (isset($_GET['np']))
-
{ // Already been determined.
-
-
-
$num_pages = $_GET['np'];
-
}
-
-
else { // Need to determine.
-
-
-
// Count the number of records
-
-
$query = "SELECT COUNT(*) FROM news ORDER BY datesent ASC";
-
-
$result = @mysql_query ($query);
-
-
$row = mysql_fetch_array ($result, MYSQL_NUM);
-
-
$num_records = $row[0];
-
-
-
// Calculate the number of pages.
-
-
if ($num_records > $display)
-
{ // More than 1 page.
-
-
$num_pages = ceil ($num_records/$display);}
-
-
-
else {
-
-
$num_pages = 1;
-
}
-
-
-
-
} // End of np IF.
-
-
-
// Determine where in the database to start returning results.
-
-
-
if (isset($_GET['s']))
-
{
-
$start = $_GET['s'];
-
}
-
-
else
-
{
-
$start = 0;
-
}
-
-
-
-
// Default column links.
-
-
$link1 = "{$_SERVER['PHP_SELF']}?sort=lna";
-
-
$link2 = "{$_SERVER['PHP_SELF']}?sort=fna";
-
-
$link3 = "{$_SERVER['PHP_SELF']}?sort=dra";
-
-
-
// Determine the sorting order.
-
-
-
if (isset($_GET['sort']))
-
{
-
-
// Use existing sorting order.
-
-
-
switch ($_GET['sort']) {
-
-
-
case 'lna':
-
-
$order_by = 'datesent ASC';
-
-
$link1 = "{$_SERVER['PHP_SELF']}?sort=lnd";
-
-
break;
-
-
-
case 'lnd':
-
-
$order_by = 'datesent DESC';
-
-
$link1 = "{$_SERVER['PHP_SELF']}?sort=lna";
-
-
break;
-
-
-
case 'fna':
-
-
$order_by = 'fromwhom ASC';
-
-
$link2 = "{$_SERVER['PHP_SELF']}?sort=fnd";
-
-
break;
-
-
case 'fnd':
-
-
$order_by = 'fromwhom DESC';
-
-
$link2 = "{$_SERVER['PHP_SELF']}?sort=fna";
-
-
break;
-
-
-
case 'dra':
-
-
$order_by = 'subject ASC';
-
-
$link3 = "{$_SERVER['PHP_SELF']}?sort=drd";
-
-
break;
-
-
-
case 'drd':
-
-
$order_by = 'subject DESC';
-
-
$link3 = "{$_SERVER['PHP_SELF']}?sort=dra";
-
-
break;
-
-
default:
-
-
$order_by = 'datesent DESC';
-
-
break;
-
}
-
-
-
-
// $sort will be appended to the pagination links.
-
-
$sort = $_GET['sort'];
-
-
}
-
else { // Use the default sorting order.
-
-
$order_by = 'datesent DESC';
-
-
$sort = 'drd';
-
}
-
-
-
-
-
-
-
-
-
// Make the query.
-
-
$query = "SELECT datesent, fromwhom, subject AS dr, message, newsid FROM news ORDER BY $order_by LIMIT $start, $display";
-
$result = @mysql_query ($query);
-
// Run the query.
-
-
-
-
//Table header.
-
-
echo '<table align="center" cellspacing="0" cellpadding="5">
-
<tr>';
-
-
echo'';
-
-
-
echo '<td align="left"><b><a href="' . $link1 . '">Date sent</a></b></td>
-
<td align="left"><b><a href="' . $link2 . '">From whom</a></b></td>
-
<td align="left"><b><a href="' . $link3 . '">Subject</a></b></td>
-
<td align="left"><b>Message</b></td>
-
-
</tr>
-
';
-
-
-
-
// Fetch and print all the records.
-
-
$bg = '#eeeeee';
-
// Set the background color.
-
-
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
-
-
$bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee');
-
// Switch the background color.
-
-
echo '<tr bgcolor="' .
-
$bg . '">
-
-
-
-
-
-
-
-
-
-
-
<td align="left">' . $row['datesent'] . ' </td>
-
<td align="left">' . $row['fromwhom'] . '</td>
-
<td align="left">' . $row['dr'] . '</td>
-
<td align="left">
-
<td align="left">' . $row['message'] . '
-
-
-
-
-
</td>
-
</tr>
-
';
-
}
-
-
echo '</table>';
-
-
mysql_free_result ($result); // Free up the resources.
-
-
mysql_close(); // Close the database connection.
-
-
// Make the links to other pages, if necessary.
-
if ($num_pages > 1) {
-
-
echo '<br /><p>';
-
// Determine what page the script is on.
-
$current_page = ($start/$display) + 1;
-
-
// If it's not the first page, make a Previous button.
-
if ($current_page != 1) {
-
echo '<a href="home.php?s=' . ($start - $display) . '&np=' . $num_pages . '&sort=' . $sort .'">Previous</a> ';
-
}
-
-
// Make all the numbered pages.
-
for ($i = 1; $i <= $num_pages; $i++) {
-
if ($i != $current_page) {
-
echo '<a href="home.php?s=' . (($display * ($i - 1))) . '&np=' . $num_pages . '&sort=' . $sort .'">' . $i . '</a> ';
-
} else {
-
echo $i . ' ';
-
}
-
}
-
-
// If it's not the last page, make a Next button.
-
if ($current_page != $num_pages) {
-
echo '<a href="home.php?s=' . ($start + $display) . '&np=' . $num_pages . '&sort=' . $sort .'">Next</a>';
-
}
-
-
echo '</p>';
-
-
} // End of links section.
-
-
-
// Include the HTML footer file.
-
-
include ('./includes/footer.html');
-
-
-
} //end of else logged in
-
?>
-
Markus 6,050
Recognized Expert Expert
mmmm strange post.
I've seen this happen a few times.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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">
|
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.
=======================================================
|
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.
|
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)):
|
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.
| |
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
|
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;
|
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?
|
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/");
|
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...
|
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...
| |
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...
|
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,...
|
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...
|
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...
|
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();...
|
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...
| |
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
|
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...
| |