Hello. I'm still a beginner in writing PHP programs. (3 weeks or so...) I hate to ask such basic questions. But I have run out of choices after spending several hours by trial and error.
(1) I have a table ($table02) with 4 fields. One of the fields (num) in this table shows the numbers of the times in which the same IP addresses are recorded in another table ($table01). (Please see the attachment if necessary.)
If I wanted to insert the same numbers shown in 'num' also into 'percent', I could write
$sql_01 = "SELECT * FROM $table01";
$result_01 = mysql_query($sql_01,$my_sql_connect) or die(mysql_error());
$num_rows = mysql_num_rows($result_01);
$sql_02 = "SELECT * FROM $table02";
$result_02 = mysql_query($sql_02,$my_sql_connect) or die(mysql_error());
WHILE ($row_ip = mysql_fetch_array($result_02)) {
$insert_percent = "INSERT INTO $table02 (percent) VALUES ('".$row_ip['num']."')";
$insert_result = mysql_query($insert_percent,$my_sql_connect) or die(mysql_error());
}
But I actually want to insert a percentage in each cell under 'percent' where a percentage is calculated by $row_ip['num']/$num_rows*100.
If I write
$insert_percent = "INSERT INTO $table02 (percent) VALUES ('".$row_ip['num']."/$num_rows*100')";
or
even if I write
$insert_percent = "INSERT INTO $table02 (percent) VALUES ('".$row_ip['num']."/30')";
the numbers in 'num' will be duplicated under 'percent.' What am I doing wrong?
(2)
I only want to insert numbers under 'percent.' If I use INSERT new rows will be inserted on top of existing ones. But I suppose I cannot use UPDATE in this situation. What can I do so that I can enter numbers only under 'percentage' without creating new rows.
I'm sorry to ask such a basic question. I search for 'insert rows mysql' and read a few dozen matches. But I didn't find anything particular.
Thank you for your time.
[attachment deleted by admin]