Shalazar
02-22-2000, 01:54 AM
I was playing around with a table where the ID field is listed as the PRIMARY KEY.[nbsp][nbsp]I understand that PRIMARY KEY is used so that no two ID fields contain the same number.
I was experimenting with two options to print out the number of rows.
1 --
$ID = mysql_insert_id ($result)
where $result is taken from the insertion of the variable into the new row.
Now, assuming the table remains unmodified, you can do something like:
print ("Your chances of winning are 1 in $ID");
Outputting something like "Your chances of winning are 1 in 19."
However, if rows are deleted in the interim, the next person would receive "Your chances of winning are 1 in 20." even though sevreal rows have been deleted.
Is there a way to alter each row's ID if deletion occurs? How about resetting the ID for the entire table without starting from scratch again?
Or is the better way to do it as follows?
2 --
$SelectAll = "SELECT * FROM table_name";
$Results =[nbsp][nbsp]MySQL($db,$SelectStr);
$RowCount = MySQL_NUMROWS($Results);[nbsp][nbsp][nbsp][nbsp][nbsp]
print ("Your chances of winning are 1 in $RowCount");
This works like a charm, even when deleting rows.[nbsp][nbsp]
I understand the majority of this code -- but could somebody better explain what values get placed into the $SelectAll?[nbsp][nbsp]When I run SELECT * FROM table_name from the mysql command line, I figure the data being send is the number of rows.
I don't understand the middle line, so that's what is most important for me to have explained.[nbsp][nbsp]What does the MYSQL() command do with those variables?
Thanks again.
I was experimenting with two options to print out the number of rows.
1 --
$ID = mysql_insert_id ($result)
where $result is taken from the insertion of the variable into the new row.
Now, assuming the table remains unmodified, you can do something like:
print ("Your chances of winning are 1 in $ID");
Outputting something like "Your chances of winning are 1 in 19."
However, if rows are deleted in the interim, the next person would receive "Your chances of winning are 1 in 20." even though sevreal rows have been deleted.
Is there a way to alter each row's ID if deletion occurs? How about resetting the ID for the entire table without starting from scratch again?
Or is the better way to do it as follows?
2 --
$SelectAll = "SELECT * FROM table_name";
$Results =[nbsp][nbsp]MySQL($db,$SelectStr);
$RowCount = MySQL_NUMROWS($Results);[nbsp][nbsp][nbsp][nbsp][nbsp]
print ("Your chances of winning are 1 in $RowCount");
This works like a charm, even when deleting rows.[nbsp][nbsp]
I understand the majority of this code -- but could somebody better explain what values get placed into the $SelectAll?[nbsp][nbsp]When I run SELECT * FROM table_name from the mysql command line, I figure the data being send is the number of rows.
I don't understand the middle line, so that's what is most important for me to have explained.[nbsp][nbsp]What does the MYSQL() command do with those variables?
Thanks again.