rinuxl Posted January 13, 2009 Share Posted January 13, 2009 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.... Link to comment https://forums.phpfreaks.com/topic/140733-solved-query-works-on-mysql-prompt-but-not-in-php/ Share on other sites More sharing options...
trq Posted January 13, 2009 Share Posted January 13, 2009 Can we see your actual code? You don't appear to do anything with $row in the example above. Link to comment https://forums.phpfreaks.com/topic/140733-solved-query-works-on-mysql-prompt-but-not-in-php/#findComment-736611 Share on other sites More sharing options...
rinuxl Posted January 14, 2009 Author Share Posted January 14, 2009 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); Link to comment https://forums.phpfreaks.com/topic/140733-solved-query-works-on-mysql-prompt-but-not-in-php/#findComment-737134 Share on other sites More sharing options...
rinuxl Posted January 14, 2009 Author Share Posted January 14, 2009 OOPS, I made a terrible mistake. I deleted a block of text but $row = mysql_fetch_array($result) was not selected. Sorry to have bordered. (and it took me hours to see it ) Link to comment https://forums.phpfreaks.com/topic/140733-solved-query-works-on-mysql-prompt-but-not-in-php/#findComment-737141 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.