How to validate variables from previous loop?

Hi,

Here’s the problem:

I am selecting records in the MySQL db and outputing to the page.

You’ll find a screenshot of some data in my saved_alerts table at http://realestateplace.com.au/Screenshot33.png

Now, I want to display the data from the user “gzeus” to the page. Doing a while endoffile loop works great. However I want to display each field of every record with gzeus username with the same title just once not 3 times, like this:

Title
mode, type, state, suburb, bedsmin, bedsmax, pricemin, pricemax

QLD 2-4
buy, house, QLD, arundel, helensvale, elanora, 2, 4, 100000, 400000

NOT:

QLD 2-4
buy, house, QLD, arundel, 2, 4, 100000, 400000

QLD 2-4
buy, house, QLD, helensvale, 2, 4, 100000, 400000

QLD 2-4
buy, house, QLD, elanora, 2, 4, 100000, 400000

Here’s the code I have now. It outputs like the last example here, row by row. Again, how can I make it select the records that have the same username AND the same Title and output them in one line like the first example? Any ideas?

Code:

[php]<?php

$query = (“SELECT * FROM savedalerts WHERE user_ID = ‘$total_user’”);

Connect to Mysql, select the correct database

$conn = mysql_connect($host,$user,$pass) or die(mysql_error());
mysql_select_db($db) or die(mysql_error());

$result = mysql_query($query);

get the number of hits, i.e. rows returned

$number_rows = mysql_num_rows($result);

if ($number_rows == 0) # if no alerts are present for this user
{
echo “You have not setup any property alerts yet.
Would you like to do so now?”;
echo “
Setup a new alert”;
}
else # if there are alerts extract them from the db and display them
{
while ($i < $number_rows) # while($row = mysql_fetch_array($result))
{
$title_alert = mysql_result($result,$i,“Title”);
$mode_alert = mysql_result($result,$i,“mode”);
$type_alert = mysql_result($result,$i,“type”);
$state_alert = mysql_result($result,$i,“state”);
$suburb_alert = mysql_result($result,$i,“suburb”);
$bedsmin_alert = mysql_result($result,$i,“bedsmin”);
$bedsmax_alert = mysql_result($result,$i,“bedsmax”);
$pricemin_alert = mysql_result($result,$i,“pricemin”);
$pricemax_alert = mysql_result($result,$i,“pricemax”);

	echo "$title_alert<br>$mode_alert, $type_alert, $state_alert, $suburb_alert, $bedsmin_alert, $bedsmax_alert, $pricemin_alert, $pricemax_alert";
	
	$i++;
}

}
?>[/php]

Thanks so much.

Alan

Admin Edit: Changed IMG tag to a linked URL instead of over sized image forcing scrolling.
Changed CODE tags to PHP tags for syntax highlighting and easier readability.

Sponsor our Newsletter | Privacy Policy | Terms of Service