
coolphpdude
Members-
Posts
214 -
Joined
-
Last visited
Never
Everything posted by coolphpdude
-
This is a wierd one. (well for me anyway) I have a message section on my uni project. On that page you see row after row of your messages, at the end of each row is a tick box, tick the box of the messages you want to delete and click the 'delete' button. The messages are deleted and the page is refreshed, it works perfectly. I borrowed the code that does this and put it on a different page and its not working properly. This page is the profile of a class, so class details, current work, loads of crap that you don't really need to know about but at the bottom of this class profile page is memo's to this class in date order. Now, i have tried to incorporate the same delete scenario in this page. Tick box after the memo, tick the ones you want to delete and click delete. So back to where i was, i took working code, applied it to this page, changed the relevant settings and half works. The memo deletes... however, the page is not refreshed, its actually blank. Any fields i pull in from the database with regards to the class profile are not showing up, i have to go out of the class profile page and go back into it to see the profile again (minus the deleted memo's). So the code is actually deleting what it is meant to, but where is my page going... Any help?? I'll post my code below, stripped down just with what you need <?php // delete message loop switch(@$_GET["action"]) { Case "delete": if(is_array($_POST['checkbox'])) { foreach($_POST['checkbox'] as $m_id) { mysql_query("DELETE FROM classmemo WHERE m_id='$m_id'") or die(mysql_error()); } } //echo 'records deleted'; //break; default: // form for memo delete echo '<form method="post" action="'.$_SERVER['PHP_SELF'].'?action=delete">'; // memo table echo "<table width='400' border='0' cellspacing='0' cellpadding='10'>"; //set number of columns and initial column number $numcols = 3; // how many columns to display $numcolsprinted = 0; // no of columns so far // get the results to be displayed $query = "SELECT * FROM classmemo WHERE c_id='$c_id"; $mysql_result = mysql_query($query) or die (mysql_error()); // get each row while($myrow = mysql_fetch_array($mysql_result)) { //get data $memo = $myrow[0]; if ($numcolsprinted == $numcols) { print "</tr>\n<tr>\n"; $numcolsprinted = 0; } $memo = $myrow["m_id"]; // output row from database echo "<td width='25%' align='center' valign='top'>$memo<input class='blank' name='checkbox[]' type='checkbox' id='checkbox[]' value='".$myrow['m_id']." '></td>\n"; // bump up row counter $numcolsprinted++; } // end while loop $colstobalance = $numcols - $numcolsprinted; for ($i=1; $i<=$colstobalance; $i++) { } print "<TD></TD>"; echo"</table>"; echo "<br>"; echo "<table width='100%'>"; echo "<tr>"; echo "<td align='left'>"; echo '<input type="submit" value="Delete Pictures" />'."\n"; echo "</td>"; echo "</tr>"; echo "</table>"; echo "</form>"; //break; } ?>
-
i will do craygo, so if i want 3 columns it will automatically keep recreating the rows until the output is complete?? I'll give this a go when i get to uni tomorrow. Cheers for your help guys
-
I've got set pic sizes and 3 pics would fit comfortably on every row... So basically do a pic count and row count?? Ignore the syntax but something as follows for quickness?? <table> <tr> // start the while loop within the row while ($imagesexist) { <td>$image<td> // if the the $imageexist counter exceeds 3 close off that row and begin new row if ($imageexist is a multiple of 3) { </tr> <tr> } // end while loop } //close table </table> would that work???
-
Hi guys, I touched on this a while back but never got it sorted. Im just wondering how to do this. Imagine these 2 scenario's. 1) You have 13 pics to display in a table... you output these 1 after another in a while loop vertically. The code would simply output the pictures 1 after another vertically until 13 pics were output (1 new row after another) ...This scenario is fine, i understand it and have used it. Nice and easy. But how about this one... 2) You need to output the pictures horizontally with limited horizontal space... Then what? Say i have got a table 800px wide and i can only fit 3 pictures on every row, i would need a table consisting of 3 columns and 5 rows. But i am still not sure how to go about doing this or how to insert each picture one after the other. Also what happens if you dont kno how many results would be returned... I could do a query that returns 53 pictures or 999 pics... What i am trying to get at is how do i output all of my pictures without using the verticle, one after another, method. Im quite stuck with this one!!
-
[SOLVED] prefix a primary id with username
coolphpdude replied to coolphpdude's topic in PHP Coding Help
how do you mark the topic as solved??? I thought they took that away -
[SOLVED] prefix a primary id with username
coolphpdude replied to coolphpdude's topic in PHP Coding Help
Champion, i guess talking through things helps! I just cudnt get my head around it when i was thinking about it!! Cheers for your help guys. -
[SOLVED] prefix a primary id with username
coolphpdude replied to coolphpdude's topic in PHP Coding Help
something like Primary Key DBuniqueID Name ETC ID UID Bob etc and then pass the UID rather than the primary ID? -
[SOLVED] prefix a primary id with username
coolphpdude replied to coolphpdude's topic in PHP Coding Help
tell me more? Sounds like what i'm after... -
[SOLVED] prefix a primary id with username
coolphpdude replied to coolphpdude's topic in PHP Coding Help
yeah pretty much. the problem is that i am running a message table. the message can correspond to records on 1 of 5 different tables. each one of the 5 tables runs a primary id with the structure of auto-incrementing integer... however the message needs to display some of the information from the record. Now say for example we have got table A, B, C, D, E. Each table will have 10 rows so each will have existing primary ID's of 1-10. If a teacher receives a message and the message needs to contain information about record 3 from table E then there is nothing to distinguish that. If i run a search query to select all records where ID = 3 FROM tables A B C D E (i know this is not the correct syntax) then there are 5 records with the same primary id... do you get me? Although that primary ID might be unique to that table it won't be unique accross my database. where if i had the ID as A1, A2, A3, etc... or similar then it would be unique within my database. -
[SOLVED] prefix a primary id with username
coolphpdude replied to coolphpdude's topic in PHP Coding Help
It is, the example i gave (probably poorly explained) is just a hypothetical scenario and nothing to do with my actual site or database structure... It was just easier explaining it that way than 30 pages of writing to explain the real scenario... lol -
[SOLVED] prefix a primary id with username
coolphpdude replied to coolphpdude's topic in PHP Coding Help
Well, i've read that, and i do understand it. I've got my tables broken down in my opinion perfectly. The information i gave above is just a very basic stripped down example. I just need help on creating an id that consists of... username(1) username(2) username(3) . . . . . . username(9865056486) etc... -
I've found a potential future problem with my code. at present i have a teachers table and a lesson table. I have a teacher unique id which is their login id. for the lessons i just have it set to integer auto-increment. I was planning on letting the table automatically assign id's for the lesson upon adding a new row. however, ive thought of a potential problem which could be corrected using a prefix to the lesson id of the username. So far example user = bob ID Lesson Teacher bob1 = english = Bob Smith bob2 = maths = Bob Smith bob3 = french = Bob Smith user = Joe ID Lesson Teacher joe1 = english = joe Smith joe2 = maths = joe Smith joe3 = french = joe Smith Rather than... ID Lesson Teacher 1 = english = Bob Smith 2 = maths = Bob Smith 3 = french = Bob Smith 4 = english = joe Smith 5 = maths = joe Smith 6 = french = joe Smith How would i make this happen? As i mentioned above im currently using an auto-incrementing integer field for the ID.
-
both ways work a treat. I've gone with dingus's code because it combines numbers and both upper and lowercase code so gives me more chance of it being unique. I just need to figure out the code now to check database to see if it exists and if it does stick it in a while loop to generate a different code. Thanks for your help guys, much appreciated.
-
is there a way to check to see if this random number already exists in the database and if it does then create an alternative random number?
-
You little star. Cheers bud!
-
Hi there, Is there a quick way of generating a random 10-digit code? it must be 10 digits long, no shorter, no longer.
-
yeah sorry database table on MySQL. I'll give that order by random thing a go! I've just messed everything up trying a very long way to go about it s i'll have to put that back together first!!! Oh the joy! Thanks for your help guys!
-
Hi there, If i have got 10 'messages of the day' in a table for example that are relevant to a user. how would i select all records from that table that are relevant to the user but only display 1 at random. so if a user was to log in it would show a random 1 of those 10 messages, if he was to log in again later on that day it would select another message at random? Thanks in advance
-
ahhh!! That obvious!! i'll give it ago!
-
Hi sorry for not replying sooner, i got pulled away from working on this. So far i played about with the positioning of the code as when we originally started it was producing lots of errors. Now, theres no errors but when you tick a box and cclick the delete button, the page kind of refreshes but nothing is deleted...
-
I started a post off a few weeks ago about this, but i have left it, avoided it, and put it to the back of my list of jobs because i wasn't having much luck with it. So any help would be appreciated. i think this will be an easy one for you lot but i just can't seem to get my head around it. I got a message database on my project. So a user receives messages from other user's just like an email system. Currently i have a delete button next to each message as it is output from the database using a while loop. Now the propblem with this is, if you have got 40 messages you have to click delete 40 times. I want it so that theres a tick box next to each message so u can mark the messages you would like to delete and click a single delete button at the top to delete all of the marked messages. Is this easy? most email messaging systems have it so i suppose its do able, i just dont know how. Also could i place a tick box at the so the user could click this and it would mark all messages on this page?? what i've got so far is with the help of jesushax which i am very grateful of. I'll post the code below... <?php session_start(); switch(@$_GET["action"]) { Case "delete": if(is_array($_POST['checkbox'])){ foreach($_POST['checkbox'] as $message){ mysql_query("DELETE FROM memos WHERE message_id='$message'") or die(mysql_error()); } } //echo 'records deleted'; //break; default: echo '<form method="post" action="'.$_SERVER['PHP_SELF'].'?action=delete">'; echo "<table width='100%' border='2' bordercolor='#cccccc' style='border-collapse: collapse' cellpadding='5' align=center >\n"; echo "<tr><th>Subject</th><th>Sender</th><th>Delete</th></tr>\n"; while ($memos = mysql_fetch_array($memos)) { printf("<td>%s</td>\n", $memos["memo_subject"]); printf("<td>%s</td>\n", $my_message_row["message_sender"]); printf("<td align='center' cellpadding='10' width='60'><input class='blank' name='checkbox[]' type='checkbox' id='checkbox[]' value='".$row['recordID']." '></td></tr>"); } echo "</table>\n"; echo '<tr><td colspan="3"><input type="submit" value="Delete these records" />'."\n"; echo "</form>"; ?> Cheers
-
Its working, had to make a couple of modifications but that code and help you both gave me was a great help. i really appreciate it!! $dir = "testfolder/test/"; //echo "$dir"; //$dir = "/testfolder/test"; //Remove the trailing / if(!file_exists($dir)) echo "Folder '$dir' doesn't exist"; echo "$dir"; // $dir = the target directory // $DeleteMe = if true delete also $dir, if false leave it alone function SureRemoveDir($dir, $DeleteMe) { if(!$dh = @opendir($dir)) return; while (false !== ($obj = readdir($dh))) { if($obj=='.' || $obj=='..') continue; if (!@unlink($dir.'/'.$obj)) SureRemoveDir($dir.'/'.$obj, true); } closedir($dh); if ($DeleteMe){ @rmdir($dir); } } SureRemoveDir($dir, true); I had to put SureRemoveDir($dir, true); after the code as it was trying to call the function before i had defined it. Also, $dir = "testfolder/test/";... i had to take off the / from before testfolder (i previously had $dir = "/testfolder/test/"; ) and it was saying the folder did not exist. Once i removed the beginning slash it worked a treat! Thanks again lads!!
-
im just off home, i'll pick up your replies when i get home. Cheers for your help lads
-
nope still not working!! no errors or anything, all it displays is the echo request that i set so i can make sure my path is in the variable.
-
lol ahh 1 sec