Okay,

here's the deal. I am designing a "Craigslist" type deal using php/MySql.

I have everything down pat, EXCEPT I cannot figure out how to enter a simple search field (in HTML) where people can browse by city.

I have a little, no, very little experience with PhP. So, when I add the code, please know that everything I have is in BETA form, and is far from validation standards. So far, it all woks, except, I cannot figure out how to link a simple page that allows you to browse by cit.

Okay, here is the page that I am trying to get to:

<?php
require("header.php");
echo"<font size='5'>";
echo"General Header";
echo"</font>";
// Make a MySQL Connection
mysql_connect("fakeserver", "model_login", "fakepassword") or die(mysql_error());
mysql_select_db("model_login") or die(mysql_error());

// Get all the data from the "myfiles" table
$result = mysql_query("SELECT * FROM myfiles ORDER BY 1 DESC") 
or die(mysql_error());  


// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
	// Print out the contents of each row into a table
	echo"<center>";
    echo"<table width='800' height='500' bgcolor='CCCCCC' cellpadding='2' cellspacing='10'>";
    echo"<tr><td>";
    echo"<b>";
	echo $row['username'];
    echo"<br>";
    echo"From: "; 
    echo $row['city'];
    echo"</td></tr>";
    echo"<br>";
    echo"<tr align='center' bgcolor='CCCCFF' border='10'><td align='center'>";
   	echo"<font size='2'>";
    echo $row['description'];
    echo"</font>";
    echo"</td>";
	echo"<br>";
    echo"<td align='center'>";
    echo "<img width='330' height='300' src=\"junk/".$row['file']."\" >"; 
    echo"<br>";
    echo"<table width='250'>";
    echo"Ad Number-><font size='4' color='red'>";
    echo $row['RecordID'];
    echo"<br>";
    echo"<font size='2' color='000000'><B>";
    echo"To flag this ad, enter the AdNumber (in red), and a description as to why, then<br> hit the flag button";
    echo"</table>";
    echo"</td></tr></table>";
    echo"<br>";
    echo"<br>";
    echo"<FORM METHOD='POST' ACTION='flag.php'>AdNumber<INPUT TYPE='text' NAME='ID' SIZE=3>&nbsp;
    Brief FLAG reason:<INPUT TYPE='text' Name='reason' Size='30'><INPUT TYPE='SUBMIT' Name='Flag' value='FLAG'></form>";
    echo"<br>";
    echo"_________________________________________________________________________________________";
 }

 
?>

I am just looking for a simple, one box form that will let you (again), put in a city, and browse people who submitted an ad, depending on the city their ad was posted with. Also, I was looking for a way to change this "flag" system that I have concocted, because it is kinda lame. I would rather try to find a way to have a simple one-button way. ACtually, If there was a way to propogate the AdNumber $variable in a hidden HTML text feild , I would do that. I'm sure there is, but, again, I am less than a novice PhP writer. My main concern is the search. I just want to get it right, and done.

ANY HELP is greatly appriciated -(besides being told to go back to school)-

Thank You &Omega;

Hi. Did you think in use some simple PHP Ajax script?
There i upload to you an example.
www.mazur.com.ar/combos.rar

You have to create the database to test it, and change the second 'select' with a table.

ch.-

I'll check that out, and thanks for replying. Sadly, I have NO AJAX experience. My field in Web Design is more the DESIGN, than the implication.

But I am realtively smart, so I will check it out and see if I can make sense of any of it.

Well, your SQL directive and what you want seems to be different.

try for instance:
Select CONCAT(name,city).
that is not even a problem like the disaster waiting to happen in your table:

you sure you want to create tables continously in your page?

please go through what you want, i feel you are going to get a different result here.

Cheers!

Howdy,

Using a text input box for searching for city will likely be problematic -- because of spelling errors, capitalization differences, same city/different state, sql injection concerns ... the list goes on.

I would use a form <select><option> type drop down menu and populate it from the cities table in the database.

But in essence you will need to grab the form input value with PHP and use it in a sequel query.

<?php
if ( $city = $_POST['city'] ) {
  if ( !preg_match( '/^[\s\w]+$/', $city) ) {
    die( "Please only use numbers and letters in your search" );
  }
  $result = mysql_query( "SELECT * FROM `my_table` WHERE `city`='$city'" );
  if ( mysql_num_rows( $result ) ) {
    // do something with the results here ...
    $obj= mysql_fetch_object( $result );
    print $obj->field_name; // etc ...
  }
}
?>
<html>
<head>
</head>
<body>
<form method="POST">
  <input type="text" name="city" />
  <input type="submit" />
</form>
</body>
</html>

But I really think this is a bad way to go, this doesn't take into account most of the things I mentioned above. Instead maybe use something like this ...

<?php
print '<select name="city">';
$result = mysql_query( "SELECT * FROM `cities`" );
while ( $obj = mysql_fetch_object( $result ) ) {
  print "<option value=\"$obj->city_id\">$obj->city_name</option>";
}
print '</select>';
?>

Then you mostly only have to worry about SQL injection and can still use the first example code above.

There's more to it that this, like filtering the city names to pass the validation test later, and similar details, but this is a general idea.

Hope it helps

This article has been dead for over six months. Start a new discussion instead.