Jump to content

Recommended Posts

I've been over it a few times and for some reason my results are being read out 2 times per row in the database. This error occurs consistently accross my scripts except for one, but for the life of me I can't work out how. Any help would be appreciated. I have a feeling this is rather basic and am sorry for asking something so trivial.

 

Many thanks.

 

GET ALL CS RESULTS PHP - FULL FILE

<?php

include ('connect.php');

$cat = $_GET['id'];

$sql = "SELECT ind_id, ind_name, cs_name, cs_value, quarter, fiscal_year FROM industry, customer_satisfaction, cs_value, time";

$result = mysqli_query($link, $sql);
$output = mysqli_affected_rows($link); 

if (!$result)
{
$error_num = mysqli_errno($link);
$error_desc = mysqli_error($link);
include ('error.html.php');
exit();
}
else
{
while ($industry_result = mysqli_fetch_array($result))
{
	$industry_results[] = array(
	'ind_id' => $industry_result['ind_id'],
	'ind_name' => $industry_result['ind_name'],
	'cs_name' => $industry_result['cs_name'],
	'cs_value' => $industry_result['cs_value'],
	'quarter' => $industry_result['quarter'],
	'fiscal_year' => $industry_result['fiscal_year']
	);
}
if (!$industry_results)
{
$error = '<p><i>Database Returned no Results.</i></p>';
}
else
{
include ('all_cs_results.html.php');
}
}

?>

 

GET ALL CS RESULTS HTML OUTPUT - FULL FILE

<ul id="result_list" class="results_list">
<?php foreach ($industry_results as $industry_result): ?>
<li id="cs_result">
<?php echo $industry_result['ind_id']; ?>

</li>
<li id="cs_result">
<?php echo $industry_result['ind_name']; ?>

</li>
<li id="cs_result">
<?php echo $industry_result['cs_name']; ?>

</li>
<li id="cs_result">
<?php echo $industry_result['cs_value']; ?>

</li>
<li id="cs_result">
<?php echo $industry_result['quarter']; ?>

</li>
<li id="cs_result">
<?php echo $industry_result['fiscal_year']; ?>

</li>

<?php endforeach; ?>
</ul>

 

JQUERY AJAX LAYER - CODE SNIPPET

$('#all_cs').click(function(){ $('#display').load('get_all_cs.php', function(){  })});

Link to comment
https://forums.phpfreaks.com/topic/231390-looping-issue/
Share on other sites

your queries are joining tables together without any direction, its not abnormal to get more than one result of the same, when two tables correlate to eachother, obviously you're gonna PULL TWO RESULTS one from each table :)

 

how to prevent this, use the ON clause

 

for example

SELECT * FROM table1 JOIN table2 ON (table1.id = table2.tableId)

 

Link to comment
https://forums.phpfreaks.com/topic/231390-looping-issue/#findComment-1190822
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.