Jump to content

AltarofScience

Members
  • Posts

    91
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

AltarofScience's Achievements

Member

Member (2/5)

0

Reputation

  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.
×
×
  • 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.