I sincerely apologize if repost, I can't find an answer. I am new to MySql and PHP and I am trying to write a stored procedure that returns content from two separate tables. The call is essentially this:
CREATE DEFINER=`root`@`localhost` PROCEDURE `grabPage`(t_user VARCHAR(32),
t_page VARCHAR(128))
BEGIN
SELECT formC FROM menuTable WHERE user=t_user;
SELECT formC FROM siteTable WHERE user=t_user AND page=t_page ORDER BY contentID;
END
Is this the wrong way of looking at this? What is the best practice? The reason I want to do this with one stored procedure is so that I only have to make one call to the database in my php. That code looks like this, if I should handle it in the php how would I go about doing that?
$con = mysqli_connect("localhost", "dbusername", "dbpassword", "database");
$query = "CALL grabPage('username', 'pagename')";
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con, $query);
if (!$result) {
printf("Error: %s
", mysqli_error($con));
exit();
}
$row = array();
while ($row[] = mysqli_fetch_array($result));
mysqli_close($con);
foreach ($row as $htmlOut)
echo $htmlOut['formattedContent'];
Thanks for your help.