Jump to content

Gekk0

Members
  • Posts

    13
  • Joined

  • Last visited

    Never

About Gekk0

  • Birthday 01/02/1988

Contact Methods

  • Website URL
    http://www.squarecirclestudio.com/

Profile Information

  • Gender
    Male
  • Location
    Amsterdam

Gekk0's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Array merge: <?php $array = array_merge($array1,$array2); ?>
  2. This sounds similar to a chess program i've been working on (well currently shelved due to other projects), but i think the basic principle is the same... Basically.... what you'd want is a like a chess board, but with only the king's movements this is it: http://sandbox.squarecirclestudio.com/chess/ I'm not sure if its really the most efficient way... i'm doing it, i wrote it after a drunken competition with a couple mates that we could design a chess playing computer ....yes we're a little geeky =P Basically what i do is - create a "board array" which has 64 elements, numbered from 1 (top left) to 64 (bottom right).. this denotes every square on the board - create an array of pieces, with elements like this $pieces[1]['type'] = 'r'; .... so this one means the piece located at square 1 (top left) is type Rook... - then i have a function with figures all of the possible movements that the piece say, located at square 1 can perfom, and in this function it checks whether there is another piece in the square its trying to move to and whether that piece is a friend or foe... its a foe we can take it, a friend we cant move there - i think whats relevant for you is this, when i'm figuring out the movements, what i'm doing is using a loop like this //y axis moves for($i = ($loc + ; $i < 65; $i = $i + { if(isset($pieces[$i]) && $pieces[$i]['colour'] != $pieces[$loc]['colour']) { $moves[$i] = 2; break; } if(isset($pieces[$i]) && $pieces[$i]['colour'] == $pieces[$loc]['colour']) { break; } $moves[$i] = 1; if(isset($lim)) { break; } } for($i = ($loc - ; $i > 0; $i = $i - { if(isset($pieces[$i]) && $pieces[$i]['colour'] != $pieces[$loc]['colour']) { $moves[$i] = 2; break; } if(isset($pieces[$i]) && $pieces[$i]['colour'] == $pieces[$loc]['colour']) { break; } $moves[$i] = 1; if(isset($lim)) { break; } } if($pieces[$loc]['type'] == 'r') { return $moves; } } so i'm taking the location number of the piece, and basically say, adding/subtracting 8 from it (this is for y axis movements), untill i "hit" either the end of the board or another piece, then i figure if its friend or foe, and then i stop. I'm not sure if this is helpful, or i've explained it very well... the program is about 440 lines long in the end... but there are probably more efficient ways... i did it kinda drunk soooo
  3. Ah! perfect, cheers for your help mate!
  4. I'm building up a menu like this: <div class="menu"> <a href="index.php" class="menuItemSelected">Home</a> <a href="index.php?page=makebooking" class="menuItem">Request A Booking</a> <a href="index.php?page=bookingReq" class="menuItem">Booking Requests</a> <a href="index.php?page=bookings" class="menuItem">Manage Bookings</a> <a href="index.php?page=calendar" class="menuItem">Calendar</a> <a href="index.php?page=vehicles" class="menuItem">Vehicles</a> <a href="index.php?page=users" class="menuItem">Users</a> <a href="index.php?page=settings" class="menuItem">Settings</a> <a href="index.php?action=logout" class="menuItem">Logout</a> </div>
  5. Is this right? .menuItem { padding-right:10px; padding-left:10px; padding-top:5px; padding-bottom:5px; background-color: #abd0e5; border-width: 1px; } .menuItem a:link { padding-right:10px; padding-left:10px; padding-top:5px; padding-bottom:5px; background-color: #abd0e5; border-width: 1px; } .menuItem a:hover { padding-right:10px; padding-left:10px; padding-top:5px; padding-bottom:5px; background-color: #9fc4d9; border-width: 1px; } So the menu item background color is supposed to change when on hover, but it isn't working, my css isn't really what it should be but umm.. yeah
  6. sorry i was talking crap, i see what your trying to do now ok i dunno if this is the problem, but i certainly think its an issue //show next button if (!($start>=$record_count-$per_page)) echo " <a href='index.php?start=$next'>Next</a>"; echo "<br><br><a href='profiles.php?addcomment=". $id ."' onclick='document.getElementById(\"commentarea\").style.visibility=\"visible\"; return false;'>Add a comment</a> <div id='commentarea' style='visibility: hidden;'> <form action='profiles.php' method='POST'><input type='hidden' name='hiddenid' value='". $id ."'><textarea name='comment' maxlength='300' cols='65' rows='15'></textarea><br><br><input type='submit' value='Add comment'> or <a href='#' onclick='document.getElementById(\"commentarea\").style.visibility=\"hidden\"; this.form.hiddenid.value=\"\";'>Discard comment</a></form> </div>"; i'm assuming that IF that statement it true, you want to do those two echo's so if thats the case you need to use {} like this //show next button if (!($start>=$record_count-$per_page)) { echo " <a href='index.php?start=$next'>Next</a>"; echo "<br><br><a href='profiles.php?addcomment=". $id ."' onclick='document.getElementById(\"commentarea\").style.visibility=\"visible\"; return false;'>Add a comment</a> <div id='commentarea' style='visibility: hidden;'> <form action='profiles.php' method='POST'><input type='hidden' name='hiddenid' value='". $id ."'><textarea name='comment' maxlength='300' cols='65' rows='15'></textarea><br><br><input type='submit' value='Add comment'> or <a href='#' onclick='document.getElementById(\"commentarea\").style.visibility=\"hidden\"; this.form.hiddenid.value=\"\";'>Discard comment</a></form> </div>"; } ..
  7. yeah that should work make sure your function is returning the correct values though so like return true; or return false; am I making sense?
  8. I dunno if this is necessary, maybe some other forum members could correct me, but this is the way i'd get your $datalist array from the database $query = mysql_query($select); //Build the array $i = 0; while ($row = mysql_fetch_assoc($query)) { $keys = array_keys($row); foreach($keys as $key) { $datalist[$i] = $row[$key]; } $i++; } instead of $datalist = mysql_fetch_array($select); $num=mysql_num_rows($select);
  9. Okidoki, a few things.... $grade = array("A","B","C","D","E","F"); $adno = $_GET['adno']; $grade[0]=A; $grade[1]=B; $grade[2]=C; $grade[3]=D; $grade[4]=E; $grade[5]=F; this is kind of redundant isn't it? you can remove all of this: $grade[0]=A; $grade[1]=B; $grade[2]=C; $grade[3]=D; $grade[4]=E; $grade[5]=F; you've already defined your array of possible grades, there's no need to do it again! for this section of code: foreach($datalist as $data){ if (intval($data) >= 80) { echo "<td>$grade[0]</td>"; } else { if (intval($data) >= 70 && intval($data) < 80) { echo "<td>$grade[1]</td>"; } else { if (intval($data) >= 60 && intval($data) < 70) { echo "<td>$grade[2]</td>"; }else { if (intval($data) >= 50 && intval($data) < 60) { echo "<td>$grade[3]</td>"; } else { if (intval($data) >= 40 && intval($data) < 50) { echo "<td>$grade[4]</td>"; } else { if (intval($data) <= 39 && intval($data) < 40) { echo "<td>$grade[5]</td>"; } } } } } } } I'd look at investing in some elseif() statements, seriously so something like this: foreach($datalist as $data) { if(intval($data) >= 80) { echo "<td>$grade[0]</td>"; } elseif(intval($data) >= 70 && intval($data) < 80) { echo "<td>$grade[1]</td>"; } elseif(intval($data) >= 60 && intval($data) < 70) { echo "<td>$grade[2]</td>"; } elseif(intval($data) >= 50 && intval($data) < 60) { echo "<td>$grade[3]</td>"; } elseif(intval($data) >= 40 && intval($data) < 50) { echo "<td>$grade[4]</td>"; } elseif(intval($data) <= 39 && intval($data) < 40) { echo "<td>$grade[5]</td>"; } } thats what the elseif is for! but, check that $data variable, i'm guessing that what you actually want there is something like $data['mark'] instead just $data, because your looking at the element of that array $data jus editing this again .. yeah so basically you downloaded your database into that variable $datalist (with entries of each row you've retrieved from the database), which is an array, and each element in that array will be another array - this will be an array for example $dataList[0]['name'], $dataList[0]['mark'], $dataList[0]['birthday'] - or whatever, just depends on how your tables are structured so when you launch into that foreach statment your going through each $dataList element and giving it the name $data, but $data is still an array - because each element of $dataList was an array.. am I making sense?
  10. by the way, i wouldnt write this: { if ($row[reported]==1) { $reporttext = "[Report]"; } else { $reporttext = "Message Reported"; } if ($row[hidden]==1) { $r The keys of $row[reported] and $row[hidden] really should be put in quotes like this $row['hidden'] and $row['reported'] you do this elsewhere too
  11. so you mean the "show next button" gets spit out twice right? well, its not a for/while/foreach statement or (from what i can see in the code snippet, within one), its just an if statement, it should not repeat that echo - my thoughts are then thats not where your problem is.. can you be more clear?
  12. Hi, i need to backup several tables from my MySql database using php. I just need some quick and easy method, nothing fancy, to backup tables and restore tables. I searched around and found a tutorial on the subject here http://www.php-mysql-tutorial.com/wikis/mysql-tutorials/using-php-to-backup-mysql-databases.aspx but i can seem to get the script to work, i'm using this: <?php $tableName = 'bookingBOOKINGS'; $backupFile = $_SERVER['DOCUMENT_ROOT'] . '/bookingBOOKINGS.sql'; $query = "SELECT * INTO OUTFILE '$backupFile' FROM $tableName"; $result = mysql_query($query); ?> I added the $_SERVER variable into $backupFile think it might help - but no cigar. I'm not getting any errors, either the file isnt being generated or i can't find it ( :-\ , doubt that though). Maybe I've been tricked by such a simple few lines of script to thinking i'd found a easy solution! I'd be happy to hear alternatives, i cant use exec() function, which another tutorial suggested, cause "its disabled for security reasons". Cheers
×
×
  • 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.