Jump to content

[SOLVED] Query works on mysql prompt but not in php


rinuxl

Recommended Posts

I have to tables: organisatie and prsorg

mysql> SELECT orgId,orgNaam FROM organisatie;

+-------+-------------------+

| orgId | orgNaam          |

+-------+-------------------+

|    1 | Politie Flevoland |

|    2 | RaadMIV          |

+-------+-------------------+

2 rows in set (0.00 sec)

mysql> SELECT * FROM prsorg;

+----------+-------+-------+-------------------+--------------+

| prsorgId | prsId | orgId | prsorgFunctie    | prsorgActief |

+----------+-------+-------+-------------------+--------------+

|        1 |    1 |    1 | Beleidsmedewerker |            1 |

+----------+-------+-------+-------------------+--------------+

1 row in set (0.28 sec)

I use a  Join to show all organisations where a certain person is involved.

SELECT orgNaam, orgURL, orgPlaats, orgSoort, orgTelefoon FROM organisatie JOIN prsorg ON organisatie.orgId=prsorg.orgId WHERE prsorg.prsId=1;

+-------------------+---------------------------------+-----------+---------------------------+-------------+

| orgNaam          | orgURL                          | orgPlaats | orgSoort                  | orgTelefoon |

+-------------------+---------------------------------+-----------+---------------------------+-------------+

| Politie Flevoland | http://www.politie.nl/Flevoland | Lelystad  | Hulpverleningsorganisatie | 0900 8844  |

+-------------------+---------------------------------+-----------+---------------------------+-------------+

1 row in set (0.00 sec)

 

So, this is working fine on the mysql prompt.

Then why does this code in my php script doesn't return a single row?

  $sql = "SELECT orgNaam, orgURL, orgPlaats, orgSoort, orgTelefoon FROM organisatie JOIN prsorg ON organisatie.orgId=prsorg.orgId WHERE prsorg.prsId=".$_GET['prsId'];

  echo $sql."<br/>";

 

  $result = mysql_query ($sql);

  $row = mysql_fetch_array($result);

  echo mysql_errno()."<br/>"; // temp check for error

 

No row is selected with this code.

SO it seems that the same sql statement on the mysql prompt gives another result than in PHP. How can?

 

Any help should be nice....

 

 

Can we see your actual code? You don't appear to do anything with $row in the example above.

$lf=chr(11).chr(13);

 

echo '<table border="1">'.$lf;

echo "<th>Naam</th>".$lf;

echo "<th>website</th>".$lf;

echo "<th>Plaats</th>".$lf;

echo "<th>Soort org.</th>".$lf;

echo "<th>Telefoon</th>".$lf;

 

while($row = mysql_fetch_array($result))

  {

  echo "<tr>".$lf;

  echo "<td>" . $row['orgNaam'] . "</td>".$lf;

  echo "<td>".'<a href="'. $row['orgURL'].'">'. $row['orgURL']."</a>" . "</td>".$lf;

  echo "<td>" . $row['orgPlaats'] . "</td>".$lf; 

  echo "<td>" . $row['orgSoort'] . "</td>".$lf;

  echo "<td>" . $row['orgTelefoon'] . "</td>".$lf;

  echo '<td> <a href="show_organisatie.php?orgId='.$row['orgId']. '">details' ."</a></td>".$lf;

  echo "</tr>".$lf;

  }

echo "</table>".$lf;

 

mysql_close($con);

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.