hellonoko Posted September 30, 2007 Share Posted September 30, 2007 Can anyone advise as to why my below nested query code is not working? Error is : Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\www\accordion\accordion\phpaccordion.php on line 340 Thanks! <?php $query = "SELECT * FROM items"; $result = mysql_query($query); $rows = mysql_num_rows($result); for ($i=0; $i <$rows; $i++) { $row = mysql_fetch_array($result); //echos each item from DB echo "<h1 class='accordion_toggle'>" .$row[title]."</h1>"; echo "<div style='height: auto; display: none;' class='accordion_content'>"; echo "<h2>".$row[title]."</h2>"; echo "<form id=add_note' name='add_note' method='get' action='phpaccordion.php'>"; echo "<input name='action' type='hidden' value='add_note'>"; echo "<input name='note_content' type='text' value='new note'>"; echo "<input name='child_of' type='hidden' value=".$row[id].">"; echo "<input type='image' src='images/plus.gif' alt='New Note'>"; echo "</form>"; echo "<p>".$row[content]."</p>"; $query2 = "SELECT * FROM main_item WHERE childof = '$row[id]'"; $result2 = mysql_query($query2); $rows2 = mysql_num_rows($result2); for ($i2=0; $i2 <$rows2; $i2++) { $row2 = mysql_fetch_array($result2); echo "+".$row2[content].""; } echo "<form id=".$row[id]." name='delete' method='get' action='phpaccordion.php'>"; echo "<input name='item_to_delete' type='hidden' value=".$row[id]." />"; echo "<input type='hidden' name='action' value='delete'>"; echo "<p><input type='image' SRC='images/x.gif' ALT='Delete'></p>"; //echo "<input type='submit' value='Delete'>"; echo "<p></P>"; echo "</form>"; echo "</div>"; } ?> Link to comment https://forums.phpfreaks.com/topic/71213-nested-queries-not-working/ Share on other sites More sharing options...
pocobueno1388 Posted September 30, 2007 Share Posted September 30, 2007 There is something wrong with one of your queries. Put a die statement at the end of all of them. Example $result = mysql_query($query)or die(mysql_error()); This will give you an error telling you what went wrong. Link to comment https://forums.phpfreaks.com/topic/71213-nested-queries-not-working/#findComment-358191 Share on other sites More sharing options...
sasa Posted September 30, 2007 Share Posted September 30, 2007 try $query2 = "SELECT * FROM main_item WHERE childof = '" . $row[id] . "'"; Link to comment https://forums.phpfreaks.com/topic/71213-nested-queries-not-working/#findComment-358319 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.