Jump to content

Recommended Posts

Hi
 
I'm trying to create a page where the menu shows all the job titles and then if you click on a title it displays all the information that has that job title.
 
For Example: In the menu I have puppies and I have kittens. If I click on puppies it has to give me all the information that I have in the database that has the job title "puppies" and if I click on kittens then it gives me all the information for the job title "kittens".
 
Here is my code
 
function putFilterResults(){
		global $_PRODUCTS_IMAGES_DIR, $_PRODUCTS_TABLE;
		$str='';
		$i=2;
				
		$jobSearch='';	
		if(isset($_SERVER['REQUEST_URI'])){
			if(stristr($_SERVER['REQUEST_URI'], '?')){
				$explodeJob = explode('?',$_SERVER['REQUEST_URI']);
				if(trim($explodeJob[1]) != ''){
					$explodeJob[1] = str_replace("-", " ", $explodeJob[1]);
					$jobSearch=strtolower($explodeJob[1]);
				}else{
					$jobSearch='';
				}
			}else{
				$jobSearch='';	
			}
		}
		
		$query = mysql_query("SELECT DISTINCT `job` FROM $_PRODUCTS_TABLE WHERE `active`='1' ORDER BY `job` ASC");
		while($result = mysql_fetch_object($query)){
			$langClass = '';
			$langVar = '';
						
			$colour='';
			if(strtolower($result->{'job'.languageText()}) == $jobSearch){
				$colour = ' style="color:#2BA8C4"';	
			}
				$str.='<a href="#"><li'.$colour.' id="'.$i.'">'.$result->{'job'.languageText()}.'</li></a>';
				$i++;
			}
		
		return $str;
	}

	function putImage(){
        global $_PRODUCTS_IMAGES_DIR, $_PRODUCTS_TABLE;
        
		$explode_img = explode(",", $this->image);
		$numImages=1;
		$numCount=1;
		$wowCount=0;
		$newImgArr = array();
		$newClientArr = array();
		$proinfo='';
		$str ='';
		
		$str.='		<div class="ws_images">';
						$jobSearch='';	
						if(isset($_SERVER['REQUEST_URI'])){
							if(stristr($_SERVER['REQUEST_URI'], '?')){
								$explodeJob = explode('?',$_SERVER['REQUEST_URI']);
								if(trim($explodeJob[1]) != ''){
									$explodeJob[1] = str_replace("-", " ", $explodeJob[1]);
									$jobSearch=' AND LOWER(job) = "'.strtolower($explodeJob[1]).'"';
								}else{
									$jobSearch='';
								}
							}else{
								$jobSearch='';	
							}
						}
						$imageArr='';
						$clientArr='';
						$ff=0;		
						$query = mysql_query("SELECT * FROM $_PRODUCTS_TABLE WHERE `active`='1' AND `image` LIKE '%.%'".$jobSearch." ORDER BY `client` ASC");
						if(mysql_num_rows($query) < 1){
							$query = mysql_query("SELECT * FROM $_PRODUCTS_TABLE WHERE `active`='1' AND `image` LIKE '%.%' ORDER BY `client` ASC");	
						}

						while($result = mysql_fetch_object($query)){
							
							if(stristr($result->image,",")){
								$explode = explode(",", $result->image);
								foreach($explode as $singleImg){
									if($singleImg != ''){
										array_push($newImgArr, $singleImg."!!!".$result->id."!!!".$result->client."!!!".$result->job."!!!".$result->description."!!!".$result->overview);
									}
								}
							}else{
								array_push($newImgArr, $result->image."!!!".$result->id."!!!".$result->client."!!!".$result->job."!!!".$result->description."!!!".$result->overview);
							}
						}
						
						shuffle($newImgArr);
						
						foreach($newImgArr as $newImages){
							if($ff < 100){
								$styleLeft= "style='left:-750px'";
								$activeImg = '';
								$explode2 = explode("!!!",$newImages);
								$pathToFile = 'products_images/'.$explode2[0].'';

								if(file_exists($pathToFile)){
									if($ff == 0){
										$styleLeft= "style='left:0px'";
										$activeImg = ' activeImg';
									}
									$str.= '<div class="ws_div_wrapper'.$activeImg.'" id="ws_div_wrapper_'.$wowCount.'" '.$styleLeft.'>';
										$str.= '<div class="ws_div_wrapper_relative" id="ws_div_wrapper_relative">';
											$str.= '<p name="wowspanName" id="wowspan'.$wowCount.'" style="display:none;">'.$explode2[1].'</p>';
											$str.= '<a style="cursor:pointer;"><img src="'.$_PRODUCTS_IMAGES_DIR.''.$explode2[0].'" id="wows'.$wowCount.'"/></a>';
											$wowCount++;
												
											if($ff==0){
												$proinfo='';
												$proinfo.= '<div class="myWrapper" id="myWrapper">';
													$proinfo.= "<div class='productbox'>";
													if( $explode2[2] != "" ) 
														$proinfo.= "<div class='topborder'>
																<span class='right'><b>".$explode2[2]."</b></span>
															</div>";
													if( $explode2[3] != "" ) 
														$proinfo.= "<div class='topborder1'>
																<span class='right'>".$explode2[3]."</span>
															</div>";
													if( $explode2[4] != "" ) 
														$proinfo.= "<div class='topborder1'>
																<span class='right'>".$explode2[4]."</span>
															</div>";
													if( $explode2[5] != "" ) 
														$proinfo.= "<div class='topborder1'>
																<span class='right'>".$explode2[5]."</span>
															</div>";
													$proinfo.= "</div>";
												$proinfo.= "</div>";
											}
											$ff++;
										$str.= "</div>";
									$str.= "</div>";	
								}
							}
							
							
							
							
							
						}
						

		$str.='			<input type="hidden" name="pVal" id="pVal" value="0">';
		$str.='				<div class="clearboth"></div>';
		$str.='				<p class="next_prev">';
		$str.='				<a class="ws_next"></a>';
		$str.='				<a class="ws_prev"></a>';
		$str.='				</p>';
		$str.='			</div>';

		return $str;
				
				
    }

If there is anything you don't understand please let me know.

 

Link to comment
https://forums.phpfreaks.com/topic/287811-link-that-will-display-all-items/
Share on other sites

Not sure what you're asking but there are some issues I'd like highlight in your code

global $_PRODUCTS_IMAGES_DIR, $_PRODUCTS_TABLE;

Stop right there. Do not use globals. Any function that requires a variable in order to function should be passed as an argument

 

This code even necessary?

		if(isset($_SERVER['REQUEST_URI'])){
			if(stristr($_SERVER['REQUEST_URI'], '?')){
				$explodeJob = explode('?',$_SERVER['REQUEST_URI']);
				if(trim($explodeJob[1]) != ''){
					$explodeJob[1] = str_replace("-", " ", $explodeJob[1]);
					$jobSearch=strtolower($explodeJob[1]);
				}else{
					$jobSearch='';
				}
			}else{
				$jobSearch='';	
			}
		

Why not get the query string parameter you're after from the $_GET superglobal? There is no need to parse the url yourself. 

 

 

Next issue

$query = mysql_query("SELECT DISTINCT `job` FROM $_PRODUCTS_TABLE WHERE `active`='1' ORDER BY `job` ASC");
		while($result = mysql_fetch_object($query)){
			$langClass = '';
			$langVar = '';
						
			$colour='';
			if(strtolower($result->{'job'.languageText()}) == $jobSearch){
				$colour = ' style="color:#2BA8C4"';	
			}
				$str.='<a href="#"><li'.$colour.' id="'.$i.'">'.$result->{'job'.languageText()}.'</li></a>';
				$i++;
			}
		
		return $str;

Why you not use MySQL to filter the results based on $jobSearch, eg

$jobSearch = mysql_real_escape_string($jobSearch);
$query = mysql_query("SELECT `job` FROM $_PRODUCTS_TABLE WHERE `active`='1' AND `job` LIKE '%$jobsearch%' ORDER BY `job` ASC");

There is no need to filter the results using PHP. it is more efficient for MySQL to do this than PHP.

 

 

This make no sense to be at all.

array_push($newImgArr, $singleImg."!!!".$result->id."!!!".$result->client."!!!".$result->job."!!!".$result->description."!!!".$result->overview);

...

array_push($newImgArr, $result->image."!!!".$result->id."!!!".$result->client."!!!".$result->job."!!!".$result->description."!!!".$result->overview);

You could just push the $result object to the array? 

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.