Search:  

 
 
   All ForumsHot TopicsGallery






how-to block ads


 
Forums » Tech and Talk » OS and Software » Webmasters and Developers » PHP MySQL while Loop
Uniqs:
55
Share Topic:
RSS topic:
toggle:
flat / full
normal / watch
Posting:
Post a:
Post a:
Hosting Domain »
« HTML "alt" tag  

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

Re: PHP MySQL while Loop

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
while_debug.zip 1,070 bytes
(while_debug.php)
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

Re: PHP MySQL while Loop

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:

Re: PHP MySQL while Loop

said by justin See Profile:
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] -
Forums » Tech and Talk » OS and Software » Webmasters and DevelopersHosting Domain »
« HTML "alt" tag  


Wednesday, 02-Dec 23:54:58 Terms of Use | Privacy Policy | Hosting by www.nac.net - DSL,Hosting & Co-lo | feedback | contact
over 10 years online! © 1999-2009 dslreports.com.
page compression OFF
Most commented news this week
· [162] Comcast Releasing Promised Usage Meter
· [95] Graduate Student Unveils Sprint's GPS Sharing With Feds
· [79] Latest Consumer Reports Survey Not Kind To AT&T
· [70] Baltimore To Ban Lazy Cable Installs
· [62] Broadband Killed The Game Console
· [55] Rogers Unveils The ISP Dream Model
· [46] ACTA: Global Three Strikes
· [41] Rural Carriers Quickly Embracing Fiber
· [39] AT&T, Verizon Drop 3G Ad Dispute
· [38] Charter Exits Chapter 11
Most people now reading
· False positive in Avast! or is it real? [Security]
· Do I have a problem due to AVAST? [Security]
· Options if ACTA is ratified [TekSavvy]
· [Scam] Is zwee.com a scam site? [Spam, Scam and Phishbusters]
· [WIN7] When exactly should you flash bios when installing new OS [Microsoft Help]
· Poll: Have you ever been charged an overage fee since ... [TekSavvy]
· [Equipment] Ubiquiti third party firmware for the M series Bulle [Wireless Service Providers]
· [FS] Acer Netbook + Candles + Hard Drives + More! [For Sale/Wanted]
· Download speeds very slow. [AT&T West]