Hey,
I have the following query which I would like to insert into another table which I guess would demand some kind of loop or such.

The query:

$colname_GetName = "-1";
if (isset($_SESSION['MM_Username'])) {
  $colname_Name = $_SESSION['MM_Username'];
}
mysql_select_db("db_name");
$query_Recordset = sprintf("SELECT * FROM Table WHERE UserName = %s", GetSQLValueString($colname_GetName, "text"));
$Recordset = mysql_query($query_Recordset) or die(mysql_error());
$row_Recordset = mysql_fetch_assoc($Recordset);
$totalRows_Recordset = mysql_num_rows($Recordset);

I would like to loop through and insert all values for $row_Recordset, $row_Recordset etc into a new table.

Hi
Is this what your looking for?
Obviously replacing the '####' with the column name of the data you want to repeat. If you want everything to be printed. Simply create a variable outside the while loop and then increment it after the process is done (just before the end of the while loop). Put this as the array value.

$colname_GetName = "-1";
if (isset($_SESSION['MM_Username'])) {
  $colname_Name = $_SESSION['MM_Username'];
}
mysql_select_db("db_name");
$query_Recordset = sprintf("SELECT * FROM Table WHERE UserName = %s", GetSQLValueString($colname_GetName, "text"));
$Recordset = mysql_query($query_Recordset) or die(mysql_error());
$totalRows_Recordset = mysql_num_rows($Recordset);
while ($row_Recordset = mysql_fetch_assoc($Recordset)) {
echo "<table>";
echo "<tr>";
echo "<td>";
echo "$row_Recordset['#####']";
echo "</td>";
echo "</tr>";
echo "</table>";
}
echo "<br><br>There are ".$totalRows_Recordset." row(s)";

If you need any help, just post
:)

Sorry I got the wrong idea to what you wanted after re-reading.
The same method applies though. Just in a different context.
Hope this helps still

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.