Hello to all,
please i'm new PHP and trying to display some records from my db using
dreamweaver.
I have 2 tables ( Subjects and Pages) where Subjects is the parent and Pages
is the child.
I want to get all pages belonging to each subject but my query gives me all
pages under the first result of the query.
How can I get only pages of each subject under it's own ID ( parent + it's
child)?
I'll include my code for better reference.
<?php require_once('../../Connections/shop.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "",
$theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ?
mysql_real_escape_string($theValue) : mysql_escape_string($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;
}
}
mysql_select_db($database_shop, $shop);
$query_menu_list = "SELECT * FROM subjets";
$menu_list = mysql_query($query_menu_list, $shop) or die(mysql_error());
$row_menu_list = mysql_fetch_assoc($menu_list);
$totalRows_menu_list = mysql_num_rows($menu_list);
mysql_select_db($database_shop, $shop);
$query_pages = "SELECT * FROM pages WHERE id_subject = id";
$pages = mysql_query($query_pages, $shop) or die(mysql_error());
$row_pages = mysql_fetch_assoc($pages);
$totalRows_pages = mysql_num_rows($pages);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>menu_list</title>
</head>
<body>
<?php while ($row_menu_list = mysql_fetch_assoc($menu_list)){
echo "<li>{$row_menu_list['subget_name']}</li>" ;
while ($row_pages = mysql_fetch_assoc($pages)){
echo "<li>{$row_pages['page_name']}</li>";}
} ?>
</body>
</html>
<?php
mysql_free_result($menu_list);
mysql_free_result($pages);
?>
The query gives this result:
* informatica
* Dove Siamo
* Lorem
* web templates in vendita
* assistenza
* shop
* contatti