Solved

Same record being displayed for each value

Posted on 2007-03-23
4
194 Views
Last Modified: 2007-03-24
Ok, I've got this thing working right, but I am getting the same record for each value displayed on the page.

<?php
$i = 0;
while ($i < 2) {
      $i = $i+1;
      if ($i==1) {
            echo "<tr>";
      }
      echo "<td width=\"250\">";
?>
<form action="/admin/delete_provider.php?Company=<?= $strCompanyname ?>" method="post">
     <a href="/admin/edit_provider.php?providerID=<?= $providerID ?>" >
       <?= $strCompanyname ?>
     </a>&nbsp;
     <a href="/admin/confirm_provider.php?Company=<?= $strCompanyname ?>">
       <input type="button" value="Delete" class="btn2">
     </a>
</form>
<?php
 echo "</td>";
      if ($i==3) {
            echo "</tr>";
            $i=0;
      }
}
?>
0
Comment
Question by:pingeyeg
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 24

Expert Comment

by:glcummins
ID: 18782334
Where are $strCompanyname and $providerID being set?
0
 
LVL 1

Author Comment

by:pingeyeg
ID: 18782377
This is the entire code block:

<?php
if ($_GET['list'] == "list") {

$SQLstr2 = mysql_query("SELECT tblAdspace.providerID, tblAdspace.strCompanyname FROM tblAdspace")
or die(mysql_error());

while($row = mysql_fetch_array($SQLstr2)){
      $strCompanyname = $row['strCompanyname'];
      $providerID = $row['providerID'];
}
?>
<table id="admin_list" align="center" border="1">
<?php
$i = 0;
while ($i < 2) {
      $i = $i+1;
      if ($i==1) {
            echo "<tr>";
      }
      echo "<td width=\"250\">";
?>
<form action="/admin/delete_provider.php?Company=<?= $strCompanyname ?>" method="post">
     <a href="/admin/edit_provider.php?providerID=<?= $providerID ?>" >
       <?= $strCompanyname ?>
     </a>&nbsp;
     <a href="/admin/confirm_provider.php?Company=<?= $strCompanyname ?>">
       <input type="button" value="Delete" class="btn2">
     </a>
</form>
<?php
 echo "</td>";
      if ($i==3) {
            echo "</tr>";
            $i=0;
      }
}
?>
0
 
LVL 9

Accepted Solution

by:
under_dog earned 500 total points
ID: 18782429
Try this:

<?php
if ($_GET['list'] == "list") {

$SQLstr2 = mysql_query("SELECT tblAdspace.providerID, tblAdspace.strCompanyname FROM tblAdspace")
or die(mysql_error());

$i = 0;

while($row = mysql_fetch_array($SQLstr2)){
      $strCompanyname = $row['strCompanyname'];
      $providerID = $row['providerID'];
?>
<table id="admin_list" align="center" border="1">
<?php
      $i = $i+1;
      if ($i==1) {
            echo "<tr>";
      }
      echo "<td width=\"250\">";
?>
<form action="/admin/delete_provider.php?Company=<?= $strCompanyname ?>" method="post">
     <a href="/admin/edit_provider.php?providerID=<?= $providerID ?>" >
       <?= $strCompanyname ?>
     </a>&nbsp;
     <a href="/admin/confirm_provider.php?Company=<?= $strCompanyname ?>">
       <input type="button" value="Delete" class="btn2">
     </a>
</form>
<?php
 echo "</td>";
      if ($i==3) {
            echo "</tr>";
            $i=0;
      }
}
?>
0
 
LVL 24

Expert Comment

by:glcummins
ID: 18782454
As under_dog said, your display portion needs to be inside the while() loop. As it stood before, your while loop was completing, and only the very last record found in the loop was passed on to the display portion of the script.
0

Featured Post

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!

Question has a verified solution.

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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
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.

615 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