if statements

Page 1 of 1

9 Replies - 1749 Views - Last Post: 09 June 2005 - 12:14 PM Rate Topic: -----

#1 iamcenz  Icon User is offline

  • You wish you were my hand!
  • member icon

Reputation: 7
  • View blog
  • Posts: 2,442
  • Joined: 26-March 01

if statements

Posted 08 June 2005 - 09:27 AM

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.

Is This A Good Question/Topic? 0
  • +

Replies To: if statements

#2 skyhawk133  Icon User is offline

  • Head DIC Head
  • member icon

Reputation: 1875
  • View blog
  • Posts: 20,283
  • Joined: 17-March 01

Re: if statements

Posted 08 June 2005 - 10:06 AM

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:

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


Was This Post Helpful? 0
  • +
  • -

#3 iamcenz  Icon User is offline

  • You wish you were my hand!
  • member icon

Reputation: 7
  • View blog
  • Posts: 2,442
  • Joined: 26-March 01

Re: if statements

Posted 08 June 2005 - 11:51 AM

ok? so if cat = 1 then i would make that case 1? i dont know very much about the switch function.
Was This Post Helpful? 0
  • +
  • -

#4 iamcenz  Icon User is offline

  • You wish you were my hand!
  • member icon

Reputation: 7
  • View blog
  • Posts: 2,442
  • Joined: 26-March 01

Re: if statements

Posted 08 June 2005 - 12:01 PM

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...
<?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....hp?cat=1&page=3 this will load everything.
Was This Post Helpful? 0
  • +
  • -

#5 snoj  Icon User is offline

  • Married Life
  • member icon

Reputation: 84
  • View blog
  • Posts: 3,564
  • Joined: 31-March 03

Re: if statements

Posted 08 June 2005 - 12:24 PM

The only thing I can think of is that you are exiting before the nav menu code can execute.
Was This Post Helpful? 0
  • +
  • -

#6 iamcenz  Icon User is offline

  • You wish you were my hand!
  • member icon

Reputation: 7
  • View blog
  • Posts: 2,442
  • Joined: 26-March 01

Re: if statements

Posted 08 June 2005 - 12:33 PM

???

here is the code i got so far.
<?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);
?> 


Was This Post Helpful? 0
  • +
  • -

#7 snoj  Icon User is offline

  • Married Life
  • member icon

Reputation: 84
  • View blog
  • Posts: 3,564
  • Joined: 31-March 03

Re: if statements

Posted 08 June 2005 - 04:43 PM

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.
Was This Post Helpful? 0
  • +
  • -

#8 iamcenz  Icon User is offline

  • You wish you were my hand!
  • member icon

Reputation: 7
  • View blog
  • Posts: 2,442
  • Joined: 26-March 01

Re: if statements

Posted 08 June 2005 - 05:42 PM

its in the URL
Was This Post Helpful? 0
  • +
  • -

#9 cyberscribe  Icon User is offline

  • humble.genius
  • member icon

Reputation: 10
  • View blog
  • Posts: 1,062
  • Joined: 05-May 02

Re: if statements

Posted 09 June 2005 - 12:29 AM

iamcenz, on Jun 8 2005, 12:01 PM, said:

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.
Was This Post Helpful? 0
  • +
  • -

#10 iamcenz  Icon User is offline

  • You wish you were my hand!
  • member icon

Reputation: 7
  • View blog
  • Posts: 2,442
  • Joined: 26-March 01

Re: if statements

Posted 09 June 2005 - 12:14 PM

i added a default to the case to load the cat1_menu, now it works perfectly. thanks
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1