Pulling Up Detailed Lists

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

4Boredom
Forum Contributor
Posts: 176
Joined: Tue Nov 08, 2005 4:29 pm

Pulling Up Detailed Lists

Post by 4Boredom »

So I fixed my server connection issues and have been diligently working on the user content. Login and everything works, I can greet the user, and everything in my USERS database works (their personal info and how many points they have).

What i want to do now is display HOW they got those points. I have a db with the following

tasknum (will auto_increment)
username
date
task (what they did)
points
notes

So I want to pull all of the tasknums from the database for username and display them.. and the other things as well... Ive been taking a stab at this, but have only done arrays for displaying pictures and am having issues reusing the code.. can anyone help me solve this?

Code: Select all

$display= mysql_query("SELECT * FROM `points` WHERE `username`=".$username.");
if(!$display) { print("We do not have a task recorded you in the database."); } else {
$row = mysql_fetch_array($display);
if(!empty($row['tasknum'])){
	$output.='$date $task $points $notes';
	print($output);
} else {
	print("You have no tasks recorded on record.");
}
}
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

Is this just a test project of yours? If not, I'd recommend you seriously reconsider the database design.

If it is, cool.

Either way, your code sniplet has a small problem with your first variable definition. It is missing a double quote at the end. You are also missing single quotes around the username variable.
In other words, it should read like this:

Code: Select all

$display= mysql_query("SELECT * FROM `points` WHERE `username`= '" . $username . "')";
Anyways, so what is your problem? What you having trouble doing aside from this?
4Boredom
Forum Contributor
Posts: 176
Joined: Tue Nov 08, 2005 4:29 pm

Post by 4Boredom »

The page states like this:

In all, you have earned 10 lifetime points.
You have 10 points left to use

Here is your point earning summary:

Then I want to display them from my points db The following code makes the page BLANK... error reporting turned up nothing

Code: Select all

$display= mysql_query("SELECT * FROM `points` WHERE `username`= '" . $username . "')"; 
if(!$display) { print("We do not have a task recorded you in the database."); } else {
$row = mysql_fetch_array($display);
if(!empty($row['tasknum'])){
	$output.='You have no tasks recorded on record.';
	print($output);
} else {
	print("$date $task $points $notes");
}
}
4Boredom
Forum Contributor
Posts: 176
Joined: Tue Nov 08, 2005 4:29 pm

Post by 4Boredom »

does it affect my table at all that I have 2 databases, 'users' and 'points' and username is a field on both, but one default one that is called is from users.
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post by Maugrim_The_Reaper »

Code: Select all

$output.='$date $task $points $notes';
Something wrong here - where are these variable declared???

Maybe you meant:

Code: Select all

$output.=$row['date'] . $row['task'] . $row['points'] . $row['notes'];
4Boredom
Forum Contributor
Posts: 176
Joined: Tue Nov 08, 2005 4:29 pm

Post by 4Boredom »

this is wierd..

I have error reporting on and the page STILL comes back blank..

loads nothing
4Boredom
Forum Contributor
Posts: 176
Joined: Tue Nov 08, 2005 4:29 pm

Post by 4Boredom »

this is the updated erroneous code... when i remove it the page loads

Code: Select all

$display= mysql_query("SELECT * FROM `points` WHERE `username`= '" . $username . "')"; 
if(!$display) { print("We do not have a task recorded you in the database."); } else {
$row = mysql_fetch_array($display);
if(!empty($row['tasknum'])){
	$output.='You have no tasks recorded on record.';
	print($output);
} else {
	$output.=$row['date'] . $row['task'] . $row['points'] . $row['notes'];
}
}
This is the code on a different page to call the variables.. the call to the different page works for my users table.. this is the points table

Code: Select all

$info3 = mysql_query("SELECT * FROM `points` WHERE username = '{$username}' ");
if(!$info3){
	die("Could not get user info");
}
$info3 = mysql_fetch_array($info3);

$tasknum = $info3['tasknum'];
$date = $info3['date'];
$task = $info3['task'];
$points = $info3['points'];
$notes = $info3['notes'];
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

The reason your not seeing the error because your display_errors configuration is set to false. Therefore, when a parse error occurs no messages are displayed (not good for development, but should be done in production). You can either modify your php.ini or add a php_flag display_errors true in an .htaccess file.

Finally, take a very close look where you put that double quote in your query.
4Boredom
Forum Contributor
Posts: 176
Joined: Tue Nov 08, 2005 4:29 pm

Post by 4Boredom »

I do that and this comes back

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, cgiadmin@yourhostingaccount.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.
4Boredom
Forum Contributor
Posts: 176
Joined: Tue Nov 08, 2005 4:29 pm

Post by 4Boredom »

the thing is... how does that block of text kill the entire code...

it should work :(
4Boredom
Forum Contributor
Posts: 176
Joined: Tue Nov 08, 2005 4:29 pm

Post by 4Boredom »

ok i kept debugging and now it comes up.. i am left with this error

Notice: Undefined variable: output in /hermes/bosweb01/b141/sl.nhforhealthcare/public_html/usermenu.php on line 49
You have no tasks recorded on record.

Code: Select all

<?
$display= mysql_query("SELECT * FROM `points` WHERE `username`= '" . $username . "'"); 
if(!$display) { print("We do not have a task recorded for you in the database."); } else {
$row = mysql_fetch_array($display);
if(!empty($row['tasknum'])){
	$output.='You have no tasks recorded on record.';
	print($output);
} else {
	$output.=$row['date'] . $row['task'] . $row['points'] . $row['notes'];
}
}


?>
4Boredom
Forum Contributor
Posts: 176
Joined: Tue Nov 08, 2005 4:29 pm

Post by 4Boredom »

ok I switched it up a little

I have a task entered and it doesnt show up

what im trying to do is grab the username that is already loaded from the userbase table...

and then pull up the date, task, points, and notes from the points table based on that username which is also in the points table.

can ANYoNEEE help

Code: Select all

$display= mysql_query("SELECT * FROM `points` WHERE `username`= '" . $username . "'"); 
if(!$display) { print("We do not have a task recorded for you in the database."); } else {
$row = mysql_fetch_array($display);
if(!empty($row['tasknum'])){
	echo 'You have no tasks recorded on record.';
} else {
	$output.=$row['date'] . $row['task'] . $row['points'] . $row['notes'];
	print($output);
}
}
SBukoski
Forum Contributor
Posts: 128
Joined: Wed May 21, 2003 10:39 pm
Location: Worcester, MA

Post by SBukoski »

You've got a few things going on in there that aren't quite right. You should be showing the first message based on "!$display", because that will tell you if the query failed or succeeded, not whether you actually have any tasks recorded. You got the notice because you are concatenating something to $option when $option had not yet been defined. See if the below code (with modifications) helps at all. I noticed inconsistent use of echo and print. Best to be consistent than to mix them up, in my opinion.

Code: Select all

$display= mysql_query("SELECT * FROM `points` WHERE `username`= '" . $username . "'");
$output = '';
if (!$display) 
{
     print("A database error has occurred. Please contact your administrator"); 
} 
else 
{
     if(!mysql_num_rows($display))
     {
          print('You have no tasks recorded on record.');
     } 
     else 
     {
          $row = mysql_fetch_assoc($display);
          $output. = $row['date'] . $row['task'] . $row['points'] . $row['notes'];
          print($output);
     }
}
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

4Boredom wrote:I do that and this comes back

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, cgiadmin@yourhostingaccount.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.
Try the following.

Code: Select all

php_flag  display_errors         on
As for your problem, SBukoski already covered the rest.. although I forgot to mention you probably should be passing $username through mysql_real_escape_string to protect against SQL injection.

Although, in the future do consider it is against our forum rules to bump your threads within 24 hours. But do familiarize yourself with the edit button to avoid bumping.
4Boredom
Forum Contributor
Posts: 176
Joined: Tue Nov 08, 2005 4:29 pm

Post by 4Boredom »

It shows one listing...

BUTTT it only pulled up the LAST entry for the person... i have 2 in for my test account and it only shows one

Also now that I entered a 2nd row in DB it produced the error report here

Code: Select all

if(!empty($row['tasknum'])){
	echo 'You have no tasks recorded on record.';
}
BAHHH this is tough
___

ok i will start to edit posts more...

it wasnt that i was trying to bump.. im at work and kept working on the problems finding new outlooks
Post Reply