Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-15-2008, 12:11 AM   PM User | #1
UrbanTwitch
Regular Coder

 
UrbanTwitch's Avatar
 
Join Date: Apr 2006
Posts: 485
Thanks: 44
Thanked 1 Time in 1 Post
UrbanTwitch is an unknown quantity at this point
mysql_query not working

PHP Code:
default: //set up the default page upon going to inbox.php
// find out how many rows are in the table 
$sql "SELECT COUNT(*) FROM privates";
$result mysql_query($sql$conn) or trigger_error("SQL"E_USER_ERROR);
$r mysql_fetch_row($result);
$msgs mysql_query("SELECT * FROM `privates` WHERE `to` = '" $logged[username] . "' ") or die(mysql_error()); //get all the
$a mysql_fetch_array($msgs);
$numrows $r[0];

// number of rows to show per page
$rowsperpage 10;
// find out total pages
$totalpages ceil($numrows $rowsperpage);

// get the current page or set a default
if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {
   
// cast var as int
   
$currentpage = (int) $_GET['currentpage'];
} else {
   
// default page num
   
$currentpage 1;
// end if

// if current page is greater than total pages...
if ($currentpage $totalpages) {
   
// set current page to last page
   
$currentpage $totalpages;
// end if
// if current page is less than first page...
if ($currentpage 1) {
   
// set current page to first page
   
$currentpage 1;
// end if

// the offset of the list, based on current page 
$offset = ($currentpage 1) * $rowsperpage;

// get the info from the db 
$sql "SELECT * FROM `privates` WHERE `to` = 'Dan' LIMIT $offset, $rowsperpage";
$result mysql_query($sql$conn) or trigger_error("SQL"E_USER_ERROR);
$getuserid mysql_query("SELECT * FROM `members` WHERE `username`  = '" $list['from'] . "'");
$mid mysql_fetch_array($getuserid);

// while there are rows to be fetched...
echo "<div id=title>Message Inbox</div><br>

<center> <div style='background: #DDF1FC;width: 380px;padding:4px; border:1px solid #AFC8D5;'><font color=#A0BBCA><b>Message Options:</font></b> <a href='inbox.php?page=compose'>Compose Message</a> <font color=#A0BBCA><b>|</b></font> <a href='inbox.php?page=deleteall'>Delete All Messages</a></div></center><br><table style='width:490px'  cellpadding='0' cellspacing='0'>"
;

while (
$list mysql_fetch_assoc($result)){
   
// echo data
   
echo "<tr><td style='position: realative;top: 3px;width:35px' align='center' rowspan=2>" $list['status'] . "</td>
<td><a href=inbox.php?page=view&id=" 
$list['pid'] . ">" $list['subject'] . "</a></td><td rowspan='2' style='width:35px;'><a href=inbox.php?page=delete&id=" $list['pid'] . ">
<img src='http://sodadome.com/phpimgs/cross.png' border='0' title='Delete Message?'></a></td></tr>
<tr><td style='width:233px;'>by <a href=members.php?user=$mid[id]><b>" 
$list['from'] . " ID: $mid[id]</b></a> on " $list['date'] . "</td></tr>";
// end while

echo "</table><br><br><center>";
/******  build the pagination links ******/
// range of num links to show
$range 3;

// if not on page 1, don't show back links
if ($currentpage 1) {
   
// show << link to go back to page 1
   
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> ";
   
// get previous page num
   
$prevpage $currentpage 1;
   
// show < link to go back to 1 page
   
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> ";
// end if 

// loop to show links to range of pages around current page
for ($x = (($currentpage $range) - 1); $x < (($currentpage $range) + 1); $x++) {
   
// if it's a valid page number...
   
if (($x 0) && ($x <= $totalpages)) {
      
// if we're on current page...
      
if ($x == $currentpage) {
         
// 'highlight' it but don't make a link
         
echo " [<b>$x</b>] ";
      
// if not current page...
      
} else {
         
// make it a link
     
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> ";
      } 
// end else
   
// end if 
// end for
         
// if not on last page, show forward and last page links    
if ($currentpage != $totalpages) {
   
// get next page
   
$nextpage $currentpage 1;
    
// echo forward link for next page 
   
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> ";
   
// echo forward link for lastpage
   
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> ";
// end if
/****** end build pagination links ******/
echo "</center>";
break; 
//end the default page 
As you can see the $mid[id] is suppose to get the id of who its from so they can go to their profile. Yet, there is no ID but a blank space. :-(

Btw guys I got pagination working :-)
__________________
Formerly MysticScript

6+ years club
UrbanTwitch is offline   Reply With Quote
Old 08-15-2008, 12:56 AM   PM User | #2
thesmart1
Regular Coder

 
thesmart1's Avatar
 
Join Date: Dec 2005
Posts: 369
Thanks: 7
Thanked 3 Times in 3 Posts
thesmart1 is an unknown quantity at this point
Quote:
Originally Posted by MysticScript View Post
PHP Code:
// get the info from the db  
$sql "SELECT * FROM `privates` WHERE `to` = 'Dan' LIMIT $offset, $rowsperpage";
$result mysql_query($sql$conn) or trigger_error("SQL"E_USER_ERROR);
$getuserid mysql_query("SELECT * FROM `members` WHERE `username`  = '" $list['from'] . "'");
$mid mysql_fetch_array($getuserid); 
Where's $list coming from?

Quote:
Originally Posted by MysticScript View Post
PHP Code:
    // show << link to go back to page 1
   
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> "
You should use &lt;&lt; instead of <<, less than characters might not show in a browser (and they won't validate).
thesmart1 is offline   Reply With Quote
Old 08-15-2008, 01:00 AM   PM User | #3
UrbanTwitch
Regular Coder

 
UrbanTwitch's Avatar
 
Join Date: Apr 2006
Posts: 485
Thanks: 44
Thanked 1 Time in 1 Post
UrbanTwitch is an unknown quantity at this point
PHP Code:
$sql "SELECT * FROM `privates` WHERE `to` = 'Dan' LIMIT $offset, $rowsperpage";

$result mysql_query($sql$conn) or trigger_error("SQL"E_USER_ERROR);

while (
$list mysql_fetch_assoc($result)){ 
from $result and $result is from $sql
__________________
Formerly MysticScript

6+ years club
UrbanTwitch is offline   Reply With Quote
Old 08-15-2008, 01:24 AM   PM User | #4
tagnu
Regular Coder

 
Join Date: Nov 2007
Location: 127.0.0.1
Posts: 348
Thanks: 26
Thanked 40 Times in 39 Posts
tagnu will become famous soon enough
Quote:
Originally Posted by MysticScript View Post
[PHP]default: /
$getuserid = mysql_query("SELECT * FROM `members` WHERE `username` = '" . $list['from'] . "'");
$mid = mysql_fetch_array($getuserid);

// while there are rows to be fetched...
echo "<div id=title>Message Inbox</div><br>

<center> <div style='background: #DDF1FC;width: 380px;padding:4px; border:1px solid #AFC8D5;'><font color=#A0BBCA><b>Message Options:</font></b> <a href='inbox.php?page=compose'>Compose Message</a> <font color=#A0BBCA><b>|</b></font> <a href='inbox.php?page=deleteall'>Delete All Messages</a></div></center><br><table style='width:490px' cellpadding='0' cellspacing='0'>";

while ($list = mysql_fetch_assoc($result)){
Hi, you are using the variable $list['from'] in the first query, before it is being created in the subsequent lines. I guess this is the issue.
__________________
Blog Charity:Water
WhatisWrongWith.me/tagnu - Send me anonymous feedback.
tagnu is offline   Reply With Quote
Old 08-15-2008, 01:40 AM   PM User | #5
UrbanTwitch
Regular Coder

 
UrbanTwitch's Avatar
 
Join Date: Apr 2006
Posts: 485
Thanks: 44
Thanked 1 Time in 1 Post
UrbanTwitch is an unknown quantity at this point
Aha, thanks so much!
__________________
Formerly MysticScript

6+ years club
UrbanTwitch is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:13 AM.


Advertisement
Log in to turn off these ads.