0

Most annoyingly I cant get this to work, I made a sample table where there will be duplicate entries in some of the fields, and I need to display then all.

table looks a bit like this
id county city phonenumber

the id is unique as is the phonenumber, but there are records that would have the same county and city.. i need to search on county and display all the records for that county, but it only returns one record..

so I would want a result like the below, if my searh query was "cardiff"

1 cardiff llandaff 123
2 cardiff llandaff 456
3 cardiff pontypoo 856
4 cardiff pontypoo 966

hope you can help...

4
Contributors
17
Replies
21
Views
4 Years
Discussion Span
Last Post by websponge
Featured Replies
  • Yes, in this case you are echoing the last row from the database because your script continues after the while loop. As @pritaeas said, you have to echo inside your `while` Read More

0

my search string is this:

$result = mysql_query("SELECT * FROM area WHERE county = '$county'");

$county coming from a form...

0

Try this

$result = mysql_query("SELECT * FROM area WHERE county = '".$county."'");

But the query looks allright, try to run your query from the phpmyadmin or the administrative tool you have, and see the results there first.

0

still will only display one result :( ive been on this for over an hour.. thanks for the reply though

0

No trailing spaces, if I echo the result I get "Resource id #4"

0
<?php
echo "<h1>Results Summary</h1>";
//TABLE RESULTS
$county = $_POST['county'];
$con = mysql_connect("localhost","root","");
mysql_select_db('project', $con) or die('Cant Connect');
$result = mysql_query("SELECT * FROM area WHERE county = '".$county."'");
while($row = mysql_fetch_array($result))
{
$id = $row['id'];
$county = $row['county'];
$city = $row['city'];
$phone = $row['phone'];
}
echo $id;
echo $county;
echo $city;
echo $phone;
?>
1

Yes, in this case you are echoing the last row from the database because your script continues after the while loop.

As @pritaeas said, you have to echo inside your while

Edited by Szabi Zsoldos

0

How incredibly stupid of me..... thank you both very much, I feel a bit dull..

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.