Solved

Same record being displayed for each value

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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…
This article discusses four methods for overlaying images in a container on a web page
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 …

708 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

18 Experts available now in Live!

Get 1:1 Help Now