Solved

Displaying the same record multiple times

Posted on 2007-03-26
9
189 Views
Last Modified: 2008-03-17
I can't seem to figure this out.  I am trying to diplay the reviews of a company from the db.  The company has 3 reviews, but right now only one review displays twice.  Can anyone help me with this?

<?php

$conn = mysql_connect("127.0.0.1", "", "");
mysql_select_db("providers", $conn);

$SQLstr = mysql_query("SELECT tblReviews.strCompanyname, tblReviews.strReportdate, tblReviews.strServicecat, tblReviews.strMonthstart, tblReviews.strDaystart, tblReviews.strYearstart, tblReviews.strDayend, tblReviews.strMonthend, tblReviews.strYearend, tblReviews.strWorkperform, tblReviews.strComments, tblReviews.strSatisfied, tblReviews.strPricereas, tblReviews.strFinishedontime, tblReviews.strReceiveguar, tblReviews.strTreatedfair, tblReviews.strShowontime, tblReviews.strCallsreturned, tblReviews.strCleanup, tblReviews.strOverall, tblReviews.strHireagain, tblReviews.strQuote, tblReviews.strActualprice, tblAdspace.strProviderservice, tblReviews.reviewID, tblAdspace.strCompanyname, tblReviews.strCustomer FROM tblReviews INNER JOIN tblAdspace ON tblReviews.strCompanyname = tblAdspace.strCompanyname WHERE tblReviews.strCompanyname = '" . $_GET['Company'] . "' ORDER BY tblReviews.strReportdate DESC")
or die(mysql_error());

while ($row = mysql_fetch_array($SQLstr)) {
$strCompanyname = $row['strCompanyname'];
$strReportdate = $row['strReportdate'];
$strServicecat = $row['strServicecat'];
$strWorkperform = $row['strWorkperform'];
$strComments = $row['strComments'];
$strMonthstart = $row['strMonthstart'];
$strDaystart = $row['strDaystart'];
$strYearstart = $row['strYearstart'];
$strMonthend = $row['strMonthend'];
$strDayend = $row['strDayend'];
$strYearend = $row['strYearend'];
$strSatisfied = $row['strSatisfied'];
$strPricereas = $row['strPricereas'];
$strFinishedontime = $row['strFinishedontime'];
$strReceiveguar = $row['strReceiveguar'];
$strTreatedfair = $row['strTreatedfair'];
$strShowontime = $row['strShowontime'];
$strCallsreturned = $row['strCallsreturned'];
$strCleanup = $row['strCleanup'];
$strOverall = $row['strOverall'];
$strHireagain = $row['strHireagain'];
$strQuote = $row['strQuote'];
$strActualprice = $row['strActualprice'];
$strProviderservice = $row['strProviderservice'];
$reviewID = $row['reviewID'];
}
?>
0
Comment
Question by:pingeyeg
  • 5
  • 3
9 Comments
 
LVL 24

Expert Comment

by:glcummins
ID: 18792942
What happens in your code after the "while($row..." statement? How are you displaying the data? Specifically, you need to make sure that the display portion appears in the while() loop. If you are waiting to display the data until after the while loop is complete, your variables are getting overwritten with the last record found, and only that record will be displayed.
0
 
LVL 1

Author Comment

by:pingeyeg
ID: 18792997
This is the beginning of the code, just to hopefully make your question clear.

$SQLstr = mysql_query("SELECT tblReviews.strCompanyname, tblReviews.strReportdate, tblReviews.strServicecat, tblReviews.strMonthstart, tblReviews.strDaystart, tblReviews.strYearstart, tblReviews.strDayend, tblReviews.strMonthend, tblReviews.strYearend, tblReviews.strWorkperform, tblReviews.strComments, tblReviews.strSatisfied, tblReviews.strPricereas, tblReviews.strFinishedontime, tblReviews.strReceiveguar, tblReviews.strTreatedfair, tblReviews.strShowontime, tblReviews.strCallsreturned, tblReviews.strCleanup, tblReviews.strOverall, tblReviews.strHireagain, tblReviews.strQuote, tblReviews.strActualprice, tblAdspace.strProviderservice, tblReviews.reviewID, tblAdspace.strCompanyname, tblReviews.strCustomer FROM tblReviews INNER JOIN tblAdspace ON tblReviews.strCompanyname = tblAdspace.strCompanyname WHERE tblReviews.strCompanyname = '" . $_GET['Company'] . "' ORDER BY tblReviews.strReportdate DESC")
or die(mysql_error());

while ($row = mysql_fetch_array($SQLstr)) {
$strCompanyname = $row['strCompanyname'];
$strReportdate = $row['strReportdate'];
$strServicecat = $row['strServicecat'];
$strWorkperform = $row['strWorkperform'];
$strComments = $row['strComments'];
$strMonthstart = $row['strMonthstart'];
$strDaystart = $row['strDaystart'];
$strYearstart = $row['strYearstart'];
$strMonthend = $row['strMonthend'];
$strDayend = $row['strDayend'];
$strYearend = $row['strYearend'];
$strSatisfied = $row['strSatisfied'];
$strPricereas = $row['strPricereas'];
$strFinishedontime = $row['strFinishedontime'];
$strReceiveguar = $row['strReceiveguar'];
$strTreatedfair = $row['strTreatedfair'];
$strShowontime = $row['strShowontime'];
$strCallsreturned = $row['strCallsreturned'];
$strCleanup = $row['strCleanup'];
$strOverall = $row['strOverall'];
$strHireagain = $row['strHireagain'];
$strQuote = $row['strQuote'];
$strActualprice = $row['strActualprice'];
$strProviderservice = $row['strProviderservice'];
$reviewID = $row['reviewID'];
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Ask2bsure.com - (Admin Section) Edit Provider</title>
<link style="text/css" href="/css/style.css" rel="stylesheet">
</head>
<body>
<table align="center" id="admin">
<tr><td align="center" colspan="2">
<img src="/images/sublogo_2.png"><br />
<span style="font-size: 12px; color: #0000FF">(Admin Section)</span>
</td></tr>
<tr><td valign="top">
<div id="navlist">
<a href="/admin/">Home</a>
<a href="/admin/add_provider.php">Add Provider</a>
<a href="/admin/list_providers.php?list=list">Delete / Edit Provider</a>
<a href="/admin/list_providers.php?review=review">Toggle / Edit Reviews</a>
<a href="/index.php">Back To Website</a>
</div>
</td><td width="625">
<table id="main_admin" align="center" border="0">
<tr><td>
<?php
$rows = 0;
while ($rows <= 1) {
?>
<table id="review_admin" border="0" style="margin-bottom: 30px"><tr>
<form action="/admin/update_review.php" method="post">
<td colspan="4" id="review_header" align="center">
<input type="hidden" value="<?= $strCompanyname ?>" name="strCompanyname">
<input type="hidden" value="<?= $reviewID ?>" name="reviewID">
<?= $strCompanyname ?>
0
 
LVL 4

Expert Comment

by:mukhtar2t
ID: 18793001
I think your problem is in the query inner join it self , try
echo $SQLstr;
and paste the result to mysql
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:pingeyeg
ID: 18793031
SELECT tblReviews.strCompanyname, tblReviews.strReportdate, tblReviews.strServicecat, tblReviews.strMonthstart, tblReviews.strDaystart, tblReviews.strYearstart, tblReviews.strDayend, tblReviews.strMonthend, tblReviews.strYearend, tblReviews.strWorkperform, tblReviews.strComments, tblReviews.strSatisfied, tblReviews.strPricereas, tblReviews.strFinishedontime, tblReviews.strReceiveguar, tblReviews.strTreatedfair, tblReviews.strShowontime, tblReviews.strCallsreturned, tblReviews.strCleanup, tblReviews.strOverall, tblReviews.strHireagain, tblReviews.strQuote, tblReviews.strActualprice, tblAdspace.strProviderservice, tblReviews.reviewID, tblAdspace.strCompanyname, tblReviews.strCustomer FROM tblReviews INNER JOIN tblAdspace ON tblReviews.strCompanyname = tblAdspace.strCompanyname WHERE tblReviews.strCompanyname = 'Plumbing When You Need It' ORDER BY tblReviews.strReportdate DESC
0
 
LVL 24

Accepted Solution

by:
glcummins earned 500 total points
ID: 18793100
Okay, let me reiterate what I said in my first post. In your while loop, you are copying the MySQL results into the variables three times. Then the loop ends, with only the last set of MySQL results in the variables.

Then, you are beginning your display portion. This only displays the last record, because that is all that the variables contain.

You need to move your display section (the HTML code) into the while() loop, so that the current record set is displayed at the same time as it is fetched.
0
 
LVL 1

Author Comment

by:pingeyeg
ID: 18793274
So do you mean to move the while loop of variables right after the while loop that makes the rows like this?

<?php
$rows = 0;
while ($rows <= 1) {

      while ($row = mysql_fetch_array($SQLstr)) {
$strCompanyname = $row['strCompanyname'];
$strReportdate = $row['strReportdate'];
$strServicecat = $row['strServicecat'];
$strWorkperform = $row['strWorkperform'];
$strComments = $row['strComments'];
$strMonthstart = $row['strMonthstart'];
$strDaystart = $row['strDaystart'];
$strYearstart = $row['strYearstart'];
$strMonthend = $row['strMonthend'];
$strDayend = $row['strDayend'];
$strYearend = $row['strYearend'];
$strSatisfied = $row['strSatisfied'];
$strPricereas = $row['strPricereas'];
$strFinishedontime = $row['strFinishedontime'];
$strReceiveguar = $row['strReceiveguar'];
$strTreatedfair = $row['strTreatedfair'];
$strShowontime = $row['strShowontime'];
$strCallsreturned = $row['strCallsreturned'];
$strCleanup = $row['strCleanup'];
$strOverall = $row['strOverall'];
$strHireagain = $row['strHireagain'];
$strQuote = $row['strQuote'];
$strActualprice = $row['strActualprice'];
$strProviderservice = $row['strProviderservice'];
$reviewID = $row['reviewID'];
}
?>
0
 
LVL 24

Expert Comment

by:glcummins
ID: 18793316
What are you trying to accomplish with this code?

   $rows = 0;
   while ($rows <= 1)

 Your 'while($row = mysql_fetch_array(...))' loop will already give you the correct number of iterations: If you received three records from the database, three records will be displayed.
0
 
LVL 1

Author Comment

by:pingeyeg
ID: 18793360
I thought I needed that to display multiple rows.  Well, now that I took that line out I only show one table of records on the page instead of 3 tables on the page.
0
 
LVL 1

Author Comment

by:pingeyeg
ID: 18793372
Nevermind, I just realized that I closed the while statement too early.  After I moved the closed bracket  to the bottom of the page all 3 records showed up correctly.  Thanks!!
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question