Jump to content

Not displaying all results


ragrim

Recommended Posts

Hi,

 

im trying to display mysql results in a form but for some reason im only getting the first field and not the rest, it will show me the "firstname" field but nothing else, for the life of me cant figure out why, any help would be appreciated.

 

<?php
$sql = mysql_query("SELECT * FROM invoicing.customers WHERE id = '$id' ");
$sql_res = mysql_query($sql); //execute query

while($row = mysql_fetch_array($sql))
  
$firstname=$row['firstname'];
$lastname=$row['lastname'];
$address=$row['address'];
$suburb=$row['suburb'];
$postcode=$row['postcode'];
$phone1=$row['phone1'];
$phone2=$row['phone2'];
$email1=$row['email1'];
$email2=$row['email2'];
$billingemail=$row['billingemail'];
?>

 

and then i display it in forms with

 

<td>First Name<input name="firstname" style="width: 191px" type="text" class="style15" value="<?php print "$firstname" ?>"></td>
<td>Last Name<input name="lastname" type="text" class="style14" value="<?php print "$lastname" ?>" style="width: 191px"> </td>

 

has it got something to do with the fact im using $row?

 

Link to comment
https://forums.phpfreaks.com/topic/136624-not-displaying-all-results/
Share on other sites

Surprised you got any results at all...

 

Try:

 

$sql = mysql_query("SELECT * FROM customers WHERE id = '$id' ");
$sql_res = mysql_query($sql); //execute query

while($row = mysql_fetch_array($ql_res))
{ 
$firstname=$row['firstname'];
$lastname=$row['lastname'];
$address=$row['address'];
$suburb=$row['suburb'];
$postcode=$row['postcode'];
$phone1=$row['phone1'];
$phone2=$row['phone2'];
$email1=$row['email1'];
$email2=$row['email2'];
$billingemail=$row['billingemail'];
}

He meant:

$sql = mysql_query("SELECT * FROM customers WHERE id = '$id' ");
$sql_res = mysql_query($sql); //execute query

while($row = mysql_fetch_array($sql_res))  //Forget the "S"
{ 
$firstname=$row['firstname'];
$lastname=$row['lastname'];
$address=$row['address'];
$suburb=$row['suburb'];
$postcode=$row['postcode'];
$phone1=$row['phone1'];	
$phone2=$row['phone2'];	
$email1=$row['email1'];	
$email2=$row['email2'];
$billingemail=$row['billingemail'];
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.