I am trying to do a loop and what i need done is i am selecting all from the user table then I need it to take the id of each users put it into the mem_id field in the support table and go until it does all the users
Here is the code i have so far
$r = mysql_query("SELECT * FROM user") or die(mysql_error());
while($info = mysql_fetch_array($r, MYSQL_ASSOC)
$q=mysql_query("INSERT into support(id,mem_id,email,subject,message,sent,status)VALUES(null,'" . $info['id'] . "','$email','$subject','$msg','$date','4')")or die(mysql_error());
@mysql_free_result($r);
}
as you can see i have it all done ecept where i make it go into the support table even though i have the query it not working I am lost on loops. anyone who can help would be nice
Thanks
A while loop .. not sure how to
Moderator: General Moderators
-
coolpositive
- Forum Newbie
- Posts: 4
- Joined: Sat Jun 07, 2008 6:13 am
Re: A while loop .. not sure how to
Hi nite4000,
First you optimized your mysql query like
$resultSet = mysql_query("SELECT id FROM user")or die(mysql_error());
while($row = mysql_fetch_array($resultSet))
{
$userId = $row["id"];
$strQuery = "INSERT into support(id,mem_id,email,subject,message,sent,status)VALUES(null,'$userId','$email','$subject','$msg','$date','4')" ;
$resultSet1 = mysql_query($strQuery)or die(mysql_error());
}
mysql_free_result($resultSet);
mysql_free_result($resultSet1);
still if you got error then
echo your both query and direct put on the phpmyadmin sql section and got the exect error.
or debug your code through echo language constructor.

First you optimized your mysql query like
$resultSet = mysql_query("SELECT id FROM user")or die(mysql_error());
while($row = mysql_fetch_array($resultSet))
{
$userId = $row["id"];
$strQuery = "INSERT into support(id,mem_id,email,subject,message,sent,status)VALUES(null,'$userId','$email','$subject','$msg','$date','4')" ;
$resultSet1 = mysql_query($strQuery)or die(mysql_error());
}
mysql_free_result($resultSet);
mysql_free_result($resultSet1);
still if you got error then
echo your both query and direct put on the phpmyadmin sql section and got the exect error.
or debug your code through echo language constructor.
-
coolpositive
- Forum Newbie
- Posts: 4
- Joined: Sat Jun 07, 2008 6:13 am
Re: A while loop .. not sure how to
Hi nite4000,
First you optimized your mysql query like
$resultSet = mysql_query("SELECT id FROM user")or die(mysql_error());
while($row = mysql_fetch_array($resultSet))
{
$userId = $row["id"];
$strQuery = "INSERT into support(id,mem_id,email,subject,message,sent,status)VALUES(null,'$userId','$email','$subject','$msg','$date','4')" ;
$resultSet1 = mysql_query($strQuery)or die(mysql_error());
}
mysql_free_result($resultSet);
mysql_free_result($resultSet1);
still if you got error then
echo your both query and direct put on the phpmyadmin sql section and got the exect error.
or debug your code through echo language constructor.

First you optimized your mysql query like
$resultSet = mysql_query("SELECT id FROM user")or die(mysql_error());
while($row = mysql_fetch_array($resultSet))
{
$userId = $row["id"];
$strQuery = "INSERT into support(id,mem_id,email,subject,message,sent,status)VALUES(null,'$userId','$email','$subject','$msg','$date','4')" ;
$resultSet1 = mysql_query($strQuery)or die(mysql_error());
}
mysql_free_result($resultSet);
mysql_free_result($resultSet1);
still if you got error then
echo your both query and direct put on the phpmyadmin sql section and got the exect error.
or debug your code through echo language constructor.