Page 1 of 1

wrap ya head around this one

Posted: Wed Nov 05, 2003 9:08 am
by diamondazza
here is the code:

Code: Select all

<?php

//Display all entries
function display_all(){
$result = mysql_query("SELECT * FROM guide");
while($r=mysql_fetch_array($result))

{    
    $id=$r["id"];
	$venue=$r["venue"];
    $band=$r["band"];
      $day=$r["day"];
    echo "::<b>$venue</b><br> <b>$band</b><br><b>$day</b><br>";
}
}

//end display all function


//thursday
function Thurs(){
global $PHP_SELF;
	$result = mysql_query("SELECT * FROM `guide` WHERE day = 'Thursday' ORDER BY `id`");
	while($r=mysql_fetch_array($result))
	{    
         $day=$r["day"];
		 $band=$r["band"];
    echo "$day $band<br>";
}
	echo "<br><a href='javascript:history.go(-1)'>[Go Back]</a><br><br>";
	}
//end

//friday
function Fri(){
global $PHP_SELF;
	$result = mysql_query("SELECT * FROM `guide` WHERE day = 'Friday' ORDER BY `id`");
	while($r=mysql_fetch_array($result))
	{    
         $day=$r["day"];
		 $band=$r["band"];
    echo "$day $band<br>";
}
	echo "<br><a href='javascript:history.go(-1)'>[Go Back]</a><br><br>";
	}
//end

//saturday
function Sat(){
global $PHP_SELF;
	$result = mysql_query("SELECT * FROM `guide` WHERE day = 'Saturday' ORDER BY `id`");
	while($r=mysql_fetch_array($result))
	{    
         $day=$r["day"];
		 $band=$r["band"];
    echo "$day $band<br>";
}
	echo "<br><a href='javascript:history.go(-1)'>[Go Back]</a><br><br>";
	}
//end

//sunday
function Sun(){
global $PHP_SELF;
	$result = mysql_query("SELECT * FROM `guide` WHERE day = 'Sunday' ORDER BY `id`");
	while($r=mysql_fetch_array($result))
	{    
         $day=$r["day"];
		 $band=$r["band"];
    echo "$day $band<br>";
}
	echo "<br><a href='javascript:history.go(-1)'>[Go Back]</a><br><br>";
	}
//end

//monday
function Mon(){
global $PHP_SELF;
	$result = mysql_query("SELECT * FROM `guide` WHERE day = 'Monday' ORDER BY `id`");
	while($r=mysql_fetch_array($result))
	{    
         $day=$r["day"];
		 $band=$r["band"];
    echo "$day $band<br>";
}
	echo "<br><a href='javascript:history.go(-1)'>[Go Back]</a><br><br>";
	}
//end

//tuesday
function Tue(){
global $PHP_SELF;
	$result = mysql_query("SELECT * FROM `guide` WHERE day = 'Tuesday' ORDER BY `id`");
	while($r=mysql_fetch_array($result))
	{    
         $day=$r["day"];
		 $band=$r["band"];
    echo "$day $band<br>";
}
	echo "<br><a href='javascript:history.go(-1)'>[Go Back]</a><br><br>";
	}
//end

//wednesday
function Wed(){
global $PHP_SELF;
	$result = mysql_query("SELECT * FROM `guide` WHERE day = 'Wednesday' ORDER BY `id`");
	while($r=mysql_fetch_array($result))
	{    
         $day=$r["day"];
		 $band=$r["band"];
    echo "$day $band<br>";
}
	echo "<br><a href='javascript:history.go(-1)'>[Go Back]</a><br><br>";
	}
//end


?>
<Div align="center">
<form method="post">
<input type="hidden" action="<? echo $PHP_SELF; ?>" name="func" value="Thurs"> 
<input type="submit" value="Thurs">
<input type="hidden" action="<? echo $PHP_SELF; ?>" name="func" value="Fri"> 
<input type="submit" value="Fri">
<input type="hidden" action="<? echo $PHP_SELF; ?>" name="func" value="Sat"> 
<input type="submit" value="Sat">
<input type="hidden" action="<? echo $PHP_SELF; ?>" name="func" value="Sun"> 
<input type="submit" value="Sun">
<input type="hidden" action="<? echo $PHP_SELF; ?>" name="func" value="Mon"> 
<input type="submit" value="Mon">
<input type="hidden" action="<? echo $PHP_SELF; ?>" name="func" value="Tue"> 
<input type="submit" value="Tue">
<input type="hidden" action="<? echo $PHP_SELF; ?>" name="func" value="Wed"> 
<input type="submit" value="Wed">
</form>

</Div>
<?
switch($_SERVER['PHP_SELF'] = $func) {
	default;
	display_all();
	break;

	case "Thurs";
	Thurs();
	break;
	
	case "Fri";
	Fri();
	break;
	
	case "Sat";
	Sat();
	break;
	
	case "Sun";
	Sun();
	break;
	
	case "Mon";
	Mon();
	break;
	
	case "Tue";
	Tue();
	break;
	
	case "Wed";
	Wed();
	break;
}
?>
heres the prob:
the code above is a module in a small portal system ive had some of it working but it just defualts to the wed(); function. if you can understand what im trying to do please help me sort this crap out, yes im a newbie, is there an easier way?
what i basically want is a bunch of links like this:
thurs||fri||sat||sun|| etc etc ..
for the days of the week, and when one of the days are "click" it selects days from the database of whatever day was selected..all in one script!!
i no its a mess its my first real script.

Posted: Wed Nov 05, 2003 10:57 am
by JAM
Multible <input type="hidden">-fields.
Hidden input's doesn't work as radio ones (as example).

The last hidden input field, will be the one sending the information. In your case, Wed. Recently discussed this in viewtopic.php?t=14286

Hope it helps some.

Btw, forgot to meantion something that might be easier. Mileage may vary...

Each function is similiar except for the where-clause, being the day.
Why not make the swith populate a $variable, then use that $variable in the function instead?

Pseudo code example:

Code: Select all

switch ($_POST['something']) {
 case 'Wed':
  run_function('Wednesday');
  break;
 case 'Sun':
  run_function('Sunday');
  break;
  // etc. etc.
}
function run_function($day) {
 $query = "select * from table where day = '$day'";
 // etc. etc.
}
Hope it was understandable enough. By doing this, you only need to maintain one function if you decide to add/remove/change something, instead of in 7 places...

Posted: Wed Nov 05, 2003 11:49 am
by Weirdan
You can even try:

Code: Select all

$mapping=array(
'Wed'=>'Wednesday',
'Sun'=>'Sunday',
//...and so on.
);
run_function(isset($mapping[$_POST['something']])?$mapping[$_POST['something']]:'Sun');
Ternary conditional is used to provide default value.