Jump to content

Data missing from my array?


jamesxg1

Recommended Posts

Hiya peeps,

 

Here is my search code;

 

<?php include("top.php");?>
<?php
$resultStr='';
$columns=1;
if($_GET)
{
	if(isset($_GET['q']))
	{
		$arrwords=explode(" ",$_GET['q']);

		$searchObj=new FIRM_Search($_GET['q']);
		$resultStr=$searchObj->search();
		$columns=$searchObj->totalcols;
		//echo $columns."arrsize=".sizeof($searchObj->compResult);
		//var_dump($searchObj->compResult);
		exit('<pre>' . print_r($searchObj->compResult, true) . '</pre>');
		if($columns==1 && sizeof($searchObj->compResult)==1)
		{
				foreach($searchObj->compResult as $key=>$value)
					$_GET['c']=$value['company_id'];
				$companyObj = new FIRM_Company_detail($_GET['c']);
				$resultStr = $companyObj->showDetails();

		}
		 if($columns==1 && sizeof($searchObj->categoryList)==1)
			{
				foreach($searchObj->categoryList as $catKey=>$value)
				{
					$_GET['cat']=$catKey;
				}
				$catObj = new FIRM_Category($_GET['cat']);
				$resultStr = $catObj->fetchByCategory();
				$columns=$catObj->totalcols;
			}	
	}
	if(isset($_GET['c']))
	{
		$companyObj = new FIRM_Company_detail($_GET['c']);
		$resultStr = $companyObj->showDetails();
	}
	if(isset($_GET['cat']))
	{
		$catObj = new FIRM_Category($_GET['cat']);
		$resultStr = $catObj->fetchByCategory();
		$columns=$catObj->totalcols;
	}
	/*$darr = array('p'=>'q','q'=>'p','w'=>'m','m'=>'w','b'=>'d','d'=>'b','a'=>'o','o'=>'a','g'=>'d','d'=>'g',6=>9,9=>6);

	if($resultStr=='' && isset($_GET['q']))
	{	

		$word=FIRM_Common::wordCombination($_GET['q']);
		//var_dump($word);
		for($i=0;$i<sizeof($word);$i++)
		{
			$searchObj=new FIRM_Search($word[$i]);
			//echo $word[$i]."=".$searchObj->checkExist()."<br>";
			if($searchObj->checkExist()){
				$resultStr=$searchObj->search();
				$columns=$searchObj->totalcols;
				if($columns==1 && sizeof($searchObj->compResult)==1)
				{
					foreach($searchObj->compResult as $key=>$value)
					$_GET['c']=$value['company_id'];
					$_GET['cname']=$value['compname'];
					$companyObj = new FIRM_Company_detail($_GET['c']);
					$resultStr = $companyObj->showDetails();
				}
			}
			if($resultStr!='')
			break;
		}
	}*/

}
if(!isset($_GET['c']) && !isset($searchObj->compResult) && $searchObj->compResult == NULL && empty($searchObj->compResult) && count($searchObj->compResult, COUNT_RECURSIVE) == 0) {
$arrayCount = count($searchObj->compResult, COUNT_RECURSIVE);

if($_SESSION['currentlang'] == 'en') {
	$sql = "SELECT * FROM `firm_text_strings` WHERE `id` = '100' AND `languages_id` = 'en' ORDER BY `id` ASC";
	$result = mysql_query($sql) ;

	if($result) {
		while($row = mysql_fetch_array($result)) {
			$resultStr .= '<br /><br /><br /><br />';
			$resultStr .= '<span style="margin-left: 330px;">' . $row['data'] . '</span><br />';
			$resultStr .= '<span style="margin-left: 330px;">' . $row['3'] . '</span>';
		}
	} else {
		$resultStr = 'error';
	}
} elseif($_SESSION['currentlang'] == 'is') {
	$sql = "SELECT * FROM `firm_text_strings` WHERE `id` = '100' AND `languages_id` = 'is' ORDER BY `id` ASC";
	$result = mysql_query($sql) ;

	if($result) {
		while($row = mysql_fetch_array($result)) {
			$resultStr .= '<br /><br /><br /><br />';
			$resultStr .= '<span style="margin-left: 330px;">' . $row['data'] . '</span><br />';
			$resultStr .= '<span style="margin-left: 330px;">' . $row['3'] . '</span>';
		}
	} else {
		$resultStr = 'error';
	}
}

}
?>
<body onLoad="checkSrcoll()"><script type="text/javascript" src="js/wz_tooltip.js"></script>
	<a name="top" />
<form name="Form1" id="Form1" action="search.php" method="get">
		<div class="header"><a href="index.php">
		<img src="images/header_top.gif" alt="" height="70" width="179" id="subLogo" alt="Firmaskra Islands exporters directory - Iceland food, mineral, shipping, IT technology,medical fishery equipements, travel firm and exporters" /></a>
			<div id="hdFrm">
				<span id="Label1"><?php echo $text[1]?$text[1]:__('Leita a');?>: </span>
<input type="text" name="q" size="42" id="q" value="<?php echo $_GET['q']!=""?$_GET['q'] :'';?>"/> 
<input type="submit" value="<?php echo $text[2]? $text[2]:__('Hefja leit')?>" name="search" id="search"/>					
<br />
				<div id="Label2" style="position:relative; float:left;"> </div><span style="width:auto;" id="searchinfo"><?php echo $text[3]? $text[3]: __('Skr inn nafn fyrirtkis - vru - vrumerkis - nafn stjrnanda');?>	</span>			</div>
		</div>
		</form>
		<div class="subHead">
	<table style="width:100%" >
			<tr>
			<td nowrap="nowrap">
			<div class="left" style="width:100%">
			<?php echo $oCommon->getflags($_SERVER['SCRIPT_NAME'],$_SERVER['QUERY_STRING']); ?>
			<?php echo $oCommon->getPrintinfoLinks();?>
			</div>
			</Td>
			</td><td nowrap="nowrap">
			<div class="right" style="height: 14px; width:100%">
			 <?php echo $oCommon->getInfoPagesLink();?>
			  </div>

		</Td></tr></table>
		</div>
		<div class="printinfo">
			<div id="pHead"><?php echo __('Firmaskrá Íslands')?></div>
			<div id="pLeft">www.firmaskra.is</div><div id="pRight">firmaskra@firmaskra.is</div>
		</div>


	<div style="position:relative; float:left; min-width:999px; width:99%;" id="datadiv">
	<?php
			if($resultStr)
			{
				echo $resultStr;
				?>
				<script language="javascript" type="text/javascript">
					var columns='<?php echo $columns;?>';
					//alert(columns);
					if(columns==1)
					{
					h2width=970;
					ulwidth=970;
					<?php if(!isset($_GET['cat'])):?>
					liwidth=960;
					<?php else:?>
					liwidth=470;
					<?php endif;?>
					}
					else {
					//alert(1)

					h2width=920/columns;
					ulwidth=960/columns;
					liwidth=930/columns;

					}

					$('ul').toggleClass('ul'+columns);
					$('li').toggleClass('li'+columns);
					$('h2').css('width',(h2width+10)+'px');
					$('ul').css('width',ulwidth+'px');
					$('li').css('width',liwidth+'px');
					$('div.FloatLeftPadding').css('width',h2width+'px');
					$('div.FloatLeftNoPadding').css('width',h2width+'px');
					$("#WzTtDiV").css('opacity',0.9);
					if(columns==1)
					{
					$('#firms_by_name').css('width',(ulwidth+ulwidth)+20);

					$('#h2firmsbyname').css('width',(h2width+h2width+20))
					}
					else{
					$('#firms_by_name').css('width',ulwidth-40);
					$('#firms_by_name1').css('width',ulwidth-40);
					$('#ulname').css('width',ulwidth-60);
					$('#h2firmsbyname').css('width',h2width-60)
					}
					$('#ulname').css('width',(ulwidth+ulwidth+20));
					$('#firms_by_name').css('width',(ulwidth+ulwidth)+20);
					$('#h2firmsbyname').css('width',(h2width+h2width+20))
				</script>
				<?php 

			}


		?>
		</div>

</body>
<script>
$('#Label2').width($('#Label1').width());

</script>
<script type="text/javascript">
$().ready(function()
{
//$('#q').width($('#searchinfo').width()-($('#search').width()+20));
if($('#searchinfo').width()<300)
	$('#q').width(300);
else
	$('#q').width($('#searchinfo').width());

});
function checkSrcoll()
{
x=$(document).scrollTop();
if(x){
  $("#datadiv").append('<a href=\"#\" class=\"toplink\" style=\"\"><img src="images/arrow_up.gif" alt="Efst  su"  border=0/> <?php echo htmlspecialchars(isset($text[35])?$text[35]:__('Efst  su'));?></a>');
}

}
</script>
</html>

 

I get this return.

 

Array
(
    [0] => Array
        (
            [compname] => 
            [address] => 
            [postcode] => IS-200
            [communityname] => Kopavogur
            [rank] => 2
            [company_id] => 14875
        )

    [1] => Array
        (
            [compname] => Toyota Kopavogur
            [address] => 
            [company_id] => 111686
            [postcode] => IS-200    
            [communityname] => Kopavogur
            [rank] => 7
        )
)

 

As you can see [1] the address is missing, and [0] most of it is missing lol. The data is all the in the MYSQL, I have made another script to echo it all out. I've been trying to solve this for ages now. The class for the search script is attached to this post, as it was too large to paste in here.

 

If anyone has any ideas it would be very much appreciated.

 

Many thanks,

 

James.

 

P.S; sorry to edit, I forgot to mention. The site has two languages, EN & IS it works perfectly in IS but not in EN. Confusing.

 

[attachment deleted by admin]

Link to comment
Share on other sites

No need to quote on a lot of stuff you do on the queries...

 

$sql = "SELECT * FROM `firm_text_strings` WHERE `id` = '100' AND `languages_id` = 'is' ORDER BY `id` ASC";

 

the above code could be written like this:

$sql = "SELECT * FROM firm_text_strings WHERE id = 100 AND languages_id = 'is' ORDER BY id ASC";

or:

$sql = 'SELECT * FROM firm_text_strings WHERE id = 100 AND languages_id = \'is\' ORDER BY id ASC';

 

I would also do this:

$result = mysql_query($sql) or die(mysql_error());

 

and if you are not sure what happens next, and you really don't know if you get any rows at all...

if(mysql_num_rows($result)>0){

}else{
echo 'Nothing found';
}

 

 

Just for testing purposes, I would have written this:

$sql = 'SELECT * FROM firm_text_strings WHERE id = 100 AND languages_id = \'is\' ORDER BY id ASC';
$result = mysql_query($sql) or die(mysql_error());
if(mysql_num_rows($result)>0){
while($row=mysql_fetch_array($result)){
	$array[]=$row;
}
}else{
echo 'Nothing found';
}

print_r($array);

 

do the same for english too, and use my exact code and just change the is to en in the query

oh and put the code just before your mysql queries.

for example under:

} elseif($_SESSION['currentlang'] == 'is') {

and

if($_SESSION['currentlang'] == 'en') {

Link to comment
Share on other sites

Hiya MMDE,

 

Thanks for a prompt reply, it's not the search page that isnt working, as all that works fine. It's the search class I have attached to this post that is playing up, and returning the array with missing data.

 

Regarding the queries; I do this for 1) Security. 2) It's clean. 3) And to close open varibles.

 

Many many thanks,

 

James.

Link to comment
Share on other sites

I read your attached file now... sorry I thought it was the same in the post.

 

I would have looked at how you assigned these problematic values. I see it isn't the same as the other ones that works fine.

If you look, it tries to check if the language session == is, and not if it == en!

Link to comment
Share on other sites

I read your attached file now... sorry I thought it was the same in the post.

 

I would have looked at how you assigned these values. I see it isn't the same as the other ones that works fine.

If you look, it tries to check if the language session == is, and not if it == en!

 

Hiya MMDE,

 

I did have an else on it if its not equal to IS, should I change this by putting an elseif?

 

Many thanks,

 

James.

Link to comment
Share on other sites

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.