User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 456,588 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,582 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 667 | Replies: 4
Reply
Join Date: Nov 2007
Posts: 2
Reputation: Chris101a is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Chris101a Chris101a is offline Offline
Newbie Poster

Help Need Help To Complete Php Project!!

  #1  
Nov 2nd, 2007
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;
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Sep 2007
Location: Buenos Aires
Posts: 30
Reputation: chmazur is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 2
chmazur's Avatar
chmazur chmazur is offline Offline
Light Poster

Re: Need Help To Complete Php Project!!

  #2  
Nov 2nd, 2007
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.-
Reply With Quote  
Join Date: Nov 2007
Posts: 2
Reputation: Chris101a is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Chris101a Chris101a is offline Offline
Newbie Poster

Re: Need Help To Complete Php Project!!

  #3  
Nov 2nd, 2007
Originally Posted by chmazur View Post
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.
Reply With Quote  
Join Date: Dec 2007
Posts: 10
Reputation: hakimkal is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
hakimkal hakimkal is offline Offline
Newbie Poster

Re: Need Help To Complete Php Project!!

  #4  
Aug 18th, 2008
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!
Reply With Quote  
Join Date: Aug 2008
Posts: 375
Reputation: langsor is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 34
langsor langsor is offline Offline
Posting Whiz

Re: Need Help To Complete Php Project!!

  #5  
Aug 18th, 2008
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
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 6:37 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC