55 users online (1 members and 54 guests)  


  Results 1 to 6 of 6

Related

  1. My Space Coding    Forum: Myspace Forum
    Replies: 3
  2. do you need Myspace coding help?    Forum: Myspace Forum
    Replies: 2
  3. My Space CSS coding... help!    Forum: Myspace Forum
    Replies: 0
  4. cgi confusion    Forum: CGI Perl Forum
    Replies: 27
  1. #1
    Replicada's Avatar
    New User

    Status
    Offline
    Join Date
    Jul 2008
    Posts
    3

    Question Coding Confusion

    well the code is below before i start my little frustrated rant.

    PHP Code:
    <?php
    session_start
    ();
    require (
    'config.php');
    include(
    'title.php');
    include(
    'resources.php');

    $messages mysql_query("SELECT * FROM messages WHERE user_id='$user'");
    $messages2 mysql_fetch_array($messages);
     
    ?>
     <table>
     <tr><td>From</td><td>Timesent</td><td>Subject</td></tr>
     <?php 
    if($messages2){
    while(
    $row mysql_fetch_array($messages))
     {
    $sender_id $row['sender_id'];
    $sender1 mysql_query("SELECT username FROM users WHERE id='$sender_id'");
    $sender2 mysql_fetch_array($sender1);
    $sender $sender2['username'];
    $subject $row['subject'];
    $message $row['message'];
    $time $row['time'];
    $date date('F j, Y, g:i a'$time);
    echo 
    "<tr><td>" $sender "</td><td>" $date "</td><td>" $subject "</td></tr>";
     }
    }
    else{echo 
    "<tr><td>You have no new Messages<td></tr>";}
     
     
    ?> </table>

     <?php include ('suffix.php'); ?>
    obviously the config, resources and other includes have within them predefined variables that are used in the script. The part that seems to be malfunctioning is the while loop, or thats what it seems.

    I have read on the php website the following, and it seems to apply:

    If two or more columns of the result have the same field names, the last column will take precedence. To access the other column(s) of the same name, you must use the numeric index of the column or make an alias for the column. For aliased columns, you cannot access the contents with the original column name.

    http://uk.php.net/manual/en/function...etch-array.php
    I am literally blown away at this point, all my other code seems to function fine, but this seems to hault at this hurdle. The diea behind it is that it looks up in a message database a user's id and finds references to all their messages, and siaplys one message per row of a table.

    The code does execute without error btw, its just it only displays the final message in the database !

    Database includes the following records:

    table messages
    user_id, sender_id, subject, message, time
    1,1,testing123,testing123,1234567890
    1,2,tester123,tester123,1234567899

    table users
    Username=Replicada, id=1
    Username=Demo, id=2

    Any help would be appreciated thanks
    Last edited by Replicada; 07-07-2008 at 09:08 AM.

  2. #2
    firmaterra's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Apr 2007
    Posts
    81

    Re: Coding Confusion

    Can you post the error message thrown??

  3. #3
    Replicada's Avatar
    New User

    Status
    Offline
    Join Date
    Jul 2008
    Posts
    3

    Re: Coding Confusion

    As i said its probably not a fault with my code, as it does execute without error. It's the fact that the Loop does not function as it should.

    When the query searches for all messages with user id 1, it should return 2 rows(As there are two messages for user 1), not just 1. Therefore i used a while loop to hopefully produce two rows in my table, but it only retrieves 1 row still, bizarely the last one...

    I was just wondering how you retrieve two rows in a query as the function mysql_fetch_array only retrieves a single row, and places it in an array for use in the script.

  4. #4
    QuietDean's Avatar
    Administrator

    Status
    Offline
    Join Date
    Oct 2000
    Location
    Bournemouth, UK
    Posts
    2,662

    Re: Coding Confusion

    Try using this code

    PHP Code:
    <?php
    session_start
    ();
    require (
    'config.php');
    include(
    'title.php');
    include(
    'resources.php');

    $messages mysql_query("SELECT * FROM messages WHERE user_id='$user'");

     
    ?>
     <table>
     <tr><td>From</td><td>Timesent</td><td>Subject</td></tr>
     <?php 

    while($row mysql_fetch_array($messages))
     {
    ...
    Also remove the closing } from the "if" I took out. Tell me how it goes.
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?

  5. #5
    HTML's Avatar
    Administrator

    Status
    Offline
    Join Date
    Aug 2000
    Posts
    3,445

    Follow HTML On Twitter Add HTML on Facebook Add HTML on Google+ Add HTML on Linkedin Visit HTML's Youtube Channel

    Re: Coding Confusion

    Are my eyes playing tricks on me or did I just read a post made today by quietdean?

    Welcome back stranger!
    AHFBWEB Less customers per server, more power for you!

    Business Class Shared Hosting

  6. #6
    QuietDean's Avatar
    Administrator

    Status
    Offline
    Join Date
    Oct 2000
    Location
    Bournemouth, UK
    Posts
    2,662

    Re: Coding Confusion

    Hi Dave
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?



Tags for this Thread