php - How to send a comment (in 1 table) to all users (referring to another table)? -


right have 2 tables. comment table , user table. short , simple, wanna sent comment users. need know sql command , how display on php.

comment table

  1. pk
  2. comment
  3. sender (refers username)
  4. receiver (refers username)

user table

  1. pk
  2. username
  3. etc.....

i tried using this:

$provider = $_request['provider'];  $cert = $_request['cert'];  $valid = $_request['valid'];  $lprice = $_request['lprice'];  $trial = $_request['trial'];  $cost = $_request['cost'];  echo $cert;  $sql=mysql_query("select * sslcert certificatename='$cert'",$connect);  if(mysql_num_rows($sql)>0)    {     echo"ssl exists.";     echo "<br><a href=addssl.php>back</a>";    }  else     {       $insert = mysql_query("insert sslcert (provider, certificatename, validation,                           listprice, trial, cost) values ('$provider', '$cert', '$valid', '$lprice',       '$trial',     '$cost')",$connect);             $result77=mysql_query("select username user");      while($row77=mysql_fetch_array($result77))      {        $insert1 = mysql_query("insert notification (msg, sender, receiver,   notification) values ('a new product available, $cert $provider', '$username',   '$row77['username']', 1)");        if(!$insert1){              die("there's little problem: ".mysql_error());             echo "<br><a href=quotesmanage1.php>back</a>";         }      }      if(!$insert){         die("there's little problem: ".mysql_error());        echo "<br><a href=addssl.php>back</a>";     }      echo "<br>you have add new product <br><a href=adminhome.php>back home</a>";      }        mysql_close($connect); } 

the call username somewhere else on page. came out blank page (error on php), ideas?

i believe want insert...select query.

 insert `comment`(`comment`.`comment`, `comment`.`sender`, `comment`.`receiver`) select 'message text or variable substitution', `user`.`pk`, '1' `user` 

you can substitute id instead of 1 @ end of select line, figured administrative user 1 (but can create new user sending these mass messages , use whatever number id corresponds.

by way, in comment table should reference user.pk, not user.username. that's sort of why have key in first place :-)


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -