This is the first time I'm using this website, I have recently started working on a project where the webpage will display two table, one of the table will gather all the information from a SQL Database and place them in the table along with a button next to each rows allowing you to insert that record to another to the other table, so far, this is the code I have written:
//Include the Following Files
include 'connect.php';
//Select All Price Plans
$query = "SELECT * FROM pricing";
$result = mysql_query($query);
//Print all Plans in Table
while ($pricing = mysql_fetch_array($result))
{
echo "<table border=1>";
echo "<tr>";
echo "<td>" .$pricing['planID']. "</td>";
echo "<td>" .$pricing['planTitle']. "</td>";
echo "<td>" .$pricing['planDescription']. "</td>";
echo "<td>" .$pricing['planPricing']. "</td>";
echo "<td>" . **<a href="'. $link .'">BUTTON HERE</a>** . "</td>";
echo "</tr>";
echo "<table>";
}
//Assign $link to Case
$link = '?run=planA';
//Pre-defined Functions
function planA()
{
$query = "INSERT into restaurant_plan (`planID`, `planTitle`, `planDescription`, `planPricing`) SELECT * FROM pricing WHERE planID='2' ";
$result = mysql_query($query);
}
//Setting Case to Run Each Functions
if (isset($_GET['run'])) $linkchoice=$_GET['run'];
else $linkchoice='';
switch($linkchoice)
{
case 'planA':
planA();
break;
case 'planB':
planB();
break;
}
Could anyone suggest any guide or possibly an example how I could assign a function to each rows? Thanks a lot!
mysql_*functions. They're being deprecated. Instead use PDO (supported as of PHP 5.1) or mysqli (supported as of PHP 4.1). If you're not sure which one to use, read this article.