BigX Posted March 28, 2008 Share Posted March 28, 2008 Hi, I have the next piece of code: <?php if(isset($_GET['categorie'])) { $categorie = $_GET['categorie']; $organisaties_categorie = mysql_query("SELECT * FROM organisaties WHERE Categorie=" . $categorie." ORDER BY Organisatie ASC"); echo "<table width='350' cellspacing='0' border='0'> <tr> <th width='20' style='color: #CB0042' bgcolor='#FFFFFF'><div class='style11'><b>Organisaties</b></div></th> </tr> <tr> <th width='20' style='color: #CB0042' bgcolor='#FFFFFF'><div class='style11'><b> </b></div></th> </tr>"; while($row = mysql_fetch_array($organisaties_categorie, MYSQL_ASSOC)) { echo "<tr>"; echo "<td style='color: #000099'><div align='left'><a href='organisatie.php?id={$row['id']}'>• " . $row['Organisatie'] . "</a></div></td>"; echo "</tr>"; $organisaties_subcategorie = mysql_query("SELECT * FROM organisaties WHERE subcategorie=" . $row['id']); while($row = mysql_fetch_array($organisaties_subcategorie, MYSQL_ASSOC)) { echo "<tr>"; echo "<td style='padding-left: 30px; font-size: 14px'><div align='left'><a class='rood' href='organisatie.php?id={$row['id']}'>" . $row['Organisatie'] . "</a></div></td>"; echo "</tr>"; } } echo "</table>"; ; } else { echo "<table width='555' border='0'> <tr> <td width='378' bgcolor='#FFFFFF'><img src=\"juridischloket.jpg\" alt=\"\" width=\"365\" height=\"320\"/></td> <td width='177' bgcolor='#FFFFFF'><table width=\"177\" border=\"0\" align=\"right\"> <tr> <td><div align=\"left\"><span class=\"style3\">Loketgegevens</span></div></td> </tr> <tr> <td><div align=\"left\"><span class=\"style2\">Juridisch Loket Amersfoort</span></div></td> </tr> <tr> <td><div align=\"left\"><span class=\"style2\">Telefoon: 0900-8020</span></div></td> </tr> <tr> <td><div align=\"left\"><span class=\"style2\">Fax: 033-4622361</span></div></td> </tr> <tr> <td> </td> </tr> <tr> <td><div align=\"left\"></div></td> </tr> <tr> <td><div align=\"left\"><strong>Bezoekadres</strong></div></td> </tr> <tr> <td><div align=\"left\"><span class=\"style2\">Van Asch van Wijckstraat 2-4</span></div></td> </tr> <tr> <td><div align=\"left\"><span class=\"style2\">3822 LP Amersfoort</span></div></td> </tr> <tr> <td> </td> </tr> <tr> <td><div align=\"left\"></div></td> </tr> <tr> <td bgcolor=\"#FFFFFF\"><div align=\"left\"><span class=\"style3\">Postadres</span></div></td> </tr> <tr> <td><div align=\"left\"><span class=\"style2\">Postbus 2081</span></div></td> </tr> <tr> <td><div align=\"left\"><span class=\"style2\">3800 CB Amersfoort</span></div></td> </tr> <tr> <td> </td> </tr> <tr> <td><div align=\"left\"></div></td> </tr> <tr> <td><div align=\"left\"><strong>Openingstijden</strong></div></td> </tr> <tr> <td><div align=\"left\"><span class=\"style2\">Ma t/m Vr : 09.00-17.00 uur</span></div></td> </tr> </table></td> </tr>"; echo "</table>"; } ?> I got this piece of code to work before and everything worked fine! I used wampserver to preview the site in localhost! Suddenly (after I tried to alter some other things on the site) the code did not work anymore! I still see the site in preview mode (localhost) but I always get this error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:############\sociale_kaart\index.php on line 165 Line 165 is the first while loop! I know that this error suggests that the query isn't valid but when I try for example: "SELECT * FROM organisaties WHERE Categorie=1 ORDER BY Organisatie ASC" in PHPmyAdmin I nicely get the results! Could there be something else wrong with the communication between the SQL database en the localhost (what??) or does anyone see a syntax error somewhere in the code especially on line 165 or on the lines with the rows?? help would be really appreciated!! Thanks in advance, Kind regards Link to comment https://forums.phpfreaks.com/topic/98326-problem-with-sql-results/ Share on other sites More sharing options...
BigX Posted March 28, 2008 Author Share Posted March 28, 2008 Anyone? Link to comment https://forums.phpfreaks.com/topic/98326-problem-with-sql-results/#findComment-503171 Share on other sites More sharing options...
discomatt Posted March 28, 2008 Share Posted March 28, 2008 There is an error in your query or there are no rows returned by it. Echo mysql_error() and your query and you may be able to figure out whats going on. Link to comment https://forums.phpfreaks.com/topic/98326-problem-with-sql-results/#findComment-503186 Share on other sites More sharing options...
BlueSkyIS Posted March 28, 2008 Share Posted March 28, 2008 $organisaties_categorie = mysql_query("SELECT * FROM organisaties WHERE Categorie=" . $categorie." ORDER BY Organisatie ASC") or die(mysql_error()); if nothing else, you should single-quote $categorie. Link to comment https://forums.phpfreaks.com/topic/98326-problem-with-sql-results/#findComment-503188 Share on other sites More sharing options...
discomatt Posted March 28, 2008 Share Posted March 28, 2008 If $catagorie is a string, then yes, single quotes are required. in the query. This is why most developers design queries like this <?php $q = 'SELECT `col` FROM `table` WHERE `thisCol` = \'' .$this. '\' AND `thatCol = \'' .$that. '\''; // Remove '//' from line below to debug // echo '<br>' .$q. '<br>'; $r = mysql_query($q); ?> Link to comment https://forums.phpfreaks.com/topic/98326-problem-with-sql-results/#findComment-503203 Share on other sites More sharing options...
BigX Posted March 28, 2008 Author Share Posted March 28, 2008 $organisaties_categorie = mysql_query("SELECT * FROM organisaties WHERE Categorie=" . $categorie." ORDER BY Organisatie ASC") or die(mysql_error()); if nothing else, you should single-quote $categorie. I added what you said and i got: No database selected On top of the site I put this: <?php require_once('Connections/socialekaart.php'); mysql_select_db($database_sociale_kaart, $sociale_kaart); ?> The database i use is called sociale_kaart (dutch) is this correct or not cuz i now get this error: Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in ######### on line 2 So strange that the site worked before and I now suddenly encounter these connection problems! Thanks in advance Link to comment https://forums.phpfreaks.com/topic/98326-problem-with-sql-results/#findComment-503222 Share on other sites More sharing options...
BlueSkyIS Posted March 28, 2008 Share Posted March 28, 2008 i'm not optimistic that this will work, because i don't believe you're connecting to the MySQL server at all, but: <?php require_once('Connections/socialekaart.php'); mysql_select_db('sociale_kaart'); ?> Link to comment https://forums.phpfreaks.com/topic/98326-problem-with-sql-results/#findComment-503252 Share on other sites More sharing options...
BigX Posted March 29, 2008 Author Share Posted March 29, 2008 i'm not optimistic that this will work, because i don't believe you're connecting to the MySQL server at all, but: <?php require_once('Connections/socialekaart.php'); mysql_select_db('sociale_kaart'); ?> You are not gonna believe it but it worked Thanks alot!! No I can finally go and finish this thing!! Thanks again Link to comment https://forums.phpfreaks.com/topic/98326-problem-with-sql-results/#findComment-503687 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.