Jump to content

AltarofScience

Members
  • Posts

    91
  • Joined

  • Last visited

    Never

Everything posted by AltarofScience

  1. Yeah I don't really understand or use explode and implode. In any case I can now handle 40x as many inserts or updates of rows as I could before I did the multi row queries. 50 rows to 2000. Thanks guys.
  2. sweet thanks. saves me a lot of trouble so I don't have to create a whole new while loop format.
  3. <html> <head> </head> <body> <?php include('filename.php'); ?> //example code for a table, table will align under the menu. you may have to change the CSS for the page because includes mess up the flow <table border=1> <tr> <td></td> </tr> </table> </body> </html>
  4. Okay, now I want to be able to do the same thing with UPDATE. It appears I have 3 options. I can use REPLACE I can use ON DUPLICATE KEY UPDATE I can use a Temporary Table Which of these methods is faster to update multiple rows in a table?
  5. Nvm. I totally figured it out and no need for arrays. <?php $querytestquery='"INSERT INTO test(qval1, qval2) VALUES'; $querymax=10; $querystart=0; while ($querystart<$querymax) { $qval1=1*$querystart; $qval2=2*$querystart; $queryadd="($qval1, $qval2)"; if ($querystart==$querymax-1) { $querytestquery=$querytestquery.$queryadd; } else { $querytestquery=$querytestquery.$queryadd.','; } $querystart++; } $query=$querytestquery.'"'; echo $query; ?> Result: "INSERT INTO test(qval1, qval2) VALUES(0, 0),(1, 2),(2, 4),(3, 6),(4, ,(5, 10),(6, 12),(7, 14),(8, 16),(9, 18)" And if I change $querymax it still works perfectly.
  6. that will work even though every time I run the script I have a different number of values?
  7. I need to insert a large variable number of records into a mysql table. I can do this using a while loop and insert queries in the loop but its slow and ive been given to understand its a bad idea. I have heard that I can insert multiple rows with one query, but how to construct the query? This code can perfectly and reliably display a statement with echo: <?php $querytestquery='"INSERT INTO test(qval1, qval2) VALUES'; echo $querytestquery; $querymax=10; $querystart=0; while ($querystart<$querymax) { $qval1=1*$querystart; $qval2=2*$querystart; $queryadd="($qval1, $qval2)"; echo $queryadd; if ($querystart<$querymax-1) { echo ','; } $querystart++; } echo '"'; ?> "INSERT INTO test(qval1, qval2) VALUES(0, 0),(1, 2),(2, 4),(3, 6),(4, ,(5, 10),(6, 12),(7, 14),(8, 16),(9, 18)" But I don't understand how to set a variable equal to the displayed query so that I can have php construct the statement based on the values and the number of records I want to update or insert.
  8. okay, that is probably enough for me to figure out what i need to do. thanks.
  9. I am making a universe, and I need a map display, so players can navigate it. Technically, you can cut the size down, by displaying only portions of the map, so I think a 2d array might work. You could have the display set to like, show a 10kby10k or 1k by 1k sector of the map. or something. Say you are at a star system and want to see nearby star systems. you would set the display so the coords of that system are at the center, and display: currentx-1000 to currentx+1000 on the x axis and currenty-1000 to currentx+1000 on the y axis. that would only be 4million possible points. and only like, 10 or 20 star systems would actually exist there. i think some people use vrml maps for this kind of thing? when i was googling i got some vrml results. i mean, technically each ordered pair would also have a z coordinate, but i might not use z if it make its too complicated for me to code.
  10. How do I create a coordinate map in php? I created ordered pairs and I want to plot them on a grid. Grid is about 200000x200000.
  11. I made this code: <?php $rad=100000; $h=5000; $ugal=3; $gal=0; while($gal<$ugal){ $xco=rand(-$rad, $rad); $yco=rand(-$rad, $rad); $zco=rand(-$h, $h); echo '|'; echo $xco; echo ','; echo $yco; echo ','; echo $zco; $v=rand(10, 20); $usys=$v; $sys=0; $rads=10000; $hs=500; while($sys<$usys){ $xcos=rand(-$rads+$xco, $rad+$xco); $ycos=rand(-$rad+$yco, $rad+$yco); $zcos=rand(-$h+$zco, $h+$zco); echo '/'; echo $xcos; echo ','; echo $ycos; echo ','; echo $zcos; echo '/'; $sys++; } echo '|'; $gal++; } Which out puts these results, or many others but format: |40168,58762,-2001/63746,144027,-5153//102639,-17356,-1650//136941,83854,-5998//123011,145799,-4154//76686,137884,-2616//114859,11075,-2067//90787,39466,-1265//131424,34430,-1708//69079,80168,2502//36170,38930,-4500//54599,99982,-5237/||-18611,-27016,-2041/8303,57253,-6618//-8854,44290,-3771//37664,23411,615//12354,-124276,-4452//72974,-43571,1285//64229,32098,-3423//-6861,-46496,-3921//-858,33672,-1419//23574,-25109,346//68339,47876,-6696//61962,-85008,2519//66619,-49085,1084//-7405,71416,-1395//76812,-54102,-1258//-4704,-69404,2914//-23123,-100604,870//16680,-61057,-5105//51008,-10595,2931//2851,-115714,-1975//-25895,60559,-3230/||-88149,52253,912/-29180,148413,4188//-7973,146844,-166//-12551,19757,5617//11357,77370,5572//-93156,103783,3482//-47864,-30258,5419//-78246,86163,5390//-46784,97466,456//-44067,85040,4267//-37549,37293,178/| That format is perfect. The problem as I said before is that it outputs only dot cluster galaxies. I mean, my game could work fine on all dot cluster galaxies. But I think players would like it better if it was obvious I went to some effort to create some other kinds of galaxies, too. I have this vague idea that I could use an equation to create a shape, and then accept only coordinate groups that fit in that shape, but I really have no idea how to do that.
  12. please, this is really important for my game, how can i create a map with coordinate system to allow ships to "travel"? i figured out how to generate random coordinates, so i could create coordinates for the center of a galaxy and each star system in a galaxy, and probably make multiple galaxies, but those will all be random dot clusters. i would like to create spiral galaxies with multiple arms of varying sizes and such, and not just dot clusters.
  13. um, is one of your variables a string? like the stuff you are calling from the database, as opposed to a number? i am trying to think of the things that happen when i get a t_string error and it usually involves one of my variables not being a number. are you positive that is line 29? also why () around limit? also, are there 8 lines of text in the included file? otherwise i only count that line as like 21.
  14. I am making a space game. The game requires a map. The map needs to contain one or more galaxies. Each galaxy should have from 100 to 1000 star systems. Each star system needs to possess a random number of planets from 1-10. I suspect that I can use while loops to control the number of galaxies star systems and planets, but I need to know how to assign coordinates when making the universe.
  15. so turns out, all i had to do was set $prod=$prod+$count*$staff*$effic and then in the containing while loop create the update query. that way prod becomes the total value of all mines and then inserts into the table and then it is reset to 0 and then i can get the $prod value of the next suptype. i tested it out and its perfect.
  16. I created the code below and it outputs the following number output: 1111111773526604115551144611337112281111221111345678910112111110035200411005110061100711008110022110034567891011411111003520041100511006110071100811002211003456789101151111100352004110051100611007110081100221100345678910112311111003520041100511006110071100811002211003456789101134 Anyways if you look at the code, I need to be able to add the values on a single colony, idcol, with the same type and subtype, btid/stid, generated as the $prod variable. buildings with the same subtype generate the same resource, in this case, several iron mines and a single copper mine are present, but there are also 9 other types of resource buildings. How do I collect on the prods which go together? <?php $dbhost = 'localhost:3306'; $dbuser = 'lordofth_aos'; $dbpass = 'flarge'; $dbname = 'lordofth_aos'; $conn = mysql_connect($dbhost,$dbuser,$dbpass) or die ('Error connecting to mysql'); mysql_select_db($dbname); $query="SELECT id FROM users"; $result=mysql_query($query); $num=mysql_num_rows($result); $i=0; $idn=1; while($i<$num){ $queryii="SELECT idcol FROM colony WHERE id=$idn"; $resultii=mysql_query($queryii); $numt=mysql_num_rows($resultii); $id=mysql_result($result, $i); echo $id; $ii=0; $ibt=1; while($ii<$numt){ $querypty="SELECT btid FROM ptypes WHERE btid=$ibt"; $resultpty=mysql_query($querypty); $numpty=mysql_num_rows($resultpty); $idcol=mysql_result($resultii, $ii); echo $idcol; $bt=0; $btid=mysql_result($resultpty, $bt); echo $btid; $bte=1; while($bt<$numpty){ $querystid="SELECT stid FROM ptypes WHERE stid=$bte"; $resultstid=mysql_query($querystid); $numstid=mysql_num_rows($resultstid); $st=0; $stid=mysql_result($resultstid, $st); echo $stid; $ste=1; while($st<$numstid){ $bidum=0; $querybpid="SELECT bpid FROM blueprints WHERE btid=$btid AND stid=$stid"; $resultbpid=mysql_query($querybpid); $numbpid=mysql_num_rows($resultbpid); while($bidum<$numbpid){ $bidumb=0; $bidumbg=mysql_result($resultbpid, $bidum, 'bpid'); echo $bidumbg; $querybid="SELECT COUNT(bid) AS count, workers, efficiency FROM buildings INNER JOIN blueprints ON buildings.bpid=blueprints.bpid WHERE blueprints.btid=$btid AND blueprints.stid=$stid AND buildings.bpid=$bidumbg AND buildings.idcol=$idcol"; $resultbid=mysql_query($querybid); $staff=mysql_result($resultbid, $bidumb, 'workers'); $effic=mysql_result($resultbid, $bidumb, 'efficiency'); $count=mysql_result($resultbid, $bidumb, 'count'); echo $staff; echo $effic; echo $count; $prod=$staff*$effic*$count; echo $prod; $bidumb++; $bidum++; } $st++; $ste++; } $bt++; $bte++; } $ii++; } $i++; $idn++; } ?>
  17. why would i need luck if i'm doing what you guys told me to? if i'm doing it right luck isn't necessary.
  18. yeah, i got rid of the amount column. we will see how it goes.
  19. well since the game is not complete, and its based on a round format, i would need to clean the database out every time a round ends. Since i only have 4 user accounts, i already made all the changes except i had the extra column, so no trouble. thanks for help
  20. what i am going to do is get the sql file for my database and make a new database with it. then i will alter the current database and try to do it your way, and if i have no problems than i will not need to redo it with the other database.
  21. yeah i have no idea what you mean. if i destroy a certain number of a building, how would that code with having all rows? would it delete x number of rows where x is the number of buildings destroyed? cause if i saved a value, it would just say, call value, set value to $x, $x=$x-$d, update with $x.
  22. can you tell me what sort of problems i would have if i just had 1 row for each print and stored the number of buildings on a colony that are that kind in a column would cause? Would it slow down my SELECT queries or something? I guess I will probably just do as you suggest, but my mind is still trying to say no.
  23. i gather by your statement that i was correct about what you are suggesting in regards to have each individual building be a separate row? you mean it searches the first column for the correct index and then ignores the rest of any row with a different first index? and if its the same first index it checks the next column for the next index, and if its different than the request ignores the rest of the row? and that follows through each key? it still seems like it would take more server resources than just going through ~40 rows and then having an extra column with a number that is updated when new buildings are built.
  24. your code requires there to be 1 row for every building in the game. that is millions of rows? How can that possibly be faster than having 1 row for each building print, which stores the total number of buildings built with that print? maybe i just don't understand how computer code works, but my brain will never accept that scanning millions of rows to find all of them that correlate to a specific print is faster than one row with an extra column holding the total.
  25. how the hell can you count something that doesn't exist? i can count the number of rows in a column. thats what count does. are you saying you want me to have a row for every single building? and you want the database to store column input for that? instead of having 10 rows that are the same building, why can't i have 1 row, and then another column with a total value? do you understand that if each separate building on a colony was stored as a row I would have like 1 million rows? Is that what you guys keep suggesting?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.