SitePoint Sponsor |
|
User Tag List
Results 1 to 8 of 8
Thread: Display issues!
-
Sep 8, 2009, 13:25 #1
Display issues!
Guys I am facing a display problem which I know it will be resolved with a If else statement or some condition of that kind.
I want that if user x click one of the submenus of the first query at or first display then user x will be able to see only first display layout below the while loop and if user x click in the subjects second display then user x will be able to see only the layout in the second display and not both how it is displaying now. as I said before right now the way it is working is that if user x click on one of the submenu in the first display then the layout of the first display appear and the layout of the second display as well and I only want it to show the one the user required first layout or second layout depending where the user clicked in other word "one at the time".Right now when user x click on the subjects 'second display layout' or Subjects menu then the layout of the second display appear this time not both together I guess becuase after the second query there is not more coding.
Can you help me to display one at the time e.g if user x clicked on the subject menu then only the layout of subject menu will appear or if user x clicked on the submenu menu then only the layout of the submenu menu will appear.
help please.
PHP Code:<?php
$submenu = false;
$cat = isset($_GET['subject']) && is_numeric($_GET['subject'])?$_GET['subject']:null;
$prod = isset($_GET['menu']) && is_numeric($_GET['menu'])?$_GET['menu']:null;
$menu_type = isset($_GET['menu_type']) && is_string($_GET['menu_type'])?$_GET['menu_type']:null
?>
//First Display
<?php
$query = "SELECT id, submenus, image,
FROM submenu
WHERE
id= " . (int) $_GET['menu'];
echo $query;
$result = mysql_query($query, $connection);
while ($content = mysql_fetch_array($result)) {
echo '<table border="0" cellspacing="0" cellpadding="0">
<td>Something</td></table>';
}
?>
// second display
<?php
$query2 = "SELECT id, Subject, image,
FROM subjects
WHERE
id= " . (int) $_GET['subject'];
echo $query2;
$result2 = mysql_query($query2, $connection);
{
echo '<table border="0" cellspacing="0" cellpadding="0" >
<td></td>
</table>';
}
?>
-
Sep 8, 2009, 13:32 #2
- Join Date
- Oct 2006
- Location
- France, deep rural.
- Posts
- 6,869
- Mentioned
- 17 Post(s)
- Tagged
- 1 Thread(s)
It still amazes me when I hear a simple logic question, yet the code which seems to be 90% crappy old html which we are supposed to willingly wade through.
If you were able to distill this down to a simple example you could expand it back into your own script when you get an answer?
That question needs some careful thought too, I am not going to read it.
-
Sep 8, 2009, 13:41 #3
Sorry For the mess i did before now it's more readable...
-
Sep 8, 2009, 14:30 #4
- Join Date
- Oct 2006
- Location
- France, deep rural.
- Posts
- 6,869
- Mentioned
- 17 Post(s)
- Tagged
- 1 Thread(s)
Thanks for responding, I have re-read your question, and still don't get it though.
Is this what you mean, build a query and make it conditional on whether menu or subject is set?
PHP Code:<?php
$submenu = false;
// decide which is the correct query
if( isset($_GET['menu']) ){
$query = "SELECT id, submenus, image,
FROM submenu
WHERE
id= " . (int) $_GET['menu'];
}elseif( isset( $_GET['subject']) ) {
$query = "SELECT id, Subject, image,
FROM subjects
WHERE
id= " . (int) $_GET['subject'];
}else{
// if neither is set, do what?
}
// take a look at which was chosen
echo $query ;
// then deal with the query and display the table
$result = mysql_query($query, $connection);
{
echo '<table border="0" cellspacing="0" cellpadding="0" >
<td></td>
</table>';
}
?>
If each table is different then you'll have to move some or all of the table creation into the if() clauses.
-
Sep 8, 2009, 16:02 #5
yes there are two queries as seen above and both tables have different layouts.
the code that links to one or the other goes as below
PHP Code:<?php
$sql = 'SELECT id,Subject FROM subjects;';
$result = mysql_query($sql);
if($result && mysql_num_rows($result)!=0) {
echo '<ul class="nav-categories">';
while($row = mysql_fetch_assoc($result)) {
$uri = 'example.php?subject='.urlencode($row['id']);
$class = !is_null($cat) && $cat==$row['id']?' class="selected"':'';
echo "\t",'<li',$class,'><a href="',$uri,'">',$row['Subject'],'</a>';
if($submenu == false && !is_null($cat) && $cat == $row['id']) {
$sql2 = 'SELECT id,shoename FROM subemenumenu WHERE menusubject_id = '.mysql_real_escape_string($cat).';';
$result2 = mysql_query($sql2);
if($result2 && mysql_num_rows($result2)!=0) {
echo "\n\t\t",'<ul class="submenu">',"\n";
while($row2 = mysql_fetch_assoc($result2)) {
$uri2 = $uri2.'&menu='.urlencode($row2['id']);
$class2 = !is_null($prod) && $prod==$row2['id']?' class="selected"':'';
echo "\t\t\t",'<li',$class2,'><a href="',$uri2,'">',$row2['shoename'].'</a></li>',"\n";
}
echo "\t\t",'</ul> <!-- end of ul.submenu -->',"\n";
}
$submenu = true;
}
echo '</li>',"\n";
}
echo '</ul> <!-- end of ul#nav-categories -->',"\n";
}
?>
the whole code together would go like this
PHP Code:<?php
$submenu = false;
$cat = isset($_GET['subject']) && is_numeric($_GET['subject'])?$_GET['subject']:null;
$prod = isset($_GET['menu']) && is_numeric($_GET['menu'])?$_GET['menu']:null;
$menu_type = isset($_GET['menu_type']) && is_string($_GET['menu_type'])?$_GET['menu_type']:null
?>
<?php
$sql = 'SELECT id,Subject FROM subjects;';
$result = mysql_query($sql);
if($result && mysql_num_rows($result)!=0) {
echo '<ul class="nav-categories">';
while($row = mysql_fetch_assoc($result)) {
$uri = 'example.php?subject='.urlencode($row['id']);
$class = !is_null($cat) && $cat==$row['id']?' class="selected"':'';
echo "\t",'<li',$class,'><a href="',$uri,'">',$row['Subject'],'</a>';
if($submenu == false && !is_null($cat) && $cat == $row['id']) {
$sql2 = 'SELECT id,shoename FROM subemenumenu WHERE menusubject_id = '.mysql_real_escape_string($cat).';';
$result2 = mysql_query($sql2);
if($result2 && mysql_num_rows($result2)!=0) {
echo "\n\t\t",'<ul class="submenu">',"\n";
while($row2 = mysql_fetch_assoc($result2)) {
$uri2 = $uri2.'&menu='.urlencode($row2['id']);
$class2 = !is_null($prod) && $prod==$row2['id']?' class="selected"':'';
echo "\t\t\t",'<li',$class2,'><a href="',$uri2,'">',$row2['shoename'].'</a></li>',"\n";
}
echo "\t\t",'</ul> <!-- end of ul.submenu -->',"\n";
}
$submenu = true;
}
echo '</li>',"\n";
}
echo '</ul> <!-- end of ul#nav-categories -->',"\n";
}
?>
//First Display
<?php
$query = "SELECT id, submenus, image,
FROM submenu
WHERE
id= " . (int) $_GET['menu'];
echo $query;
$result = mysql_query($query, $connection);
while ($content = mysql_fetch_array($result)) {
echo '<table border="0" cellspacing="0" cellpadding="0">
<td>Something</td></table>';
}
?>
// second display
<?php
$query2 = "SELECT id, Subject, image,
FROM subjects
WHERE
id= " . (int) $_GET['subject'];
echo $query2;
$result2 = mysql_query($query2, $connection);
{
echo '<table border="0" cellspacing="0" cellpadding="0" >
<td></td>
</table>';
}
?>
I will test your variations let me see.
-
Sep 8, 2009, 16:13 #6
Thank you Cups..
I understand what you did it's good if both queries would have the same table I guess, but in this case both queries has different tables and layouts.
you mentioned
If each table is different then you'll have to move some or all of the table creation into the if() clauses.
again the code below is what links the user to what he wants to see the SubjectsPHP Code:$uri = 'example.php?subject='.urlencode($row['id']);
PHP Code:$uri2 = $uri2.'&menu='.urlencode($row2['id']);
PHP Code:. (int) $_GET['subject'];
PHP Code:. (int) $_GET['menu'];
PHP Code:<?php
$sql = 'SELECT id,Subject FROM subjects;';
$result = mysql_query($sql);
if($result && mysql_num_rows($result)!=0) {
echo '<ul class="nav-categories">';
while($row = mysql_fetch_assoc($result)) {
$uri = 'example.php?subject='.urlencode($row['id']);
$class = !is_null($cat) && $cat==$row['id']?' class="selected"':'';
echo "\t",'<li',$class,'><a href="',$uri,'">',$row['Subject'],'</a>';
if($submenu == false && !is_null($cat) && $cat == $row['id']) {
$sql2 = 'SELECT id,shoename FROM subemenumenu WHERE menusubject_id = '.mysql_real_escape_string($cat).';';
$result2 = mysql_query($sql2);
if($result2 && mysql_num_rows($result2)!=0) {
echo "\n\t\t",'<ul class="submenu">',"\n";
while($row2 = mysql_fetch_assoc($result2)) {
$uri2 = $uri2.'&menu='.urlencode($row2['id']);
$class2 = !is_null($prod) && $prod==$row2['id']?' class="selected"':'';
echo "\t\t\t",'<li',$class2,'><a href="',$uri2,'">',$row2['shoename'].'</a></li>',"\n";
}
echo "\t\t",'</ul> <!-- end of ul.submenu -->',"\n";
}
$submenu = true;
}
echo '</li>',"\n";
}
echo '</ul> <!-- end of ul#nav-categories -->',"\n";
}
?>
-
Sep 9, 2009, 13:36 #7
I have been trying to place the tables inside the if() parentheses but has work so far...
-
Sep 9, 2009, 17:44 #8
cups This is what I was looking for
PHP Code:<?php
$submenu = false;
$cat = isset($_GET['subject']) && is_numeric($_GET['subject'])?$_GET['subject']:null;
$prod = isset($_GET['menu']) && is_numeric($_GET['menu'])?$_GET['menu']:null;
$menu_type = isset($_GET['menu_type']) && is_string($_GET['menu_type'])?$_GET['menu_type']:null
if ($prod){
$query = "SELECT id, submenus, image,
FROM submenu
WHERE
id= " . (int) $_GET['menu'];
echo $query ;
$result = mysql_query($query, $connection);
{
echo '<table border="0" cellspacing="0" cellpadding="0" >
<td>different</td><td>different</td>
</table>';
}
elseif( $cat) {
$query = "SELECT id, Subject, image,
FROM subjects
WHERE
id= " . (int) $_GET['subject'];
echo $query ;
$result = mysql_query($query, $connection);
{
echo '<table border="0" cellspacing="0" cellpadding="0" >
<td></td>
</table>';
}
?>
Check it out I didn't express it well at the beginning.
Now if ($prod) is set then table x will appear or if ($cat) is set then table x will appear...
Bookmarks