  cdog Boo Premium join:2001-10-11 Chicago, IL clubs:
1 edit | PHP MySQL while Loop
Hey I have a question I AM STUMPED. I am setting up a message board on my website and I have an alert admins section. Well in the forum I have "Super Admins" which have control over the whole site and every forum. Also I have board admins which just moderate what board they are assigned to.
"If someone hits "Hey Mods" like we have here at dslr it sends out an alert to the moderators of THAT forum and to the super mods.
Here are my 2 while loops:
// GET SUPER ADMIN $z_getsuper = mysql_query("SELECT * FROM members WHERE mem_level = '5'"); while ($row = mysql_fetch_array($z_getsuper)) { $z_super_id = $row['mem_id']; // SEND MESSAGE TO SUPER ADMINS $sendalertsuper = mysql_query("INSERT INTO mb_mod_alert SET mb_mod_alert_receive_id = '$z_super_id', mb_mod_alert_sender_id = '$l_id', mb_mod_alert_preset = '$preset', mb_mod_alert_reason = '$reason', mb_mod_alert_msg = '$alert_msg', mb_mod_alert_date = '$rightnow', mb_mod_alert_status = 'new'"); }
Here is the problem... I have 3 super admins in my database, each have their own unique id set by mysql(auto_increment)
When the information gets entered into the database it works fine for one admin inserting his id, but then the other two it inserts and id of "0" as their member id.
it's counting there is 3 mods because it is inserting 3 rows in the table, but why is it only entering ONE user with his member ID???
I'm so confused
full code here : »www.pastebin.com/28435 |
|
  WalkGood Checkin Out Your Desk Premium join:2002-12-28 Patchogue, NY
| Are u sure you are retrieving the CORRECT 3 super-admins in the first query?
Maybe you could break it into 2 parts. First fetch all the super-admins into an array. As a temporary debugging aide then in a separate loop go thru the array and display what's in that array.
Second part, in a separate loop go thru the array and do the insert. |
|
  Ken Sohryu Darkest Days
join:2001-01-07 Chicago, IL
1 edit | reply to cdog The link to the source code you posted didn't work, so I had to wing it in writing up some basic error checking tools. I hope they help you out a bit.
edit: Stupid forum screwed up my beautiful code formatting, so I've attached the actual script.
// I basically threw in some basic diagnostic displays. // Had no choice since the link to your complete source code // wasn't working. Anyway, this should help you track down // your problem. Hopefully.
error_reporting( E_ALL );
// GET SUPER ADMIN $z_getsuper = mysql_query( "SELECT * FROM members WHERE mem_level = '5'" ) or die( mysql_e *rror() );
// Loop through results. while( $row = mysql_fetch_array( $z_getsuper ) ) { // Comment this if() statement out or delete it when finished debugging. if( $row['mem_id'] == 0 ) { // Output all fields of "faulty" record for troubleshooting. echo '<p>Error: An ID number of <strong>0</strong> was detected.</p>';
rsort( $row, SORT_NUMERIC );
$i = ( count( $row ) - 1 );
do { echo '<p>' . $row[$1] . '</p>'; } while( $i-- );
die(); }
$z_super_id = $row['mem_id'];
// Construct SQL query separately. Easier to read. $sql ="INSERT INTO mb_mod_alert SET mb_mod_alert_receive_id = '$z_super_id', mb_mod_alert_sender_id = '$l_id', mb_mod_alert_preset = '$preset', mb_mod_alert_reason = '$reason', mb_mod_alert_msg = '$alert_msg', mb_mod_alert_date = '$rightnow', mb_mod_alert_status = 'new'";
// Send message to Super Admins. $sendalertsuper = mysql_query( $sql );
// If message insertion fails, kill script and display debugging info. // Comment out or delete when finished debugging. if( mysql_affected_rows() <= 0 ) { echo '<p><strong>NOTICE:</strong> Could not insert new record into database.</p>';
// If there was an SQL error, we'll display it. if( mysql_error() ) { echo '<p><strong>MySQL Error:</strong>' . mysql_error() . '</p>'; }
echo '<p><strong>Your SQL Query:</strong> <span style="color: #696;">' . $sql . '</span></ *p>';
die(); } }
(*) WARNING 2 long line(s) split
-- » I am surrendering to the Gravity and the unknown.
» Catch me, heal me, lift me back up to the sun.
» I choose to live.
A Perfect Circle - Gravity |
|
  justin Australian join:1999-05-28 Brooklyn, NY | Ths stupd forum was protecting us all from your long lines blowing the right margin, if you kept them to 80 columns or less, it would look just as you wanted it to. |
|
  cdog Boo Premium join:2001-10-11 Chicago, IL clubs:
| said by justin : Ths stupd forum was protecting us all from your long lines blowing the right margin, if you kept them to 80 columns or less, it would look just as you wanted it to.
ahhhh ok 
p.s. I got it to work... thanks guys appreciate it -- If what ya got is perfect and you always want better. Happiness will never come. - [Have Some Fun] - |
|