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 10 of 10
  1. #1
    Regular Coder
    Join Date
    Jan 2008
    Posts
    216
    Thanks
    10
    Thanked 1 Time in 1 Post

    While loop help plz

    I have problem displaying multiple records from a mysql database, the code wont display anything, can anyone please help?

    My code is

    PHP Code:
    <?php
    session_start
    (); 
    if(!isset(
    $_SESSION['username'])){ 
    header("Location: index2.php"); 
    }  

    include(
    "database.php");
    include(
    "loginemployer.php");
    ?>


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Jobs4U</title>


    <!--CSS Stylesheet  -->
        <link rel="stylesheet" type="text/css" href="./css/main.css" />
        <link rel="stylesheet" type="text/css" href="./css/registerform.css" />
        </head>

        <body style="margin-left:1px;margin-right:1px;margin-bottom:0px;margin-top:0px;">
        
    <!--Main Container  -->    
        <div id="container">

    <!--Main Header  -->
        <div id="header" style="width: 988px; height: 154px">
            &nbsp;
        </div>


    <!-- Navigation Menu -->
        <div id="nav_menu">
            <div class="link_container" style="width: 852px; height: 32px">
                <a href="Index.php" class="main_nav">home</a><span class="link_separator">::</span>
                <a href="page.htm" class="main_nav">products</a><span class="link_separator">::</span>
                <a href="page.htm" class="main_nav">services</a><span class="link_separator">::</span>
                <a href="page.htm" class="main_nav">about us</a><span class="link_separator">::</span>
                <a href="page.htm" class="main_nav">contact</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <input type="text" name="search0" maxlength="30" size="30" >&nbsp;&nbsp;
                <a href="page.htm" class="main_nav">Quick Search&gt;&gt;&gt;</a></div>
        </div>

    <!-- Container (left) -->    
        <div id="body">
            <div id="body-left-panel" style="width: 654px; height: 811px">
                <div style="padding:10px;">
                    
    <!-- Left container 1(Top) -->
                    <div class="box_upper_partviewdetails">
                        <img src="img/box_up-left_edge.png" alt="" class="align-left"/>
                        <img src="img/box_up-right_edge.png" alt="" class="align-right"/>
                        <span class="box_header">:: Company Account Details</span></div>
                        
    <!--(Middle)  -->
                    <div class="box_middle_partviewdetails">
                    <div class="pad_15tah">
                    
    <!--Register Form  --> 
     
    <?php  
     
       
     $q 
    mysql_fetch_array(mysql_query("SELECT * FROM job WHERE username='" $_SESSION["username"] . "'"));
     while (
    $account = @mysql_fetch_array($q))
     {
       
      
    $id=$account["id"];
      
    $jobtitle=$account["jobtitle"];
      
      
      
    echo 
    "<table>";
    echo 
    "<tr><td>$jobtitle</td></tr>";
    echo 
    "</table>"
      
      }
    ?> 
    <!--this will show whatever is in the $message variable -->                    
    </div>
    </div>


                 
    <!-- (bottom) -->             
                <div class="box_lower_part">
                    <img src="img/box_low-left_edge.png" alt="" class="align-left"/>
                    <img src="img/box_low-right_edge.png" alt="" class="align-right"/>
                </div>
                
    <!--Left Container 2 (Top)  -->
                </div>
                </div>
            <p>
            
    <!--Right Panel 1  -->
            </p>
            <div id="body-right-panel" style="width: 333px; height: 811px">
                <div style="padding:10px;">


    <!--Top  -->
                    <div class="box_upper_part">
                        <img src="img/box_up-left_edge_dark.png" alt="" class="align-left"/>
                        <img src="img/box_up-right_edge_dark.png" alt="" class="align-right"/>
                        <span class="box_header">Employer Login</span></div>


    <!--Middle  -->
                    <div class="box_middle_part">
                        <div style="padding:5px;">
                        <ul class="img_red">
                            
                
                <!--Login -->                        
                <?php displayLoginemployer(); ?>
                    <p><br /></p>
                </div>
                </div>
                
            
    <!-- (bottom)  -->        
                    <div class="box_lower_part">
                    <img src="img/box_low-left_edge_dark.png" alt="" class="align-left"/>
                    <img src="img/box_low-right_edge_dark.png" alt="" class="align-right"/>
                    </div>
                    
                    
    <!--Right Panel 2 (top)  -->
            <div class="box_upper_part" style="width: 313px; height: 29px">
                <img src="img/box_up-left_edge_dark_nodot.png" alt="" class="align-left"/>
                <img src="img/box_up-right_edge_dark.png" alt="" class="align-right"/>
                <span class="box_header">:: Resource Centre</span>
            </div>
            
                    
    <!--Middle  -->
            <div class="box_middle_part">
            <div style="padding:10px;">
            <div align="center">
                    <table border="0" width="65%" id="table12" cellspacing="0" cellpadding="0" bgcolor="#E7E6E4">
                        <tr>
                            <td>
                            <img border="0" src="images/cv.gif" width="221" height="23"></td>
                        </tr>
                        <tr>
                            <td><p>&nbsp;</p>
                                <p><span class="navyboldtxt">CV Advice</span>. </p>
                                <p>&nbsp;- <a href="cvadvice.php">How to create a CV</a> </p>
                                <p>&nbsp;- <a href="cvreferences.php">CV References</a> </p>
                                <p>&nbsp;</p>
                            </td>
                        </tr>
                    </table>
                    <table border="0" width="65%" id="table13" cellspacing="0" cellpadding="0" bgcolor="#E7E6E4">
                        <tr>
                            <td>
                                <img border="0" src="images/interview.gif" width="221" height="23">
                            </td>
                        </tr>
                        <tr>
                            <td>&nbsp;<p><span class="navyboldtxt">
                                Interview Advice</span> - </p>
                                <p>&nbsp;&nbsp;- <a href="interviewadvice.php">Interview tips</a> </p>
                                <p>&nbsp;</p><p>&nbsp;</td>
                        </tr>
                    </table>
            </div>
            </div>
            </div>
            
                    
    <!-- (bottom)  -->
            <div class="box_lower_part" style="width: 313px; height: 22px">
                <img src="img/box_low-left_edge_dark.png" alt="" class="align-left"/>
                <img src="img/box_low-right_edge_dark.png" alt="" class="align-right"/>
            </div>
            </div>
            </div>
            </div>
            
            
    <!-- Footer  -->
            <div id="footer">        
            <div id="footer_designby" style="width: 987px; height: 30px">
                <div class="designedby">Designed by 
                    <a href=""></a></div>
            </div>
            </div>
            </div>    

    </body>
    </html>

  • #2
    Regular Coder
    Join Date
    Jan 2008
    Posts
    216
    Thanks
    10
    Thanked 1 Time in 1 Post
    I am using the following while loop, which looks up a table "job" and checks the username session of the person is logged in, the code is then supposed loop round each record and display the jobtitle of each job in the table assigned to that user. The code displays nothing when i run it,
    can someone please help, i dont know what the problem is.

    PHP Code:
    <?php   
      
        
     $q 
    mysql_fetch_array(mysql_query("SELECT * FROM job WHERE username='" $_SESSION["username"] . "'")); 
     while (
    $account = @mysql_fetch_array($q)) 
     { 
        
      
    $id=$account["id"]; 
      
    $jobtitle=$account["jobtitle"]; 
       
       
       
    echo 
    "<table>"
    echo 
    "<tr><td>$jobtitle</td></tr>"
    echo 
    "</table>";  
       
      } 
    ?>

  • #3
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    PHP Code:
    <?php   

    $sessid 
    $_SESSION["username"] ;
    // look to the value if is what you expect
    print $sessid;

    $query "SELECT * FROM job WHERE username='" $sessid"'";
    // look if the query have valid mysql syntax
    print $query;

    $result mysql_query($query);
    if(!
    $result){
       
    // check if is something wrong
       
    print "this don't work";
    }else{
      if(
    $mysql_numrows($result) == 0){
         print 
    "no data";
     }else{
     while (
    $account = @mysql_fetch_array($result)) { 
        
    $id=$account["id"]; 
        
    $jobtitle=$account["jobtitle"]; 
       
    echo 
    "<table>"
    echo 
    "<tr><td>$jobtitle</td></tr>"
    echo 
    "</table>";  
      } 
     }
    }

    ?>

  • #4
    Regular Coder
    Join Date
    Jan 2008
    Posts
    216
    Thanks
    10
    Thanked 1 Time in 1 Post
    Quote Originally Posted by oesxyl View Post
    PHP Code:
    <?php   

    $sessid 
    $_SESSION["username"] ;
    // look to the value if is what you expect
    print $sessid;

    $query "SELECT * FROM job WHERE username='" $sessid"'";
    // look if the query have valid mysql syntax
    print $query;

    $result mysql_query($query);
    if(!
    $result){
       
    // check if is something wrong
       
    print "this don't work";
    }else{
      if(
    $mysql_numrows($result) == 0){
         print 
    "no data";
     }else{
     while (
    $account = @mysql_fetch_array($result)) { 
        
    $id=$account["id"]; 
        
    $jobtitle=$account["jobtitle"]; 
       
    echo 
    "<table>"
    echo 
    "<tr><td>$jobtitle</td></tr>"
    echo 
    "</table>";  
      } 
     }
    }

    ?>
    Hi oesxyl thanks for the reply, i tried the above code but im getting the following error:

    userSELECT * FROM job WHERE username='user'
    Fatal error: Function name must be a string in C:\wamp\www\Jobs4U\viewjob.php on line 79

    Sames to be the line:

    PHP Code:
      if($mysql_numrows($result) == 0){ 

    Im not sure whats happening here.

  • #5
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    hi,

    sorry, is my fault, I don't test it and I misspell the name of the function. Instead of this:

    Quote Originally Posted by PRodgers4284 View Post
    PHP Code:
      if($mysql_numrows($result) == 0){ 
    Im not sure whats happening here.
    must be:
    PHP Code:
      if($mysql_num_rows($result) == 0){ 
    best regards

  • #6
    Banned
    Join Date
    Feb 2008
    Location
    USA
    Posts
    61
    Thanks
    15
    Thanked 1 Time in 1 Post
    It also must have a " } " at the end of your code.

  • #7
    Regular Coder
    Join Date
    Jan 2008
    Posts
    216
    Thanks
    10
    Thanked 1 Time in 1 Post
    Quote Originally Posted by Dfraz View Post
    It also must have a " } " at the end of your code.
    At the very end of the php code?

  • #8
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by PRodgers4284 View Post
    At the very end of the php code?
    PHP Code:
    <?php   

    if(!$result){
    }else{
       if(
    $mysql_numrows($result) == 0){
         print 
    "no data";
       }else{
          while (
    $account = @mysql_fetch_array($result)){
       ....
          } 
       }
    }
    thank you for replay, but, I don't see where it is.

    best regards

  • #9
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    I hope that is final correction, I mess this line twice:

    PHP Code:
      if($mysql_numrows($result) == 0){ 
    - first missing a _
    - second have a additional $

    it must be:

    PHP Code:
      if(mysql_num_rows($result) == 0){ 
    I don't find any unclosed brackets but Dfraz or PRodgers4284 could
    confirm or not if I'm right.

    best regards

  • #10
    Regular Coder
    Join Date
    Jan 2008
    Posts
    216
    Thanks
    10
    Thanked 1 Time in 1 Post
    Quote Originally Posted by oesxyl View Post
    I hope that is final correction, I mess this line twice:

    PHP Code:
      if($mysql_numrows($result) == 0){ 
    - first missing a _
    - second have a additional $

    it must be:

    PHP Code:
      if(mysql_num_rows($result) == 0){ 
    I don't find any unclosed brackets but Dfraz or PRodgers4284 could
    confirm or not if I'm right.

    best regards
    This is correct, the problem was nothin to do with unclosed brackets


  •  

    Posting Permissions

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