Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 132,628 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,048 people online right now. Registration is fast and FREE... Join Now!




if statements

 
Closed TopicStart new topic

if statements

iamcenz
post 8 Jun, 2005 - 08:27 AM
Post #1


You wish you were my hand!

Group Icon
Joined: 26 Mar, 2001
Posts: 2,385



Dream Kudos: 201
My Contributions


ok, i know how to use the basic if statements, but this is what im trying to so i wanna know if its possible, i got this site, im trying to make it never leave index.php by making ALL content dynamic, so right now i got its like index.php?cat=3&page=1 i have the different menus for each category. can i use a if statement to show the different menus? the idea i got is i can do something like this. if cat=3 then echo "code for table here"; would it even be possible? cause this way looks to be sloppy. maybe righting functions, but ive never done that.
User is offlineProfile CardPM

Go to the top of the page

skyhawk133
post 8 Jun, 2005 - 09:06 AM
Post #2


Head DIC Head

Group Icon
Joined: 17 Mar, 2001
Posts: 14,846



Thanked 45 times

Dream Kudos: 1650

Expert In: Web Development

My Contributions


I would suggest using includes rather than echoing, this will be more organized in the long run. And I would use a switch statement rather than an if for this situation:

CODE

<?
switch ($cat) {
case 0:
  include("cat0_menu.php");
  break;
case 1:
  include("cat1_menu.php");
  break;
case 2:
  include("cat2_menu.php");
  break;
}
?>
User is offlineProfile CardPM

Go to the top of the page

iamcenz
post 8 Jun, 2005 - 10:51 AM
Post #3


You wish you were my hand!

Group Icon
Joined: 26 Mar, 2001
Posts: 2,385



Dream Kudos: 201
My Contributions


ok? so if cat = 1 then i would make that case 1? i dont know very much about the switch function.
User is offlineProfile CardPM

Go to the top of the page

iamcenz
post 8 Jun, 2005 - 11:01 AM
Post #4


You wish you were my hand!

Group Icon
Joined: 26 Mar, 2001
Posts: 2,385



Dream Kudos: 201
My Contributions


i answered my own question. now i ran into a little problem. i have the page load with default values for cat and page. the switch dont load those...
CODE
<?php
$c_a = "1";
if (isset($_GET['cat'])) {
 $c_a = (get_magic_quotes_gpc()) ? $_GET['cat'] : addslashes($_GET['cat']);
}
$p_a = "3";
if (isset($_GET['page'])) {
 $p_a = (get_magic_quotes_gpc()) ? $_GET['page'] : addslashes($_GET['page']);
}
mysql_select_db($database_conn, $conn);
$query_a = sprintf("SELECT * FROM site WHERE catID = %s AND pageID = %s", $c_a,$p_a);
$a = mysql_query($query_a, $conn) or die(mysql_error());
$row_a = mysql_fetch_assoc($a);
$totalRows_a = mysql_num_rows($a);
?>


the c_a="1"; and the p_a="3"; those are the defaults. if i type them into the address it works fine. how can i make so it loads right. take a look.

http://www.ask4tech.net/ask.php this loads the default. the content will load, but no navigation on left

http://www.ask4tech.net/ask.php?cat=1&page=3 this will load everything.
User is offlineProfile CardPM

Go to the top of the page

snoj
post 8 Jun, 2005 - 11:24 AM
Post #5


$Null

Group Icon
Joined: 31 Mar, 2003
Posts: 3,304



Thanked 5 times

Dream Kudos: 700
My Contributions


The only thing I can think of is that you are exiting before the nav menu code can execute.
User is offlineProfile CardPM

Go to the top of the page

iamcenz
post 8 Jun, 2005 - 11:33 AM
Post #6


You wish you were my hand!

Group Icon
Joined: 26 Mar, 2001
Posts: 2,385



Dream Kudos: 201
My Contributions


???

here is the code i got so far.
CODE

<?php require_once('Connections/conn.php'); ?>
<?php
$c_a = "1";
if (isset($_GET['cat'])) {
   $c_a = (get_magic_quotes_gpc()) ? $_GET['cat'] : addslashes($_GET['cat']);
}
$p_a = "3";
if (isset($_GET['page'])) {
   $p_a = (get_magic_quotes_gpc()) ? $_GET['page'] : addslashes($_GET['page']);
}
mysql_select_db($database_conn, $conn);
$query_a = sprintf("SELECT * FROM site WHERE catID = %s AND pageID = %s", $c_a,$p_a);
$a = mysql_query($query_a, $conn) or die(mysql_error());
$row_a = mysql_fetch_assoc($a);
$totalRows_a = mysql_num_rows($a);
?>
<html>
<head>
<script type="text/javascript" src="milonic_src.js"></script>
<link href="styles.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
body,td,th {
   font-family: Verdana, Arial, Helvetica, sans-serif;
   font-size: 12px;
   color: #000000;
}
-->
</style><div class=milonic><a href="http://www.milonic.com/">JavaScript Menu, DHTML Menu Powered By Milonic</a></div>
<script type="text/javascript">
if(ns4)_d.write("<scr"+"ipt type=text/javascript src=mmenuns4.js><\/scr"+"ipt>");
else _d.write("<scr"+"ipt type=text/javascript src=mmenudom.js><\/scr"+"ipt>");
</script>
<script type="text/javascript" src="menu_data.js"></script>
<title>ASK Technology Solutions :: <?php echo $row_a['title']; ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table id="Table_01" width="100%" height="425" border="0" cellpadding="0" cellspacing="0">
<tr>
<td colspan="15" background="images/bg.jpg">
<img src="images/ask_01.jpg" width="740" height="118" alt=""></td>
</tr>
<tr valign="top" background="images/ask_15.jpg">
<td colspan="14" background="/images/ask_15.jpg">
<p align="right"><img src="images/ask_14.jpg" width="44" height="28"></p>    </td>
<td background="/images/ask_15.jpg"><img src="images/ask_15.jpg" width="13" height="28" align="right"></td>
</tr>
<tr>
<td colspan="7" valign="top"><?
switch ($cat) {
   case 1:
   include("cat1_menu.php");
   break;
   case 2:
   include("cat2_menu.php");
   break;
   case 3:
   include("cat3_menu.php");
   break;
}
?></td>
<td colspan="8" valign="top"><table width="100%"  border="0" cellspacing="0" cellpadding="2">
<tr>
<td><?php echo $row_a['content']; ?></td>
</tr>
</table></td>
</tr>
<tr>
<td>
<img src="images/spacer.gif" width="51" height="1" alt=""></td>
<td>
<img src="images/spacer.gif" width="13" height="1" alt=""></td>
<td>
<img src="images/spacer.gif" width="65" height="1" alt=""></td>
<td>
<img src="images/spacer.gif" width="15" height="1" alt=""></td>
<td>
<img src="images/spacer.gif" width="67" height="1" alt=""></td>
<td>
<img src="images/spacer.gif" width="14" height="1" alt=""></td>
<td>
<img src="images/spacer.gif" width="9" height="1" alt=""></td>
<td>
<img src="images/spacer.gif" width="42" height="1" alt=""></td>
<td>
<img src="images/spacer.gif" width="12" height="1" alt=""></td>
<td>
<img src="images/spacer.gif" width="67" height="1" alt=""></td>
<td>
<img src="images/spacer.gif" width="12" height="1" alt=""></td>
<td>
<img src="images/spacer.gif" width="169" height="1" alt=""></td>
<td>
<img src="images/spacer.gif" width="147" height="1" alt=""></td>
<td>
<img src="images/spacer.gif" width="44" height="1" alt=""></td>
<td>
<img src="images/spacer.gif" width="13" height="1" alt=""></td>
</tr>
</table>
</body>
</html>
<?php
mysql_free_result($a);
?>
User is offlineProfile CardPM

Go to the top of the page

snoj
post 8 Jun, 2005 - 03:43 PM
Post #7


$Null

Group Icon
Joined: 31 Mar, 2003
Posts: 3,304



Thanked 5 times

Dream Kudos: 700
My Contributions


I haven't gone over the code with a fine toothed comb. But I did notice that you never declare $cat (in switch($cat)) anywhere in that file.
User is offlineProfile CardPM

Go to the top of the page

iamcenz
post 8 Jun, 2005 - 04:42 PM
Post #8


You wish you were my hand!

Group Icon
Joined: 26 Mar, 2001
Posts: 2,385



Dream Kudos: 201
My Contributions


its in the URL
User is offlineProfile CardPM

Go to the top of the page

cyberscribe
post 8 Jun, 2005 - 11:29 PM
Post #9


humble.genius

Group Icon
Joined: 5 May, 2002
Posts: 1,062



Thanked 2 times

Dream Kudos: 154
My Contributions


QUOTE(iamcenz @ Jun 8 2005, 12:01 PM)
now i ran into a little problem. i have the page load with default values for cat and page. the switch dont load those...

You can end a swtich statement with the default: case and thereby catch whatever your final, default case is (i.e. anything not handled by the previous cases). Much cleaner than a series of IF statements. Though not as clean as just looking up the ID in your database, or numbering the files to include to correspond with the IDs.
User is offlineProfile CardPM

Go to the top of the page

iamcenz
post 9 Jun, 2005 - 11:14 AM
Post #10


You wish you were my hand!

Group Icon
Joined: 26 Mar, 2001
Posts: 2,385



Dream Kudos: 201
My Contributions


i added a default to the case to load the cat1_menu, now it works perfectly. thanks
User is offlineProfile CardPM

Go to the top of the page

Closed TopicStart new topic
Time is now: 11/23/08 03:44AM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month