Solved

Displaying the same record multiple times

Posted on 2007-03-26
9
187 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
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 create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

776 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