从第1页上的链接列出第2页的数据

时间:2015-07-07 04:59:46

标签: php

第1页,下面的代码工作正常,并列出食谱名称,即BBQ Pork等

<form action="recipe_show.php" method="post">
<?php 
$result = mysql_query("SELECT recipe_name FROM recipes ORDER BY recipe_name ASC"); // Run the query
if ($result) { // If it ran OK, display the records
// Table header
echo '<table>
<td align="left"><b>Recipe Name</b></td>
</tr>';
// Fetch and print all the records
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
    echo '<tr>
        <td><a href="recipe_show.php">'. $row['recipe_name'] .'</a></td>    
    </tr>';
    }
    echo '</table>'; // Close the table
    mysql_free_result ($result); // Free up the resources   
} else { // If it did not run OK
// Message
    echo '<p class="error">The current recipe_name could not be retrieved. We apologize for any inconvenience.</p>';
    // Debugging message
    echo '<p>' . mysql_error($dbcon) . '<br><br />Query: ' . $q . '</p>';
} // End of if ($result)
mysql_close($dbcon); // Close the database connection.
?></p>
</form>
</div>

当我点击链接时,从第1页开始,它会打开第2页。我得到了标题,但没有关于BBQ Pork链接的数据。以下是第2页的代码。

<form action="" method="post">
<?php 
$recipe = mysql_real_escape_string($_GET['recipe_name']); //if using mysql
    $myresult = "SELECT * FROM recipes WHERE recipe_name = '".$recipe. "'";
        $num = mysql_num_rows($myresult);                         
            for ($i = 0; $i < $num; $i++){
                $row = mysql_fetch_array($myresult, MYSQL_ASSOC);
                $row = (($i % 2) == 0) ? "table_odd_row" : "table_even_row";
    echo "<tr row=".$row.">";
    }
if ($myresult) { // If it ran OK, display the records
echo '<table>
<td width="250" align="center"><b>Recipe Name</b></td>
<td width="250" align="left"><b>Instructions</b></td>
<td width="250" align="left"><b>Directions</b></td>
<td width="250" align="left"><b>Notes</b></td>
</tr>';

while ($row = mysql_fetch_array($myresult, MYSQL_ASSOC)) {
    echo '<tr>
    <td align="left">' . $row['recipe_name'] . '</td>
    <td align="left">' . $row['ingredients'] . '</td>
    <td align="left">' . $row['directions'] . '</td>
    <td align="left">' . $row['notes'] . '</td>
    </tr>';
    }
    echo '</table>'; // Close the table
    mysql_free_result ($myresult); // Free up the resources 
} else { 
    echo '<p row="error">The current Recipe could not be retrieved. We apologize for any inconvenience.</p>';

    echo '<p>' . mysql_error($dbcon) . '<br><br />Query: ' . $q . '</p>';
} ($myresult)
mysql_close($dbcon); // Close the database connection.
?>

希望我已经正确设置了这个?非常感谢,提前寻求帮助和指导

0 个答案:

没有答案