Worqy Posted March 19, 2010 Share Posted March 19, 2010 Hi. I have a script that adds a value to a MySQL value every second. Now I made another script that shows this value to the user. The problem is that the value in MySQL can be 200,945646 , and I just want to show the 200 . Anyone that knows how do I get this? Btw: The number is in a array Link to comment https://forums.phpfreaks.com/topic/195857-number-problem/ Share on other sites More sharing options...
TeddyKiller Posted March 19, 2010 Share Posted March 19, 2010 if the number is 12312 , 12131412 Meaning with a comma in the middle, you can do it so its 2 seperate collums. collum1 = number1, collum2 = number2 That way you can just call number 1 Link to comment https://forums.phpfreaks.com/topic/195857-number-problem/#findComment-1028779 Share on other sites More sharing options...
Worqy Posted March 19, 2010 Author Share Posted March 19, 2010 and how do I make a collum? Link to comment https://forums.phpfreaks.com/topic/195857-number-problem/#findComment-1028785 Share on other sites More sharing options...
TeddyKiller Posted March 19, 2010 Share Posted March 19, 2010 Ah, is this not to do with a database? You might be better off posting in the mysql section. Link to comment https://forums.phpfreaks.com/topic/195857-number-problem/#findComment-1028788 Share on other sites More sharing options...
teamatomic Posted March 19, 2010 Share Posted March 19, 2010 $x='200,945646'; $num=explode(",",$x); echo $num[0]; HTH Teamatomic Link to comment https://forums.phpfreaks.com/topic/195857-number-problem/#findComment-1028840 Share on other sites More sharing options...
Worqy Posted March 20, 2010 Author Share Posted March 20, 2010 $x='200,945646'; $num=explode(",",$x); echo $num[0]; HTH Teamatomic Thank you, works great. Now I have a question that I need a answer on, because some people say its not possible and some people say I can do it. I'm retrieving some data from MySQL. I have made a script that adds a value to MySQL every second (refresh with META). Now I retrieve the info to main.php, but I need to use META to refresh the page so I can see the new value, that the other script adds. It looks a bit weird when the page updates every second (main.php). Is there some other way? Link to comment https://forums.phpfreaks.com/topic/195857-number-problem/#findComment-1029042 Share on other sites More sharing options...
TeddyKiller Posted March 20, 2010 Share Posted March 20, 2010 You can have a Div, and use javascript to reload the div every second. Link to comment https://forums.phpfreaks.com/topic/195857-number-problem/#findComment-1029088 Share on other sites More sharing options...
Ruzzas Posted March 20, 2010 Share Posted March 20, 2010 use jquery for this. I believe you are lucky since i was working on this earlier on about two weeks ago. I will give you my code to make it "refresh" The proper term would be reload. <script src="http://code.jquery.com/jquery-latest.js"></script> <script type="text/javascript"> // When page has completed loading. Then LOAD the part of the page you need to be loaded $(document).ready(function() { // Once document has loaded the fadeOut content (If any) and then load the php code. Fade it in slowly. $("#divname").fadeOut('slow').load('loadthis.php').fadeIn('slow'); var refreshId = setInterval(function() { // After the amount of seconds below this code will keep loading over and over. $("#divname").fadeOut('slow').load('loadthis.php').fadeIn('slow'); }, 30000); }); Link to comment https://forums.phpfreaks.com/topic/195857-number-problem/#findComment-1029094 Share on other sites More sharing options...
TeddyKiller Posted March 20, 2010 Share Posted March 20, 2010 <script src="http://code.jquery.com/jquery-latest.js"></script> <script type="text/javascript"> // When page has completed loading. Then LOAD the part of the page you need to be loaded $(document).ready(function() { // Once document has loaded the fadeOut content (If any) and then load the php code. Fade it in slowly. $("#divname").fadeOut('slow').load('loadthis.php').fadeIn('slow'); var refreshId = setInterval(function() { // After the amount of seconds below this code will keep loading over and over. $("#divname").fadeOut('slow').load('loadthis.php').fadeIn('slow'); }, 30000); }); $("#divname") = You replace "divname" with your div id. As said above, if you have a piece of code which displays information every 1 second, stick it in a div, and use the JQuery (Thats if you wanted to) 30000 = 30 seconds. 1000 = 1 second. So just adjust that to when you want to reload the div. (eg: each second) Link to comment https://forums.phpfreaks.com/topic/195857-number-problem/#findComment-1029143 Share on other sites More sharing options...
Ruzzas Posted March 20, 2010 Share Posted March 20, 2010 change loadthis.php to what file you want it to load too. Link to comment https://forums.phpfreaks.com/topic/195857-number-problem/#findComment-1029148 Share on other sites More sharing options...
Ruzzas Posted March 20, 2010 Share Posted March 20, 2010 you can change loadthis.php to something like: includes.php #divcontainer which will load that file and take the contents of #(div) you have selected Link to comment https://forums.phpfreaks.com/topic/195857-number-problem/#findComment-1029155 Share on other sites More sharing options...
Worqy Posted March 20, 2010 Author Share Posted March 20, 2010 you can change loadthis.php to something like: includes.php #divcontainer which will load that file and take the contents of #(div) you have selected Thank you for your reply. I didn't get it to work, maby I did something wrong? auto-update.php (Should I set this script in main.php?) <script src="http://code.jquery.com/jquery-latest.js"></script> <script type="text/javascript"> // When page has completed loading. Then LOAD the part of the page you need to be loaded $(document).ready(function() { // Once document has loaded the fadeOut content (If any) and then load the php code. Fade it in slowly. $("#ResTable").fadeOut('slow').load('main.php').fadeIn('slow'); var refreshId = setInterval(function() { // After the amount of seconds below this code will keep loading over and over. $("#Restable").fadeOut('slow').load('main.php').fadeIn('slow'); }, 1000); }); main.php (Only a part of the code) ?> <html> <div id="ResTable"> </html> <?php //Gold $numGold= $info['gold']; $gold=explode(".",$numGold); echo $gold[0]; echo " "; //Three $numThree= $info['three']; $three=explode(".",$numThree); echo $three[0]; echo " "; //Clay $numClay= $info['clay']; $clay=explode(".",$numClay); echo $clay[0]; echo " "; //Iron $numIron= $info['iron']; $iron=explode(".",$numIron); echo $iron[0]; echo " "; //Wheat $numWheat= $info['wheat']; $wheat=explode(".",$numWheat); echo $wheat[0]; echo " "; /** echo ' Three: '; echo $info['three']; echo ' Clay: '; echo $info['clay']; echo ' Iron: '; echo $info['iron']; echo ' Wheat: '; echo $info['wheat']; **/ ?> <html> </div> </html> I started up the script tha adds the value to MySQL, and the new script. But the only thing that happends is that I see the old values in main.php. Something wrong? Link to comment https://forums.phpfreaks.com/topic/195857-number-problem/#findComment-1029180 Share on other sites More sharing options...
TeddyKiller Posted March 20, 2010 Share Posted March 20, 2010 Yes, it should go between the <head></head> tags on main.php You can also use <html> tags and have PHP between them too. Instead of using them twice or more. Put the PHP code that needs to be refreshed into another file. eg: myfile.php Then in your jquery script, replace "main.php" with myfile.php Also, in the jquery script, after the line "});" (lastl ine) You'll need to put in "</script>" It wasn't in the origional by mistake. Link to comment https://forums.phpfreaks.com/topic/195857-number-problem/#findComment-1029185 Share on other sites More sharing options...
Worqy Posted March 20, 2010 Author Share Posted March 20, 2010 Ok, I'll do that, but why this: "Put the PHP code that needs to be refreshed into another file. eg: myfile.php" ?? Because it is this part that needs to be updated: main.php //Gold $numGold= $info['gold']; $gold=explode(".",$numGold); echo $gold[0]; echo " "; //Three $numThree= $info['three']; $three=explode(".",$numThree); echo $three[0]; echo " "; //Clay $numClay= $info['clay']; $clay=explode(".",$numClay); echo $clay[0]; echo " "; //Iron $numIron= $info['iron']; $iron=explode(".",$numIron); echo $iron[0]; echo " "; //Wheat $numWheat= $info['wheat']; $wheat=explode(".",$numWheat); echo $wheat[0]; echo " "; Link to comment https://forums.phpfreaks.com/topic/195857-number-problem/#findComment-1029203 Share on other sites More sharing options...
Worqy Posted March 20, 2010 Author Share Posted March 20, 2010 Now, I did as you said: main.php <html> <head> <title>Access denied!</title> <script src="http://code.jquery.com/jquery-latest.js"></script> <script type="text/javascript"> // When page has completed loading. Then LOAD the part of the page you need to be loaded $(document).ready(function() { // Once document has loaded the fadeOut content (If any) and then load the php code. Fade it in slowly. $("#ResTable").fadeOut('slow').load('test.php').fadeIn('slow'); var refreshId = setInterval(function() { // After the amount of seconds below this code will keep loading over and over. $("#Restable").fadeOut('slow').load('test.php').fadeIn('slow'); }, 1000); }); </script> </head> and test.php <html> <div id="ResTable"> <?php //Gold $numGold= $info['gold']; $gold=explode(".",$numGold); echo $gold[0]; echo " "; //Three $numThree= $info['three']; $three=explode(".",$numThree); echo $three[0]; echo " "; //Clay $numClay= $info['clay']; $clay=explode(".",$numClay); echo $clay[0]; echo " "; //Iron $numIron= $info['iron']; $iron=explode(".",$numIron); echo $iron[0]; echo " "; //Wheat $numWheat= $info['wheat']; $wheat=explode(".",$numWheat); echo $wheat[0]; echo " "; ?> </div> </html> But still it does not work Link to comment https://forums.phpfreaks.com/topic/195857-number-problem/#findComment-1029258 Share on other sites More sharing options...
TeddyKiller Posted March 21, 2010 Share Posted March 21, 2010 Keep everything between the php tags in test.php Move the <div id="ResTable"> and the close div back into main.php. So main.php should look like.. <html> <head> <title>Access denied!</title> <script src="http://code.jquery.com/jquery-latest.js"></script> <script type="text/javascript"> // When page has completed loading. Then LOAD the part of the page you need to be loaded $(document).ready(function() { // Once document has loaded the fadeOut content (If any) and then load the php code. Fade it in slowly. $("#ResTable").fadeOut('slow').load('test.php').fadeIn('slow'); var refreshId = setInterval(function() { // After the amount of seconds below this code will keep loading over and over. $("#ResTable").fadeOut('slow').load('test.php').fadeIn('slow'); }, 1000); }); </script> </head> <body> <div id="ResTable"> </div> </body> </html> And all test.php has is the everything between the php tags (WITH THE PHP TAGS) no other tags eg: html etc Link to comment https://forums.phpfreaks.com/topic/195857-number-problem/#findComment-1029365 Share on other sites More sharing options...
Worqy Posted March 21, 2010 Author Share Posted March 21, 2010 Thank you, now it works. But when I putted in this code in test.php <?php //Include include "connect.config.php"; // Connect to server and select database mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select Database"); // Collect data from MySQL, table resources $data = mysql_query("SELECT * FROM resources") or die(mysql_error()); while($info = mysql_fetch_array($data)) //Gold $numGold= $info['gold']; $gold=explode(".",$numGold); echo " Gold: "; echo $gold[0]; //Three $numThree= $info['three']; $three=explode(".",$numThree); echo " Three: "; echo $three[0]; //Clay $numClay= $info['clay']; $clay=explode(".",$numClay); echo " Clay: "; echo $clay[0]; //Iron $numIron= $info['iron']; $iron=explode(".",$numIron); echo " Iron: "; echo $iron[0]; //Wheat $numWheat= $info['wheat']; $wheat=explode(".",$numWheat); echo " Wheat: "; echo $wheat[0]; ?> It only shows: Gold: 1500 Three: Clay: Iron: Wheat: If I runt the same code in main.php it get this answer: Gold:1500 Three:5000 Clay:1750 Iron:3248 Wheat:2250 Strange? Link to comment https://forums.phpfreaks.com/topic/195857-number-problem/#findComment-1029461 Share on other sites More sharing options...
Worqy Posted March 22, 2010 Author Share Posted March 22, 2010 Anyone with a idea why this wount work in test.php , but in main.php ? Link to comment https://forums.phpfreaks.com/topic/195857-number-problem/#findComment-1029852 Share on other sites More sharing options...
TeddyKiller Posted March 22, 2010 Share Posted March 22, 2010 I don't know sorry. Although if it works in main.php .. then thats alright.. isn't it? Link to comment https://forums.phpfreaks.com/topic/195857-number-problem/#findComment-1030046 Share on other sites More sharing options...
Worqy Posted March 22, 2010 Author Share Posted March 22, 2010 I don't know sorry. Although if it works in main.php .. then thats alright.. isn't it? hmm no? Because it is the content in test.php that shall be refreshed and shown on the page. ANd while looking today, I saw that your script isnt even refreshing, or it isnt showing the new value Link to comment https://forums.phpfreaks.com/topic/195857-number-problem/#findComment-1030107 Share on other sites More sharing options...
TeddyKiller Posted March 22, 2010 Share Posted March 22, 2010 I'm not sure about it not refreshing. However.. replace your while with this. while($info = mysql_fetch_array($data)) { //Gold $numGold= $info['gold']; $gold=explode(".",$numGold); echo " Gold: "; echo $gold[0]; //Three $numThree= $info['three']; $three=explode(".",$numThree); echo " Three: "; echo $three[0]; //Clay $numClay= $info['clay']; $clay=explode(".",$numClay); echo " Clay: "; echo $clay[0]; //Iron $numIron= $info['iron']; $iron=explode(".",$numIron); echo " Iron: "; echo $iron[0]; //Wheat $numWheat= $info['wheat']; $wheat=explode(".",$numWheat); echo " Wheat: "; echo $wheat[0]; } You didn't have brackets in, and basically the while function only recognised that it only had to do "gold" If that wasn't the problem, I still prefer to use brackets. Link to comment https://forums.phpfreaks.com/topic/195857-number-problem/#findComment-1030112 Share on other sites More sharing options...
Worqy Posted March 22, 2010 Author Share Posted March 22, 2010 You mena like this? $numGold= $info('gold'); ? But now when I looked more closly, your script does not refresh the values. If you want, you can come and look on it by TeamViewer //Kevin Link to comment https://forums.phpfreaks.com/topic/195857-number-problem/#findComment-1030122 Share on other sites More sharing options...
TeddyKiller Posted March 22, 2010 Share Posted March 22, 2010 Nooo. The while function. You didn't have { } I put them in the code I supplied. Just copy and paste it Link to comment https://forums.phpfreaks.com/topic/195857-number-problem/#findComment-1030126 Share on other sites More sharing options...
Worqy Posted March 22, 2010 Author Share Posted March 22, 2010 Nooo. The while function. You didn't have { } I put them in the code I supplied. Just copy and paste it I'll fix that echo array problem later, I just need your script to work: main.php <script src="http://code.jquery.com/jquery-latest.js"></script> <script type="text/javascript"> // When page has completed loading. Then LOAD the part of the page you need to be loaded $(document).ready(function() { // Once document has loaded the fadeOut content (If any) and then load the php code. Fade it in slowly. $("#ResTable").fadeOut('slow').load('test.php').fadeIn('slow'); var refreshId = setInterval(function() { // After the amount of seconds below this code will keep loading over and over. $("#Restable").fadeOut('slow').load('test.php').fadeIn('slow'); }, 1000); }); </script> test.php: <?php //Include include "overall.config.php"; // Connect to server and select database mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select Database"); // Collect data from MySQL, table resources $data = mysql_query("SELECT * FROM resources") or die(mysql_error()); while($info = mysql_fetch_array($data)) { //Gold $numGold= $info['gold']; $gold=explode(".",$numGold); echo " Gold: "; echo $gold[0]; //Three $numThree= $info['three']; $three=explode(".",$numThree); echo " Three: "; echo $three[0]; //Clay $numClay= $info['clay']; $clay=explode(".",$numClay); echo " Clay: "; echo $clay[0]; //Iron $numIron= $info['iron']; $iron=explode(".",$numIron); echo " Iron: "; echo $iron[0]; //Wheat $numWheat= $info['wheat']; $wheat=explode(".",$numWheat); echo " Wheat: "; echo $wheat[0]; } ?> Your function is not refreshing the main.php page (or the #ResTable part to be exact) Link to comment https://forums.phpfreaks.com/topic/195857-number-problem/#findComment-1030137 Share on other sites More sharing options...
TeddyKiller Posted March 22, 2010 Share Posted March 22, 2010 Whats the page link? Link to comment https://forums.phpfreaks.com/topic/195857-number-problem/#findComment-1030146 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.