Solved

Displaying the same record multiple times

Posted on 2007-03-26
9
185 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

914 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now