PDA

View Full Version : my MySql Query not working correctly



- |Flash Man| -
March 30th, 2007, 01:30 AM
Hey all,

i have a mysql query which works fine and pulls the corrcet data it just when i try and print it to a single or essentially (a dynamic text field in flash) which i have done before but for some reason it's not working this time round.

I have 3 results in the database under the field suburb and i want all 3 of these results to appear on the one line/ in the one dynamic textfield on one line.

ATM i only get one suburb showing instead of three?
My take on it i think i'm missing a loop or something?

Maybe a fresh set of eyes will help????
Here is the code below:


<?php

$suburbs = $_POST['suburbs_vars'];

mysql_pconnect("$server", "$user", "$pass") or die (mysql_error());
mysql_select_db("$database") or die (mysql_error());

$sql = "SELECT suburb FROM `mytable` ORDER BY `suburb` ASC";
$result = mysql_query( $sql );

while ($line = mysql_fetch_array($result)) {
printf("Suburb: %s", $line[0]);
$ourtext = "suburbs_vars=" . $line['suburb'];

}
print($ourtext);

mysql_free_result($result);

?>

theHollow
March 30th, 2007, 05:01 AM
I think you need to change this:


$ourtext = "suburbs_vars=" . $line['suburb'];

to this:


$ourtext .= "suburbs_vars=" . $line['suburb'] . "\n";

- |Flash Man| -
March 30th, 2007, 09:43 AM
great thanks for that i'll defiantly give that ago...can't try it out till monday AUST time tho...keep you posted...thanks again for that.