user3079125
user3079125

Reputation: 35

PHP MYSQL Result is not complete

This code works unless $market returns more then one word. IE: Colorado would return Pueblo, which works. When it returns "colorado springs", $market only echos "colorado" and SID never displays. I am sorry the code might be ugly, but its all I got in a rut.

$pickstate = $_POST['state'];
    $result = mysql_query("SELECT * FROM ppc WHERE State='" . $pickstate . "'");
      if (!$result) {
        echo("<P>Error performing query: " .
             mysql_error() . "</P>");
       exit();
  }

echo '<form action="" method="POST"><select id="Market" name="Market">';

while ($row = mysql_fetch_array($result)) {
    echo ( '<option value= '.$row['Market'].' onclick="this.form.submit();">'.$row['Market'].'</option>' );
}
echo "</select></form>";

$market = $_POST['Market'];
echo "Market = " . $market . "<br />";
$sid = mysql_query("SELECT SID FROM ppc WHERE Market='" . $market . "'");
while ($row = mysql_fetch_array($sid)) {
    echo '<p>SID = ' . $row['SID'] . '</p><br />';
}

Upvotes: 0

Views: 45

Answers (2)

miyasudokoro
miyasudokoro

Reputation: 1745

You are missing the quotation marks around the value. You need to put the quotation marks in just as they are around the onclick. It shows only the first word because the following words are lost due to the space. The quotation marks make it include the space and the following words.

echo ( '<option value= "'.$row['Market'].'" onclick="this.form.submit();">'.$row['Market'].'</option>' );

Upvotes: 0

PatomaS
PatomaS

Reputation: 1603

considering your actual code, you have to change

echo "<option value=" . $row['Market'] . " onclick=\"this.form.submit();\" . $row['Market'] . "</option>";

to this

echo "<option value=" . $row['Market'] . " onclick=\"this.form.submit();\"" . $row['Market'] . "</option>";

Also, you may consider writing those lines with readability in mind, something like this:

echo ( '<option value= '.$row['Market'].' onclick="this.form.submit();"'.$row['Market'].'</option>' );

Combining the different kind of quotes will help. When you have to output double quotes, try surrounding that with single ones.

Upvotes: 1

Related Questions