Problem with mysql + PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
c.stivanson
Forum Newbie
Posts: 5
Joined: Mon Dec 06, 2010 9:30 am

Problem with mysql + PHP

Post by c.stivanson »

Hello, I am trying to get a variable from a form that posts to a mysql database to sort and post onto a page called events.php into a certain div tag depending on the month the chose when filling out the form? any help? its like they choose a month it posts to a database then displays in a div tag name January, or February... ect... depending on what month they chose..

Code: Select all



<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>

<script>
$(document).ready(function() {
	//Code goes here
	//Set default open/close settings
$('.acc_container').hide(); //Hide/close all containers
$('.acc_trigger:first').addClass('active').next().show(); //Add "active" class to first trigger, then show/open the immediate next container

//On Click
$('.acc_trigger').click(function(){
	if( $(this).next().is(':hidden') ) { //If immediate next container is closed...
		$('.acc_trigger').removeClass('active').next().slideUp(); //Remove all "active" state and slide up the immediate next container
		$(this).toggleClass('active').next().slideDown(); //Add "active" state to clicked trigger and slide down the immediate next container
	}
	return false; //Prevent the browser jump to the link anchor
});

	
	
});
</script>

</head>
<body>
<div id="wrapper">
	<div id="header">
	</div><!--closes the header tag-->
		<div id="sidebar">
		</div><!--closes the sidebar tag-->
				<div id="navigation">
                       <div id="navbox">
			<div id="nav"><a href = "../index.html">Home</a></div>
			<div id="nav"><a href = "Chaps-programs.html">Programs</a></div>
			<div id="nav"><a href = "Chaps-events.php">Events</a></div>
			<div id="nav"><a href = "Chaps-relatedlinks.html">Related Links</a></div>
			<div id="nav"><a href = "chaps-howtohelp.html">How To Help</a></div>
            <div id="nav"><a href = "chaps-contact.html">Contact Us</a></div>
            </div><!-- closes the navbox div-->
				</div><!--closes the navigation tag-->
					<div id="content">
                    <div class = "drop">
                    <h2>Calendar of Events</h2>
                    <a href = "#">Drop In Center</a><br />
                    <a href = "#">Journey Center</a><br />
                    <a href = "#">(Upload Files)</a>
                    </div><!--closes the drop tag-->
                    
                    <div class = "events">
                    <h2>Events</h2>
                    <a href = "#">Event Title</a><br/>
                    <a href = "#">Date (Start Date/End Date)</a><br/>
                    <a href = "#">Description</a><br/>
                    </div><!--closes the events tag-->
                    
                    <div class = "didyou">
                    <h2>Did You Know</h2>
                    <a href = "#">Description</a><br/>
                    </div><!--closes the events tag-->
					
						<div id="content3">
                        
                        <div class="para2">
                        
<h1>Chaps Events</h1>

	<?php
	//if the user has chosen a columns to sort by...
	if (isset($_GET['sortcol'])){
	//recieve the column nmae the user chose to sort by, and store it in a variable
	$chosencol=$_GET['sortcol'];
	}else{
	//otherwise order by a default column...
	$chosenID="eventID";
	}
	//make a connection to the server...connect("servername", "username", "password")
	$link=mysql_connect("localhost","root", "");
	//connect to our database...
	$db= mysql_select_db("events");
	//construct a sql query...
	$query="select * from eventstable ORDER by month";
	//run the query...
	$result=mysql_query($query);
	//for each row returned by our query do what is in {}
	
?>
	
<br />
<br />
<br />

       

<!------------------------- shows the months------------------------->
     <h2>Click on Month to See Events</h2>

<div id="january">
<h2 class="acc_trigger"><a href="#">January</a></h2>
<div class="acc_container">
    <div class="block">
	
This is where i want the post to display if the month chose was january
    </div>
</div>
</div><br />



Thanks for the help
c.stivanson
Forum Newbie
Posts: 5
Joined: Mon Dec 06, 2010 9:30 am

Re: Problem with mysql + PHP

Post by c.stivanson »

I accidentally left out the display code here is the updated code

Thanks,

Code: Select all

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>

<script>
$(document).ready(function() {
	//Code goes here
	//Set default open/close settings
$('.acc_container').hide(); //Hide/close all containers
$('.acc_trigger:first').addClass('active').next().show(); //Add "active" class to first trigger, then show/open the immediate next container

//On Click
$('.acc_trigger').click(function(){
	if( $(this).next().is(':hidden') ) { //If immediate next container is closed...
		$('.acc_trigger').removeClass('active').next().slideUp(); //Remove all "active" state and slide up the immediate next container
		$(this).toggleClass('active').next().slideDown(); //Add "active" state to clicked trigger and slide down the immediate next container
	}
	return false; //Prevent the browser jump to the link anchor
});

	
	
});
</script>

</head>
<body>
<div id="wrapper">
	<div id="header">
	</div><!--closes the header tag-->
		<div id="sidebar">
		</div><!--closes the sidebar tag-->
				<div id="navigation">
                       <div id="navbox">
			<div id="nav"><a href = "../index.html">Home</a></div>
			<div id="nav"><a href = "Chaps-programs.html">Programs</a></div>
			<div id="nav"><a href = "Chaps-events.php">Events</a></div>
			<div id="nav"><a href = "Chaps-relatedlinks.html">Related Links</a></div>
			<div id="nav"><a href = "chaps-howtohelp.html">How To Help</a></div>
            <div id="nav"><a href = "chaps-contact.html">Contact Us</a></div>
            </div><!-- closes the navbox div-->
				</div><!--closes the navigation tag-->
					<div id="content">
                    <div class = "drop">
                    <h2>Calendar of Events</h2>
                    <a href = "#">Drop In Center</a><br />
                    <a href = "#">Journey Center</a><br />
                    <a href = "#">(Upload Files)</a>
                    </div><!--closes the drop tag-->
                    
                    <div class = "events">
                    <h2>Events</h2>
                    <a href = "#">Event Title</a><br/>
                    <a href = "#">Date (Start Date/End Date)</a><br/>
                    <a href = "#">Description</a><br/>
                    </div><!--closes the events tag-->
                    
                    <div class = "didyou">
                    <h2>Did You Know</h2>
                    <a href = "#">Description</a><br/>
                    </div><!--closes the events tag-->
					
						<div id="content3">
                        
                        <div class="para2">
                        
<h1>Chaps Events</h1>

	<?php
	//if the user has chosen a columns to sort by...
	if (isset($_GET['sortcol'])){
	//recieve the column nmae the user chose to sort by, and store it in a variable
	$chosencol=$_GET['sortcol'];
	}else{
	//otherwise order by a default column...
	$chosenID="eventID";
	}
	//make a connection to the server...connect("servername", "username", "password")
	$link=mysql_connect("localhost","root", "");
	//connect to our database...
	$db= mysql_select_db("events");
	//construct a sql query...
	$query="select * from eventstable ORDER by month";
	//run the query...
	$result=mysql_query($query);
	//for each row returned by our query do what is in {}
	
	while($row = mysql_fetch_array($result)){
	 //for troubleshooting --comment out later:
	   //print_r($row);
	   	 //store into a variable the ID # for the current row
	  $newID=$row['eventID'];
	 //store into a variable the ID # for the current row
	  $newtype=$row['eventtype'];
	  //store into a variable the ID # for the current row
	  $newtitle=$row['eventtitle'];
	  //store into a variable the ID # for the current row
	  $newmonth=$row['month'];
	  //store into a variable the ID # for the current row
	  $newday=$row['day'];
	  //store into a variable the ID # for the current row
	  $newyear=$row['year'];
	  //store into a variable the ID # for the current row
	  $newtime=$row['time'];
	  //store into a variable the ID # for the current row
	  $newdesc=$row['eventdesc'];
	  //store into a variable the ID # for the current row
	  $delete="Delete";
	 

  	
	 
	 //display the row data...
?>
<br />
<br />
<br />

<?php

?>
        <div class="type">
     	<span class="subheader"> Type </span>

<?php 
		//prints the type
	  		 print 
	   		"$newtype";
?>
		</div><!--closes the type div-->
        <div class="title">
        <span class="subheader">Title </span>

<?php
		//prints the product ID number
	   		print
				"$newtitle";
?>
		</div><!--closes the title tag-->
        <div id="date">
       <span class="subheader"> Date </span>
       
<?php
		//prints the name of the product and makes it so the user can click it to continue to the viewdetails page
			print
				"$newmonth" . " "; 
			print
				"$newday" . ", ";
			print
				"$newyear";
?>
      </div><!--closes the date tag-->
      <div id="time">
      <span class="subheader"> Time </span>
      
<?php	
		//prints the price of the product
			print		
				"$newtime";
?>
	</div><!--closes the time tag-->
    <div id="desc">
      <span class="subheader">Description</span>
      
<?php	
		//prints the price of the product
			print		
				"$newdesc";
?>
		</div><!--closes the desc tag-->
		<div class="delete">
<?php
            //this prints a variable that will allow the user to delete an item if they are an administrator
			print  "<a href=\"deleteprocess.php?chosenID=$newID\">$delete</a>";
?>
</div><!--closes the delete tag-->
<?php
			}
?>
	
<br />
<br />
<br />

       

<!------------------------- shows the months------------------------->
     <h2>Click on Month to See Events</h2>

<div id="january">
<h2 class="acc_trigger"><a href="#">January</a></h2>
<div class="acc_container">
    <div class="block">
	
<?php 
print $newtime;
print $newdesc;

?>
    </div>
</div>
c.stivanson
Forum Newbie
Posts: 5
Joined: Mon Dec 06, 2010 9:30 am

Re: Problem with mysql + PHP

Post by c.stivanson »

ok i think i may be getting closer i can get the right information to show up where i want it to but i need to make it so it will print all the january records in the january tag instead of just the last record from the database any ideas?
Post Reply