Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 261
  • Last Modified:

WHILE LOOP PHP BEING A PAIN! Help please

Hi Experts,

This while loop is createing the output over and over and over in a seperate box. All i need it to do is to add the information into the last spoken to and the notes box. rather than recreate seperate tables. is this possible?? Ive attached my code.
<?php 
error_reporting(E_ALL);
include 'myphp.php';
$val = $_GET['val'];

$sql = "select * from customer, notes where customer.customer_name = notes.customer_name AND customer.customer_name = '" . $val . "'"; 
$result = mysql_query($sql) or die(mysql_error() . " IN $sql"); 
$rs = mysql_query($sql);

while($row = mysql_fetch_array($rs))
{
   echo"<table>";
   echo "<tr><td>Company:</td><td>".$row['customer_name']."</td></tr>";
    echo "<tr><td>Account Number:</td><td><a href=\"account.php?val=".$row['account_number']."\">".$row['account_number']."</a></td></tr>";
	 echo "<tr><td>Contact Name:</td><td>".$row['contact_name']."</td></tr>";
	 echo "<tr><td>Telephone Number:</td><td>".$row['telephone_number']."</td></tr>";
	 echo "<tr><td>Fax:</td><td>".$row['fax']."</td></tr>";
	 echo "<tr><td>Contact Mob Number:</td><td>".$row['contact_mobile']."</td></tr>";
	 echo "<tr><td>Address:</td><td>".$row['full_address']."</td></tr>";
	 echo "<tr><td>Network:</td><td>".$row['network']."</td></tr>";	 
	 echo "<tr><td>Last Spoke To:</td><td>
<div style=\"width: 190px;height: 250px;overflow:auto;\">"
.$row['last_spoke_to']."</div></td></tr>";
echo "<tr><td>Notes:</td><td>
<div style=\"width: 190px;height: 250px;overflow:auto;\">"
.$row['notes']."</div></td></tr>";
	 echo "<tr><td>Kit Fund Level:</td><td>".$row['kit_fund_level']."</td></tr>";
   echo"</table>";
}
   ?>

Open in new window

0
NeoAshura
Asked:
NeoAshura
  • 6
  • 3
  • 2
1 Solution
 
NeoAshuraAuthor Commented:
I should of explained a little better, there is only one data field for Customer name, telephone, fax, mob, address and network..

but Last spoke to and notes are from a diffrent table where there is more than one entry.

it creates a new table for every notes entry when all i require is for it to be added to the exsisting table.

is this possible?
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
you have to move the  following 2 lines outside the loop:
echo"<table>";  // this has to go before the loop
echo"</table>"; // this has to go after the loop
0
 
Lukasz ChmielewskiCommented:
Move the <table> and </table> outside the loop.
Does the query run ok through phpmyadmin ?
0
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

 
NeoAshuraAuthor Commented:
thanks for the attempt guys but that didnt solve it either. It repeats the data still, Last spoke to and Notes are from a different table but it repeats all data. have a look at the screenshots i provided but try and imagine them joined together on the same page. thats the problem im having.
0
 
NeoAshuraAuthor Commented:
sorry forgot the screen shots didnt i...

can you see the data above the last spoke to and notes is the same but the last spoke to and notes entry is diffrennt.. it repeats all of the table but i only need it to add the last_spoke to and notes bit to one box and not two
picture.jpg
picture2.jpg
0
 
Lukasz ChmielewskiCommented:
There are no screenshots... ?
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
I see.

well, either you make this in 2 queries, or you put the account information only on the first "loop"...

what happens if there are 0 notes for a customer?
you need a left join ...

something like this:
<?php 
error_reporting(E_ALL);
include 'myphp.php';
$val = $_GET['val'];

$sql = "select * from customer left join notes on customer.customer_name = notes.customer_name WHERE customer.customer_name = '" . $val . "'"; 
$result = mysql_query($sql) or die(mysql_error() . " IN $sql"); 
$rs = mysql_query($sql);

echo"<table>";
$row_count = 0;

while($row = mysql_fetch_array($rs))
{
   $row_count ++;
   if ($row_count == 1)
   {
     echo "<tr><td>Company:</td><td>".$row['customer_name']."</td></tr>";
     echo "<tr><td>Account Number:</td><td><a href=\"account.php?val=".$row['account_number']."\">".$row['account_number']."</a></td></tr>";
     echo "<tr><td>Contact Name:</td><td>".$row['contact_name']."</td></tr>";
     echo "<tr><td>Telephone Number:</td><td>".$row['telephone_number']."</td></tr>";
     echo "<tr><td>Fax:</td><td>".$row['fax']."</td></tr>";
     echo "<tr><td>Contact Mob Number:</td><td>".$row['contact_mobile']."</td></tr>";
     echo "<tr><td>Address:</td><td>".$row['full_address']."</td></tr>";
     echo "<tr><td>Network:</td><td>".$row['network']."</td></tr>";  
     echo "<tr><td>Last Spoke To:</td><td>
<div style=\"width: 190px;height: 250px;overflow:auto;\">"
.$row['last_spoke_to']."</div></td></tr>";
  }
  echo "<tr><td>Notes:</td><td>
<div style=\"width: 190px;height: 250px;overflow:auto;\">"
.$row['notes']."</div></td></tr>";
         echo "<tr><td>Kit Fund Level:</td><td>".$row['kit_fund_level']."</td></tr>";
}
   echo"</table>";
   ?>

Open in new window

0
 
NeoAshuraAuthor Commented:
Hi thanks that fixed the repeat of the company data..... however.. how would i go about only getting one notes box and one last_spoke to box, The last spoke to box also only appears once when it should appear multiple times like the notes box is there antoher join needed here?

i appricate all your time i would be lost otherwise.

please see picture attached
picture4.jpg
0
 
NeoAshuraAuthor Commented:
I am open to changeing Database structure and insert query to get around this problem too. I have attached my insert query which may be the cause of the problem.

If there is a way of just adding information to an already exsisiting database entry then that may be an option too.

ive attached my insert code.
<?php
session_start();
ob_start();
?>
<?php 
error_reporting(E_ALL);

$last_spoke_to = $_POST['last_spoke_to'];
$notes = $_POST['notes'];
$val= $_REQUEST['val'];
var_dump($val); 
var_dump($notes); 


include 'myphp.php';


//update the database with the set variables recoverd from the form from the other page. 

$query = "INSERT INTO `notes` (customer_name, notes, last_spoke_to) VALUES ('".$val."','".$notes."','".$last_spoke_to."')";


$result=mysql_query($query);

 if($result){
	header("location:mobilenum.php?val=".$val);
}
else{
	echo "ERROR";
}
mysql_close();

?>

Open in new window

0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
UPDATE means: update an existing record.
INSERT means: create a new record.

so, what exactly do you want?
anyhow, this goes beyond the original question, no?
0
 
NeoAshuraAuthor Commented:
indeed ill reward and open new question which hopefully you can assist in.

many thanks
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 6
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now