Jump to content

[SOLVED] Weird Result


june_c21

Recommended Posts

i don't understand why this code can get exactly the same output from database. Did i miss out something ?? Pls help and guide me. thanks in advance

the sql statement are correct when i run in phpmyadmin but why when display in IE , it came out same output and not according the one i try in phpmyadmin

 

if ($GF = "1" && $Year = "2006")
{
$query = "SELECT reg_no, title1, incident_date, fault_rep_id, secr_recd, status FROM report WHERE GF = '1'AND year = '2006' ";
$result = mysql_query($query, $dblink);
while($myrow = mysql_fetch_row($result))
{

echo "<tr><td align=center><span class=style2>" . $myrow[0] . "</span</td><td align=center><span class=style2>" . $myrow[1] . "</span</td><td align=center><span class=style2>" . $myrow[2] . "</td></span><td><span class=style2>" . $myrow[3] . "</span></td><td align=center><span class=style2>" . $myrow[4] . "</span></td><td align=center><span class=style2>" . $myrow[5] . "</span></td></tr>";
    }
}

if ($GF = "2" && $Year = "2006")
{
$query = "SELECT reg_no,title1,incident_date,fault_rep_id,secr_recd,status from report where GF='2' AND year = '2006'  ";
$result = mysql_query($query, $dblink);
while($myrow = mysql_fetch_row($result))
{

echo "<tr><td align=center><span class=style2>" . $myrow[0] . "</span</td><td align=center><span class=style2>" . $myrow[1] . "</span</td><td align=center><span class=style2>" . $myrow[2] . "</td></span><td><span class=style2>" . $myrow[3] . "</span></td><td align=center><span class=style2>" . $myrow[4] . "</span></td><td align=center><span class=style2>" . $myrow[5] . "</span></td></tr>";
    }
}

Link to comment
Share on other sites

Ah, now I see. Hard to read your code with its lack of indentation. Where do you define $GF and $Year? Also note that = is an assignment operator not comparison. You need ==

 

Its likely your if should look something like....

 

if ($_GET['GF'] == 1 && $_GET['Year'] == 2006) {

Link to comment
Share on other sites

Ah, now I see. Hard to read your code with its lack of indentation. Where do you define $GF and $Year? Also note that = is an assignment operator not comparison. You need ==

 

Its likely your if should look something like....

 

if ($_GET['GF'] == 1 && $_GET['Year'] == 2006) {

 

i still having problem to display the result. it came out not according to what i choose (user input)

Link to comment
Share on other sites

i still having problem to display the result. it came out not according to what i choose (user input)

 

And what have you tried to debug the issue? Did you echo the query to the page to verify that the query is what you expect? Are there any results or just incorrect results? We have no idea what is in your database and what you expect to be returned.

 

You never stated that the two values are supposed to come from the GET array, that was an assumption that thorpe made. Is that the case? Where are $GF and $Year supposed to be defined?

 

In any event the logic in your code is horribly inefficient. As thorpe already stated having two IF statements makes no sense sice you are just using those values in the query anyway. The only prupose would be for validating that the values are within the proper range. And, if that's the case you only need one IF statement. You also don't need to have two sets of code for displaying the results.

 

This won't "fix" whatevr the issue is with not gettng the correct results, but it will clean it up. But, I did add some debuggin code to help trace the problem. I also noticed that the code to write the results had some erros as well

 

<?php
//IF statement used just to validate the range of the values
if ($Year = "2006" && ($GF = "1" || $GF = "2"))
{
    $query = "SELECT reg_no, title1, incident_date, fault_rep_id, secr_recd, status
              FROM report WHERE GF = '" . $GF . "'AND year = '" . $Year . "'";
    $result = mysql_query($query, $dblink);

    if ($result==false) { //Error with Query
        echo "The query:<br />$query<br />Produced the error:<br />".mysql_error());

    } else if (mysql_num_rows($result)==0) { //No results
        echo "The query:<br />$query<br />Returned 0 records.";

    } else { //Query was successful & there were results
        while($myrow = mysql_fetch_assoc($result))
        {
            echo "<tr>";
            echo "<td align=\"center\"><span class=\"style2\">" . $myrow['reg_no'] . "</span></td>";
            echo "<td align=\"center\"><span class=\"style2\">" . $myrow['title1'] . "</span></td>";
            echo "<td align=\"center\"><span class=\"style2\">" . $myrow['incident_date'] . "</span></td>";
            echo "<td><span class=\"style2\">" . $myrow['fault_rep_id'] . "</span></td>";
            echo "<td align=\"center\"><span class=\"style2\">" . $myrow['secr_recd'] . "</span></td>";
            echo "<td align=\"center\"><span class=\"style2\">" . $myrow['status'] . "</span></td>";
            echo "</tr>";
        }
    }
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.