canty Posted March 30, 2011 Share Posted March 30, 2011 First off I know this will be a problem with my code but I honestly have looked at it for too long. If anyone can shed a bit of simple light on it that would be great. $count should return about 8 or 9 or so but just returns 1 - I can only print out the number 1 if I do a direct echo of the mysql_num_rows() instead of putting it into the $count variable. Its really confusing, the database is all set up correctly as earlier on in the page I get all the information from the database and print out a table with it. There is something wrong here! Problem only occurs when $count = mysql_num_rows($result1); is written. //Following user presses button with name applyChanges. if(isset($_POST['applyChanges'])) { $result1 = mysql_query("SELECT * FROM music") or die ("Could not get result1"); $count = mysql_num_rows($result1) or die ("Could not count rows"); //Changed this to an echo without $count and prints a 1. - Should be greater than 8 echo "$count"; for($i=0; $i<$count; $i++) { $query2 = "UPDATE music SET name='$name[$i]' WHERE path='$path[$i]'"; $result2 = mysql_query($query2); } } Thanks, Matt Quote Link to comment https://forums.phpfreaks.com/topic/232222-mysql-num-rows-being-unresponsive/ Share on other sites More sharing options...
btherl Posted March 30, 2011 Share Posted March 30, 2011 What exactly is the problem you are having? What do you expect to see and what are you seeing? Quote Link to comment https://forums.phpfreaks.com/topic/232222-mysql-num-rows-being-unresponsive/#findComment-1194625 Share on other sites More sharing options...
betterphp Posted March 30, 2011 Share Posted March 30, 2011 MySQL num rows being unresponsive unresponsive suggests the page is too slow ? which could be because of the loped query, which is a bit of a no no in terms of efficiency. Quote Link to comment https://forums.phpfreaks.com/topic/232222-mysql-num-rows-being-unresponsive/#findComment-1194630 Share on other sites More sharing options...
canty Posted March 30, 2011 Author Share Posted March 30, 2011 I've edited the original for a bit more clarity, should this be an issue when the page is only about 30 lines or so. The code is efficient I hope. Besides I'm doing another mysql_query specifically for this bit. Would putting it at the top of the code help? Quote Link to comment https://forums.phpfreaks.com/topic/232222-mysql-num-rows-being-unresponsive/#findComment-1194635 Share on other sites More sharing options...
btherl Posted March 30, 2011 Share Posted March 30, 2011 Can you please copy this code to the top of your script, directly after the database connection is made. Then post the output. $result1 = mysql_query("SELECT * FROM music") or die ("Could not get result1"); print "<pre>"; var_dump($result1); $count = mysql_num_rows($result1) or die ("Could not count rows"); //Changed this to an echo without $count and prints a 1. - Should be greater than 8 echo "Count: $count\n"; exit; Quote Link to comment https://forums.phpfreaks.com/topic/232222-mysql-num-rows-being-unresponsive/#findComment-1194637 Share on other sites More sharing options...
betterphp Posted March 30, 2011 Share Posted March 30, 2011 If you are doing the same query above, can you not use the result of that ? Quote Link to comment https://forums.phpfreaks.com/topic/232222-mysql-num-rows-being-unresponsive/#findComment-1194638 Share on other sites More sharing options...
canty Posted March 30, 2011 Author Share Posted March 30, 2011 Can you please copy this code to the top of your script, directly after the database connection is made. Then post the output. $result1 = mysql_query("SELECT * FROM music") or die ("Could not get result1"); print "<pre>"; var_dump($result1); $count = mysql_num_rows($result1) or die ("Could not count rows"); //Changed this to an echo without $count and prints a 1. - Should be greater than 8 echo "Count: $count\n"; exit; Result: resource(3) of type (mysql result) Count: 9 This looks promising but its getting late... The count is now right! Quote Link to comment https://forums.phpfreaks.com/topic/232222-mysql-num-rows-being-unresponsive/#findComment-1194647 Share on other sites More sharing options...
btherl Posted March 30, 2011 Share Posted March 30, 2011 Ok, so we've confirmed that your query and count code is correct. My gut feeling is that you are actually seeing output from different code, not the code you are editing. There are 2 approaches I use in this kind of situation, and you can use either or both: 1. Keep adding print/var_dump statements until it becomes obvious where things are going wrong. A good idea is to include some text to identify what part of the code is producing the output, so you don't spend hours debugging the wrong code (yes I've made that mistake many times!) 2. If your script is not terminating, add "exit" at various points so you can confirm how far it gets before it hangs. Then you can narrow down the problem area. Quote Link to comment https://forums.phpfreaks.com/topic/232222-mysql-num-rows-being-unresponsive/#findComment-1194667 Share on other sites More sharing options...
canty Posted March 30, 2011 Author Share Posted March 30, 2011 Thanks will look in morning and let you know how I get on. Quote Link to comment https://forums.phpfreaks.com/topic/232222-mysql-num-rows-being-unresponsive/#findComment-1194713 Share on other sites More sharing options...
canty Posted March 31, 2011 Author Share Posted March 31, 2011 Hi guys, thanks all for your help the solution was to put the count at the top straight after the query. I've got something else though, I have been building a site for a musician friend and they have hosting and domain with 34sp.com .... I've been having problems all the way through mostly due to permissions which I've never had with netoxide.co.uk. Latest problem is this <?php $newPlaylist = "<?xml version='1.0' encoding='UTF-8'?><xml>"; echo $newPlaylist; ?> I have this running its own file called "string.php" and it does not run - $newPlaylist ="xml"; does work however. Never had a problem like this before, and I certainly remember it working when I first wrote it. What is going on? Quote Link to comment https://forums.phpfreaks.com/topic/232222-mysql-num-rows-being-unresponsive/#findComment-1195058 Share on other sites More sharing options...
Pikachu2000 Posted March 31, 2011 Share Posted March 31, 2011 Make sure short open tags are turned off in the php.ini file. Quote Link to comment https://forums.phpfreaks.com/topic/232222-mysql-num-rows-being-unresponsive/#findComment-1195069 Share on other sites More sharing options...
canty Posted March 31, 2011 Author Share Posted March 31, 2011 Make sure short open tags are turned off in the php.ini file. short_open_tag = 0 like this? Still not working. Quote Link to comment https://forums.phpfreaks.com/topic/232222-mysql-num-rows-being-unresponsive/#findComment-1195074 Share on other sites More sharing options...
btherl Posted March 31, 2011 Share Posted March 31, 2011 When you say "does not run", what do you mean? Do you see a blank page? Quote Link to comment https://forums.phpfreaks.com/topic/232222-mysql-num-rows-being-unresponsive/#findComment-1195238 Share on other sites More sharing options...
canty Posted March 31, 2011 Author Share Posted March 31, 2011 Yeah its just showed a blank page. I meant to write back to say that I have somewhat solved the problem... yet at the same time I have not! Basically I have a system where my client can upload songs and rename them etc, this is all stored in an SQL database. When a user comes to listen to the songs on the website itself the player requires an XML file for the playlist which needed to be auto updated each time my client made changes. Option 1 : Each user makes a new playlist.xml file when they visit the page - This caused problems with strings containing <? Option 2 : Rewrite the XML file each time client makes a change - This now works. But the code is actually no different to that in Option 1. My problems are solved, thanks very much for help. If anyone would like more info on a similar problem please don't hesitate to ask, I hope to help. Quote Link to comment https://forums.phpfreaks.com/topic/232222-mysql-num-rows-being-unresponsive/#findComment-1195257 Share on other sites More sharing options...
btherl Posted March 31, 2011 Share Posted March 31, 2011 Hmm, I tried your xml printing code and it worked for me, php version 5.2.0. Did you try "view source" in your browser after accessing that script? I've noticed when working with xml that some browsers will parse the xml and display it as a blank page if they think there's nothing to show. Quote Link to comment https://forums.phpfreaks.com/topic/232222-mysql-num-rows-being-unresponsive/#findComment-1195263 Share on other sites More sharing options...
betterphp Posted April 8, 2011 Share Posted April 8, 2011 Option 1 : Each user makes a new playlist.xml file when they visit the page - This caused problems with strings containing <? <? is the short version of <?php you may need to output those directly with php to avoid this <?php echo '<?'; ?> bit untidy. Quote Link to comment https://forums.phpfreaks.com/topic/232222-mysql-num-rows-being-unresponsive/#findComment-1198749 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.