...

View Full Version : mysql_query not working



UrbanTwitch
08-15-2008, 12:11 AM
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 :-)

thesmart1
08-15-2008, 12:56 AM
// 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?



// 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).

UrbanTwitch
08-15-2008, 01:00 AM
$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

tagnu
08-15-2008, 01:24 AM
[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.

UrbanTwitch
08-15-2008, 01:40 AM
Aha, thanks so much!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum