Jump to content

Looping List Problem First, Then Php Switch Writing


jcc5018
 Share

Recommended Posts

hey guys, I am experimenting with a possible new idea for a gallery using php and CSS, since I cant figure out how to program in action script. Currently I am pulling data from a database with php and formating it into a list that I hope I may be able to convert into what I need later. It almost works except for the fact that once it goes through one project type, I can't figure out how to make it go back and do the same sequence but with the next project type. Every for or while loop i try just repeats the sequence using the same project type again opposed to the next one in the list. The page that displays it working with only my first project type "Residential" http://jonsonlineportfolio.site40.net/Projects.php It should be looping through about 8 other typesThe XML format that gives the general idea of how each project should be arranged is as follows

<gallery>	<Project_type>	<type></type>	<caption></caption>	<project>			<title></title>			<Type></Type>			<Size></Size>			<Features></Features>			<Year ></Year >			<Program></Program>			<Skills></Skills>			<Work></Work>			<comment></comment>			<Picture>				<location></location>				<pTitle></pTitle>				<pCaption></pCaption>			</Picture>		</project>

I am basically trying to do that same thing except I want it in an unordered list format. but for whatever reason, it only goes through once, opposed to giving the information for every Project Type.Here is my PHP

echo "<ul>";$query='Select *FROM project_typeORDER BY project_type.ID';$results = mysql_query($query);while($row= mysql_fetch_array($results)){ echo "<li><h1>".$row['type']. "</h1><p>".$row['caption']."</p>";$id = $row['t_shortcut'];echo "<ul>";$query="Select *FROM projectWHERE typeID= '$id'";$results2 = mysql_query($query);while($row= mysql_fetch_array($results2)){	echo "<li>".$row['title']."<ul class='info'>";echo "<li>".$row['project_Type']."</li>";		echo "<li>".$row['yrDesigned']."</li>";	echo "<li>".$row['program_used']."</li>"; 	echo "<li>".$row['size']."</li>";	echo "<li>".$row['features']."</li>";	echo "<li>".$row['skills_learned']."</li>";		echo "<li>".$row['work_left']."</li>" ;		echo "<li class='comment'>".$row['comment']."</li>" ;	echo "<li><ul class='pics'>";$id= $row['ID'];	$query="Select *FROM pictureWHERE projNumber= '$id'";$results = mysql_query($query);while($row= mysql_fetch_array($results)){ echo "<li><h3>".$row['title']."</h3>";	echo "<p>".$row['caption'] ."</p></br>";	echo "<img src='/projects/Gallery/".$row['location']."'/></li>";}echo "</ul></li></ul></li>";	}echo "</ul></li>";	} echo "</ul>";		?>

Once I get this working, I'll have another question. I am going to want to divide this list up into a couple different parts that includes a navigation menu, a series of thumbnails and various pieces of information that goes in a lot of different places. I dont think its possible for me to have content change depending on a button pressed using just php. I dont really know java script, so if anyone knows code that can handle that, that can also be explained so i understand what it is doing, that would be great. Another option I thought of was having the above code write the different sections into another file or two that would be formatted into a switch statement. The question then being, how do I accomplish that task. to clarify:the Project type selections are going to become main level navigation, while the Project Titles will become sub level navigation.Instead of writing a new nested list, The next section will insert the data into a formated switch statement on another sheet.This sheet will consist of the project Details and the block for the thumbnails which will be its own switch file the links the thumbs with its respective picture and caption.Exp : Residential -- House 1 --> passes variable "1" which triggers the switch to display the project details associated with house 1 and also the thumbnails which will be another set of links essentially. These links also pass a variable to another switch to pull up the its larger picture. I think that should do what I want it to do, I just need to figure out first why my code isn't looping to the other project types, and then I need to figure out how to make it automatically write to another file to form the switch. Thanks for any help

Link to comment
Share on other sites

You keep using the same variable names, inside your loop you overwrite $results to point to some other result set, so when it goes back to the top of the loop and tries to get the next project type the $results set is already at the end (because you overwrote it with a different result). Use different variable names, ideally instead of generic names like $row and $results and $results2 you would name them what they actually are.I'm not sure what you're talking about with the switch statement, a switch statement is a conditional statement like an if statement, it's a control structure. You don't insert data into it, I'm not sure what you're asking.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...