Jump to content

[SOLVED] php not always creating links, random per page refresh


Recommended Posts

The plan to this code is to create a kind of drop down menu depending on the category of the results pulled from SQL.

 

The results would render Distinctively through their numbers. Outputting: 001, 002, 003, etc.

 

Within the while function for them categorys, it'll also do another SQL and pull information from the same table dependant upon the current category it's rendering.

 

This when page renders it'll notice first distinctive category is 000, then within that the second sql will pull all information regarding data in 000, then it'll loop until it finishes.

 

The code generates a number of div's with titles, so when you click them it changes the style of a hidden dive to display:show,

 

everything kinda works great but sometimes when you load the page it doesnt create the <a href link, its like skipping it, and im not sure what could be causing that? Anyone have any idea?

 

The code below:

function showResults() {
global $possible_choice_array, $users_choice_array;

$categorys = mysql_query("SELECT DISTINCT ". MONSTER_DATABASE_MOBCAT ." FROM ". MONSTER_DATABASE ." ORDER BY ". MONSTER_DATABASE_MOBCAT ." ASC"); 
if (!$categorys) { echo("<div id='error'><img src='img/icons/icon_cross.png'>Could not load items from data base: " . mysql_error() . "</div>"); } 

while ($cats = mysql_fetch_array($categorys)) { 
	$category = $cats[MONSTER_DATABASE_MOBCAT];
	if ($category=="000") { $categorytitle="Miscellaneous"; }
	if ($category=="001") { $categorytitle="SKY"; }
	if ($category=="002") { $categorytitle="SEA"; }
	if ($category=="003") { $categorytitle="DYNAMIS"; }
	if ($category=="004") { $categorytitle="EINHERJAR"; }
	if ($category=="005") { $categorytitle="ZNM"; }
	if ($category=="006") { $categorytitle="KSNM"; }
	if ($category=="007") { $categorytitle="OMEGA"; }
	if ($category=="008") { $categorytitle="SALVAGE"; }
	if ($category=="009") { $categorytitle="ASSAULT"; }
	// LOOPS ----------------
		// THIS CODE SOMETIMES GETS SKIPPED UPON LOADING THE PAGE
		echo "<a href='#' onclick='categorylist(\"$category\");return false;'>";
		// ---
		echo "<div id='wishlistcategory'>";
		echo "<strong>$categorytitle</strong>"; 
		echo "</div>";
		echo "</a>";
		echo "<div id='$category' style='display:none;'>";
		// Possible Choices
		$possible_choice_sql = mysql_query("SELECT * FROM ". MONSTER_DATABASE ." WHERE ". MONSTER_DATABASE_MOBCAT ."='$category' ORDER BY ". MONSTER_DATABASE_MOBCAT ." ASC"); 
		if (!$possible_choice_sql) { echo("<div id='error'><img src='img/icons/icon_cross.png'>Could not load items from data base: " . mysql_error() . "</div>"); } 
		// Categorys
		// Print Results
		while ($possiblelist = mysql_fetch_array($possible_choice_sql)) { 
			// ARRAY FROM POSSIBLE CHOICE SQL
			$nmID = $possiblelist[MONSTER_DATABASE_MOBID];
			$possible_choice = $possiblelist[MONSTER_DATABASE_MOBDROP];
			$possible_choice_name = $possiblelist[MONSTER_DATABASE_MOBNAME];
			$possible_choice_area = $possiblelist[MONSTER_DATABASE_MOBZONE];
			$possible_choice_reqi = $possiblelist[MONSTER_DATABASE_MOBREQI];
			$possible_choice_array = explode("|", $possible_choice);
			// Count the number of values in array.
			$possible_choice_array_total = count($possible_choice_array);
			// Adjust Areas so | changes to a comma and a space.
			$items_needed = str_replace("|", ", ", "$possible_choice_reqi");
			// -------------------------------------------------------------------
			// Header of Table
			echo "<div id='wishTable-title'>";
			echo "<a href='#' onclick='wishlist(\"nm$nmID\");return false;'><h2>$possible_choice_name</h2></a>
					<div id='mob-left'><strong>Location: $possible_choice_area</strong></div>
					<div id='mob-middle'><strong>Requirements:</strong> $items_needed</div>
					<div id='mob-right'><strong>Total Drops:</strong> $possible_choice_array_total</div>
					<div style='clear:both;'></div>
					<ul id='nm$nmID' style='display:none;'>
					<div id='wishTable-options'>"; 
			showChoices();
			echo "<div style='clear:both;'></span>";
			echo "</div></ul>";
			echo "</div>";
		}
		echo "</div>";
	// LOOPS ----------------
}	
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.