how to show more than the last record in 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

how to show more than the last record in php

Post by c.stivanson »

I'm using the print statement in php and trying to show all the information in my database after using a while loop to show all the info. I want to show the info by the month in a certain div tag. when i print all it shows is the last record entered. I need it to show all the records for that month in the correct div? any help?
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: how to show more than the last record in php

Post by AbraCadaver »

Any code?
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
c.stivanson
Forum Newbie
Posts: 5
Joined: Mon Dec 06, 2010 9:30 am

Re: how to show more than the last record in php

Post by c.stivanson »

i want it to grab the info from the database and place it in the <div id="January"> feb, march, ect... tags according to what month the person selected in the form but all it is showing is the last posted, which is right i guess. I just dont know how to make it grab it all and put it where it is supposed to go!

Thanks,

Code: Select all

	<?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
				"<a href=\"Chaps-events-details.php?chosenID=$newID\">$newtitle</a>";
?>
		</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 
	
if ($newmonth=="January ") echo "$row $newmonth $newday $newyear $newtitle $newtype $newdesc $newtime"; 

?>
    </div>
</div>
</div><br />
Post Reply