SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot NevadaSam's Avatar
    Join Date
    May 2006
    Location
    Georgia
    Posts
    112
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help finding what $row[$j] is in an IF STATEMENT

    This script prints the selected information from a database table.
    I want to modify it so it treats the data from a designated column differently.
    I need to know how to modify the first line I have commented out so the IF STATEMENT will say in PHP what I said in simple English.

    PHP Code:
    <?php
    $query 
    "SELECT `id`, `username`, `otherstuff` FROM `userTable`";
    $result mysqli_query($connect$query);

    echo 
    "<table border='1'><thead><tr>";
    $finfo mysqli_fetch_fields($result);
    for(
    $i 0;$i mysqli_num_fields($result);$i++)
    {
        echo 
    "<th>" .$finfo[$i]->name."</th>";
    }
    echo 
    "  </tr></thead><tbody>";
    for (
    $i 0$i mysqli_num_rows($result); $i++)
    {
        echo 
    "<tr>";
        
    $row mysqli_fetch_row($result);
        for(
    $j 0;$j<mysqli_num_fields($result);$j++)
        {
    //        if ($row[$j] is from the `username` field)
    //            echo("<td><strong>" . $row[$j] . "</strong></td>");
    //        else 
                
    echo("<td>" $row[$j] . "</td>");
        }
            echo 
    "</tr>";
    }
    echo 
    "</tbody></table>";
    ?>
    Sam
    ;

  2. #2
    hi galen's Avatar
    Join Date
    Jan 2006
    Location
    New Haven, CT
    Posts
    1,228
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try using mysqli_fetch_assoc instead of mysqli_fetch_row. then you can test if $j='username'

  3. #3
    SitePoint Zealot NevadaSam's Avatar
    Join Date
    May 2006
    Location
    Georgia
    Posts
    112
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    galen: That did not work for me because I would get an error of the index being wrong.

    Your post was very helpful. It got be to thinking and I found I could leave things as they are and use if ($j == '2') with [2] being the index of the username field. I can work with that until I understand PHP a lot better.

    Sam
    ;


Bookmarks

Posting Permissions

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