Professional Web Applications Themes

If/else statements - help. - PHP Development

Sorry to post so much code all at once but I'm banging my head against the wall trying to get this to work! Does anyone have any idea where I'm going wrong? Thanks in advance and sorry again for adding so much code... <TABLE border="1" bordercolor="#000000" cellspacing="0"> <TR> <TD> <?php include("misc.inc"); $connection = mysql_connect($host,$user,$password) or die ("Couldn't connect to the server"); $db = mysql_select_db($database,$connection) or die ("Couldn't select the database"); /* based upon the selection from the drop-down list, select the player's basic details and format his birthdate to the english format */ $query = "SELECT *, DATE_FORMAT(birthdate, '%d/%m/%y') AS ...

  1. #1

    Default If/else statements - help.

    Sorry to post so much code all at once but I'm banging my head against
    the wall trying to get this to work!

    Does anyone have any idea where I'm going wrong?

    Thanks in advance and sorry again for adding so much code...


    <TABLE border="1" bordercolor="#000000" cellspacing="0">
    <TR>
    <TD>

    <?php

    include("misc.inc");

    $connection = mysql_connect($host,$user,$password)
    or die ("Couldn't connect to the server");

    $db = mysql_select_db($database,$connection)
    or die ("Couldn't select the database");


    /* based upon the selection from the drop-down list, select the
    player's basic details and format his
    birthdate to the english format */

    $query = "SELECT *, DATE_FORMAT(birthdate, '%d/%m/%y') AS birth FROM
    player WHERE playerid='{$_POST['interest']}'";
    $result = mysql_query($query)
    or die ("Couldn't execute query");

    $row = mysql_fetch_array($result);


    /* again, based upon the selection from the drop-down list, select
    all the player's historical details from
    the playerhistory table ensuring the date joined is in the english
    format */

    $query2 = "SELECT *, DATE_FORMAT(joined, '%d/%m/%Y') AS joined FROM
    playerhistory WHERE playerid='{$_POST['interest']}'";
    $result2 = mysql_query($query2)
    or die ("Couldn't execute query2");

    $row2 = mysql_fetch_array($result2);



    /* This selects all records from player appearances table and links
    with playerhistory table

    $query3 = "SELECT * FROM playerapps LEFT JOIN playerhistory ON
    playerapps.playerhistid = playerhistory.playerhistid";
    $result3 = mysql_query($query3)
    or die ("Couldn't execute query3");

    $rows3 = mysql_fetch_array($result3);
    $nrows3 = mysql_num_rows($result3);


    /* display the results in a table */

    print "<TABLE border='1' bordercolor='#000000' width='800'
    class='table'>\n";



    print "<tr valign='top'>\n";
    printf ("<td width='90'><b>%s</b>\n",$row['forename']);
    printf ("<b>%s</b></td>\n",$row["surname"]);
    print "<td width='70'></td>\n";
    print "<td width='70'></td>\n";
    print "<td width='70'></td>\n";
    print "<td width='70'></td>\n";
    print "<td width='70'></td>\n";
    print "<td width='70'></td>\n";
    print "</tr>\n";

    print "<tr>\n";
    print "<td>BIRTHDATE:</td>\n";
    printf ("<td>%s</td>\n",$row["birth"]);
    print "</tr>\n";

    print "<tr>\n";
    print "<td>BIRTHPLACE:</td>\n";
    printf ("<td>%s</td>\n",$row['birthplace']);
    print "</tr>\n";

    print "<tr>\n";
    print "<td>NATIONALITY:</td>\n";
    printf ("<td>%s</td>\n",$row['nationality']);
    print "<tr>\n";

    print "<tr>\n";
    print "<td>POSITION:</td>\n";
    printf ("<td>%s</td>\n",$row['position']);
    print "</tr>\n";
    print "</TABLE>\n";

    print "<TABLE border='1' bordercolor='#000000' width='700'
    class='table'>\n";
    print "<tr align='center' class='heading'>\n";
    print "<td bgcolor='#000066' width='70'>JOINED</td>\n";
    print "<td bgcolor='#000066' width='70'>FROM</td>\n";
    print "<td bgcolor='#000066' width='70'>TO</td>\n";
    print "<td bgcolor='#000066' width='70'>VALUE</td>\n";

    print "<td bgcolor='#000066' width='70'>FULL APPS</td>\n";
    print "<td bgcolor='#000066' width='70'>SUB APPS</td>\n";
    print "<td bgcolor='#000066' width='70'>GOALS</td>\n";
    print "<td bgcolor='#000066' width='70'>RED CARDS</td>\n";
    print "<td bgcolor='#000066' width='70'>YELLOW CARDS</td>\n";
    print "</tr>\n";

    while ($rows3 = mysql_fetch_array($result3))

    {

    print "<tr align='center'>\n";
    printf ("<td width='70'>%s</td>\n",$row2['joined']);
    printf ("<td width='70'>%s</td>\n",$row2['goals']);
    printf ("<td width='70'>%s</td>\n",$row2['toclub']);
    printf ("<td width='70'>%s</td>\n",$row2['boughtfor']);
    print "</tr>\n";

    if ($nrows3 == 1)

    {
    printf ("<td width='70'>%s</td>\n",$rows3['apps']);
    printf ("<td width='70'>%s</td>\n",$rows3['subapps']);
    printf ("<td width='70'>%s</td>\n",$rows3['goals']);
    printf ("<td width='70'>%s</td>\n",$rows3['redcards']);
    printf ("<td width='70'>%s</td>\n",$rows3['yellowcards']);
    print "</tr>\n";
    }
    else
    {
    while ($rows3 = mysql_fetch_array($result3))
    {
    printf ("<td width='70'>%s</td>\n",$rows3['apps']);
    printf ("<td width='70'>%s</td>\n",$rows3['subapps']);
    printf ("<td width='70'>%s</td>\n",$rows3['goals']);
    printf ("<td width='70'>%s</td>\n",$rows3['redcards']);
    printf ("<td width='70'>%s</td>\n",$rows3['yellowcards']);
    print "</tr>\n";
    print "<tr>\n";
    print "<td></td>\n";
    print "<td></td>\n";
    print "<td></td>\n";
    print "<td></td>\n";
    }

    }

    }



    print "</TABLE>\n";


    ?>

    </TD>
    </TR>
    </TABLE>
    Chris Guest

  2. #2

    Default Re: If/else statements - help.

    On 28 Jun 2003 06:24:13 -0700, [email]hsirhchotmail.com[/email] (Chris) wrote:
    >Sorry to post so much code all at once but I'm banging my head against
    >the wall trying to get this to work!
    >
    >Does anyone have any idea where I'm going wrong?
    >
    >Thanks in advance and sorry again for adding so much code...
    This not a good way to ask a question - you've sent 160 lines of code, but
    you've not said anything about:

    - What's going wrong
    - What errors you get, if any
    - What output you get, if any
    - What you were expecting
    - What you've tried to fix the code
    - And you haven't tried to cut down the code to the minimum required to show
    your (unstated) problem.

    The only clue is in your subject line, that it's something to do with an
    if/else.

    [big snip]
    > $query3 = "SELECT * FROM playerapps LEFT JOIN playerhistory ON
    >playerapps.playerhistid = playerhistory.playerhistid";
    > $result3 = mysql_query($query3)
    > or die ("Couldn't execute query3");
    >
    > $rows3 = mysql_fetch_array($result3);
    > $nrows3 = mysql_num_rows($result3);
    >
    [another big snip]
    >
    >while ($rows3 = mysql_fetch_array($result3))
    You've fetched one row from $result3 here.

    [snip]
    >if ($nrows3 == 1)
    If there is one row then...
    > {
    [snip print of $rows3]

    You print this row.
    > }
    > else
    > {
    > while ($rows3 = mysql_fetch_array($result3))
    Else, you start a loop by fetching another row - but you've not yet printed
    out the $row3 you fetched the first time you fetched from $result3 above, so
    you've lost that row now.
    > {
    [snip print of $rows3]
    > }
    >
    > }
    >
    >}
    [another snip]

    So you're missing some data, but is that the problem you were asking about?
    You've not said what you wanted, so no idea if that's what's missing.

    --
    Andy Hassall (andyandyh.co.uk) icq(5747695) ([url]http://www.andyh.co.uk[/url])
    Space: disk usage ysis tool ([url]http://www.andyhsoftware.co.uk/space[/url])
    Andy Hassall Guest

Similar Threads

  1. If Statements????
    By ccarterca in forum Macromedia Dynamic HTML
    Replies: 0
    Last Post: October 17th, 12:34 PM
  2. 2 sql statements in one <cfquery>
    By Kiriran in forum Coldfusion Database Access
    Replies: 12
    Last Post: May 13th, 04:07 PM
  3. If statements in PHP?
    By barbedwire103 in forum Dreamweaver AppDev
    Replies: 1
    Last Post: April 11th, 11:24 AM
  4. Include statements
    By The Voivod in forum PHP Development
    Replies: 1
    Last Post: August 5th, 06:40 AM
  5. echo statements
    By Jay Fitzgerald in forum PHP Development
    Replies: 2
    Last Post: July 19th, 12:36 AM

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
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139