psyion Posted March 7, 2006 Share Posted March 7, 2006 here is my problem, i'm need to randomly pick 15 names from a table call student and store them to another table call temp_classhere is the random partSELECT nameFROM studentORDER BY RAND() LIMIT 15but than how do i send this 15 names to temp_class????? Quote Link to comment https://forums.phpfreaks.com/topic/4363-help~-how-pick-few-things-and-insert-to-another-table/ Share on other sites More sharing options...
psyion Posted March 8, 2006 Author Share Posted March 8, 2006 can some one help me please... i've been stuck here for roughly 2 days i'll be happy if some one can help me... below are the code generate by Dreamweaver about showing a repeted table showing all the 15 randomly pick name and a text field that submit new name... can some one help me modify or show where i can get more example.<?php require_once('../Connections/activity.php'); ?><?phpfunction GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue; switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue;}$editFormAction = $_SERVER['PHP_SELF'];if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);}if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $insertSQL = sprintf("INSERT INTO temp_class (temp_name) VALUES (%s)", GetSQLValueString($_POST['temp_name'], "text")); mysql_select_db($database_activity, $activity); $Result1 = mysql_query($insertSQL, $activity) or die(mysql_error()); $insertGoTo = "untitled.php"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo));}mysql_select_db($database_activity, $activity);$query_rand_pick = "SELECT student.name FROM student ORDER BY RAND() LIMIT 15";$rand_pick = mysql_query($query_rand_pick, $activity) or die(mysql_error());$row_rand_pick = mysql_fetch_assoc($rand_pick);$totalRows_rand_pick = mysql_num_rows($rand_pick);?><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>Untitled Document</title></head><body><table border="1" cellpadding="0" cellspacing="0"> <tr> <td>name</td> </tr> <?php do { ?> <tr> <td><?php echo $row_rand_pick['name']; ?></td> </tr> <?php } while ($row_rand_pick = mysql_fetch_assoc($rand_pick)); ?></table><p> </p><p> </p><form method="post" name="form1" action="<?php echo $editFormAction; ?>"> <table align="center"> <tr valign="baseline"> <td nowrap align="right">Temp_name:</td> <td><input type="text" name="temp_name" value="" size="32"></td> </tr> <tr valign="baseline"> <td nowrap align="right"> </td> <td><input type="submit" value="Insert record"></td> </tr> </table> <input type="hidden" name="MM_insert" value="form1"></form><p> </p><p> </p></body></html><?phpmysql_free_result($rand_pick);?> Quote Link to comment https://forums.phpfreaks.com/topic/4363-help~-how-pick-few-things-and-insert-to-another-table/#findComment-15274 Share on other sites More sharing options...
greycap Posted March 8, 2006 Share Posted March 8, 2006 [!--quoteo(post=352614:date=Mar 7 2006, 03:01 PM:name=psyion)--][div class=\'quotetop\']QUOTE(psyion @ Mar 7 2006, 03:01 PM) [snapback]352614[/snapback][/div][div class=\'quotemain\'][!--quotec--]here is my problem, i'm need to randomly pick 15 names from a table call student and store them to another table call temp_classhere is the random partSELECT nameFROM studentORDER BY RAND() LIMIT 15but than how do i send this 15 names to temp_class?????[/quote][code]INSERT INTO temp_class ( SELECT * FROM student ORDER BY RAND() LIMIT 15)[/code]Also, in that code you posted, you cant use strings in a switch() statement. Quote Link to comment https://forums.phpfreaks.com/topic/4363-help~-how-pick-few-things-and-insert-to-another-table/#findComment-15276 Share on other sites More sharing options...
psyion Posted March 8, 2006 Author Share Posted March 8, 2006 thanks alot... Quote Link to comment https://forums.phpfreaks.com/topic/4363-help~-how-pick-few-things-and-insert-to-another-table/#findComment-15294 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.