Need Help, Full Code And Background Provided

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

malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

lol bech

you should know by now the amount of times ive posted here

my net is down @ home and im @ uni, my web server account at uni only supports HTML not PHP, so i cant test it until i get on my web server at home, NET BACK ON IN 2 WEEKS!!! 2mb wahoooo!

still though what the hell is that code for!?!?!?!!?

also i was wondering, i heard about a function in PHP ythat turns a numerical value into a picture/graph is this true?
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

i think fastfingertips was getting excited and maybe didn't read the problem correctly. i would just ignore it. Unless he can tell you otherwise

Mark
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

yeah thats what i thought, i mean ive pretty much done exactly the same thing as i have done before sucessfully, only without the "double SQL filter"
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

well, i shoudl work now if you use the corrected query i gave you

Mark
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

thank you bech, you are always helpful

cheers mate
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

ok guys last night i edited and compacted all of the code i had into this

Code: Select all

<?php
$_SESSION['username'] = malcolmboston;
// database variables for connections 
$host = "localhost"; 
$user = "malcolmboston"; 
$password = "xxxxxxxx"; 
$DBname = "tees-drug-network"; 
$tablename = "private_messaging"; 
//connection variables completed 
// establishing connections 
$link = mysql_connect ($host, $user, $password); 
//connection established 
//the query defined 
$query = "SELECT * 
FROM $tablename 
WHERE recipient = '".$_SESSION['username']."' 
AND Read_Unread = 'unread'"; 
// select the database 
mysql_select_db($DBname); 
// query the database 
$result = mysql_query($query); 
$data = mysql_fetch_array($result, MYSQL_ASSOC);
//statement to see if theres any new e-mail for the user
if (mysql_num_rows($result) >=1) {
    header("mail_yes.php");
} else {
    header("mail_no.php");
}
exit;
now that will print my unread messages, ok thats done and working

how should i go about gathering unread messages?
should i create a new query or is there something else i can do?

also this is the bit i think i may have problems on
i had alot of problems trying to display what it actually in the array, i could only view what was in it with this

Code: Select all

<?php print_r $data ?>
is there anyway i could easily echo it in a page as what i usually do to do this isnt working!

after i know this then it'll be nearly completed

thanks in advance
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

what do you usually do?
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

well my code for one of my other projects is very similar

Code: Select all

<?php print $data['recipient']
?>
but this wont work :?
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

yeah, becuase you have a query that has return numerous rows.

What you need to do is this (your first useful use for a loop ;))

Code: Select all

while ($data = mysql_fetch_array($result, MYSQL_ASSOC)) {
    print $data['recipient'];
}
and remove this line, you don't need it

Code: Select all

$data = mysql_fetch_array($result, MYSQL_ASSOC);
Mark
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

ok cool, thanks alot, just one more question for when i come to echoing it for the user

say i have 16 unread messages each one coming from a different row
how do i turn row 1 into a var, row to into another var etc

i might no how to do this, because i only managed to fix the code i submitted 2 mins before i came out so didnt get to test this out, but it wouldnt do it last night
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

malcolmboston wrote:say i have 16 unread messages each one coming from a different row
how do i turn row 1 into a var, row to into another var etc
Why would you want to do that? The code i gave you will echo ALL unread messages (obviously you need to add the other print statement to print the other columns from the DB).

Mark
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

ah yeah sorry, i missed the comment about the loop

now getting the read messages i can do, dont need any code, just wondered what is the standard way of doing it?
creating a new query or something else?
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

i would do another query and select the messages that are read.

Mark
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

cheers bech, its appreciated
Post Reply