Jump to content

Help with Loop count?


danjapro

Recommended Posts

 

 

I have this SQL query that gathers set information for the Salesperson($user) that is logged in and viewing theri need information.

Everything works weell, except my Loop Count.

 

I don't know, what I am doping incorrectly. It returns only two values which are the same.

 

But the Query returns 10 values for that user. When I run the query direct in SQL DB.

 

What am I missing?

 






  <div class='page_content clearfix'>
                  <div class='grid_8 first'>





<?php



$salesPersonId = & JFactory::getUser()->get('username');
//$merchantId = JFactory::getSession()->get('merchantId');  
$db =& JFactory::getDBO();
$query = "	SELECT XXX_merchant.*, XXX_merchant.name as MercName, XXX_merchant.address as MercAddress 
		FROM XXX_sales_person, jXXX_merchant 
		WHERE XXX_sales_person.user_name = '$salesPersonId'
		AND XXX_merchant.sales_person_id = XXX_sales_person.id";
$db->setQuery( $query );
$row  = $db->loadObject();
//echo $query;


//echo $query;
//echo '<br>';
//echo $salesPerson->name;


?>
<?php
   

$link = 'index.php?option=XXX&controller=deal&task=view&id=' . $row->id;

$count = 0; 
        foreach ( $row as $row): 



	$link = '/index.php?option=XXX&controller=merchant&task=edit&cid[]=' . $row->id;
?>

<div class='quickie_login grid_9 last' style="width: 140px">
                    <div class='text_center' id='login_banner'>
                      <div class='page_content text_center'>
				      <div class="avatar" style="float: left; margin-top: -10px; padding: 0px;">
                          <a class="k2Avatar ubAvatar" href="<?php echo $link; ?>" title="<?php echo JText::_($row->MercName); ?> Edit Account" target="_blank">
<span class="ubName" style="display: block;  margin-top: -20px;"><b><?php echo $row->MercName; ?></b> </span>				
	<?php 
	if(!empty($row->logo_url))
	{
		$imagePathArr = unserialize(urldecode($row->logo_url));
		$link='http://';
		$link.= $_SERVER["SERVER_NAME"].$link_server.DS;
		$link.=$imagePathArr[0];
		$link =str_replace("\\","/",$link);

	?>
		<img src='<?php echo $link; ?>' alt="<?php echo $row->name; ?>" style="max-width: 100px; height:100px;"/>
	<?php 
}
	?>



</a>
</div>


<div class="sales-system2">

<div style="display: block; margin-top: 0px;">

</div>
</div>		


</div>
</div>


<?php endforeach;?>





Link to comment
https://forums.phpfreaks.com/topic/250945-help-with-loop-count/
Share on other sites

not sure if you simply put the XXX in for security, but

 

SELECT XXX_merchant.*, XXX_merchant.name as MercName, XXX_merchant.address as MercAddress 
		FROM XXX_sales_person, jXXX_merchant 
		WHERE XXX_sales_person.user_name = '$salesPersonId'
		AND XXX_merchant.sales_person_id = XXX_sales_person.id";

 

1. if your table is jXXX_merchant, then your table references will need to be changed, or else your table name will.

 

since I don't know what your methods do, it's hard to say what's really going on here, have you tried debugging your code at all?

 

foreach ( $row as $row):

 

this is not doing what you expect, if you are trying to iterate through each row grabbed, you will want to use a while loop..

 

while($row = mysql_fetch_assoc($query_identifier)) // example

 

the first step here is to use mysql_num_rows to see how many rows your query is actually grabbing before you begin to process the results.

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.