Solved

Same record being displayed for each value

Posted on 2007-03-23
4
192 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

Suggested Solutions

This article discusses four methods for overlaying images in a container on a web page
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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 …

756 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