Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder UrbanTwitch's Avatar
    Join Date
    Apr 2006
    Posts
    485
    Thanks
    44
    Thanked 1 Time in 1 Post

    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

  • #2
    Regular Coder thesmart1's Avatar
    Join Date
    Dec 2005
    Posts
    369
    Thanks
    7
    Thanked 3 Times in 3 Posts
    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).

  • #3
    Regular Coder UrbanTwitch's Avatar
    Join Date
    Apr 2006
    Posts
    485
    Thanks
    44
    Thanked 1 Time in 1 Post
    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

  • #4
    Regular Coder
    Join Date
    Nov 2007
    Location
    127.0.0.1
    Posts
    348
    Thanks
    26
    Thanked 40 Times in 39 Posts
    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.

  • #5
    Regular Coder UrbanTwitch's Avatar
    Join Date
    Apr 2006
    Posts
    485
    Thanks
    44
    Thanked 1 Time in 1 Post
    Aha, thanks so much!
    Formerly MysticScript

    6+ years club


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •