PDA

Arată versiune īntreagă : Ajutor php



kytionut
28.01.2011, 08:03
Nu stiu daca am plasat bine subiectul dar:
Vreau sa fac un script de coduri postale dar nu reusesc
Nu stiu ce si unde gresesc deoarece nu functioneaza.Cine doreste baza de coduri postale sa zica in topic

<!-- CSS Stylesheet -->
<style type="text/css" id="dinBacau_css">
<!--

/* dinBacau CSS For Style 'Default' */
.text_normal
{
color: black;
font-family: arial;
font-size: 11px;
text-decoration: none;
}.titlu
{
color: #FFFFFF;
font-family: arial;
font-size: 12px;
text-decoration: none;
font-weight: bold;
}
table.blog {
border: 1px solid #999999;
width: 500;
color: #FFFFFF;
font-family: arial;
font-size: 12px;
text-decoration: none;
font-weight: bold;
} .blog2{
border: 1px solid #999999;
color: #000000;
text-align: center;
font-family: arial;
font-size: 12px;
text-decoration: none;
}

-->
</style>
<form name="search" method="post" action="<?$_SERVER['PHP_SELF']?>">
Cauta:
<input type="text" name="find" /> in
<Select NAME="field">
<Option VALUE="localitate">Localitatea</option>
<Option VALUE="strada">Strada</option>
<Option VALUE="numar">Numarul</option>
</Select>
<input type="hidden" name="searching" value="yes" />
<input type="submit" name="search" value="Cauta" />
</form>
<p>
<?
//This is only displayed if they have submitted the form
if ($_POST['searching'] =="yes")
{
echo "<h2>Rezultate Cautare</h2><p>";

//If they did not enter a search term we give them an error
if ($_POST['find'] == "")
{
echo "<p>You forgot to enter a search term";
exit;
}

// Otherwise we connect to our Database
mysql_connect("localhost", "298078_kyt", "prepelita") or die(mysql_error());
mysql_select_db("scurt_zxq_kyt") or die(mysql_error());

// We preform a bit of filtering
$_POST['find'] = strtoupper($find);
$_POST['find'] = strip_tags($find);
$_POST['find'] = trim ($find);

//Now we search for our search term, in the field the user specified
$data = mysql_query("SELECT * FROM users WHERE upper($field) LIKE'%$find%'");
echo "<table class='blog' >";
echo "<tr><th align='center' valign='top' width='100' bgcolor='#999999'>Localitate</th><th align='center' valign='top' width='100' style='width=250;' bgcolor='#999999'>Numele Strazii</th> <th align='center' valign='top' bgcolor='#999999' >Judet</th><th align='center' valign='top' width='100' bgcolor='#999999'>Cod Postal</th></tr>";
//And we display the results
while($result = mysql_fetch_array( $data ))
{
echo "<tr ><td class='blog2'>";
echo $result['localitate'];
echo "</td><td class='blog2'>";
echo $result['strada'];
echo "</td><td class='blog2'>";
echo $result['judet'];
echo "<td class='blog2' >";
echo $result['cp'];
echo "</td></tr>";
}
echo "</table>";
//This counts the number or results - and if there wasn't any it gives them a little message explaining that
$anymatches=mysql_num_rows($data);
if ($_POST['anymatches'] == 0)
{
echo "Sorry, but we can not find an entry to match your query<br><br>";
}

//And we remind them what they searched for
echo "<b>Ai cautat Codul Postal pentru:</b> " .$_POST['find'];
}
?>

socu
28.01.2011, 10:48
nu merge pentru ca $find nu este nicaieri. tu aveai tot timpul $_POST['find']=functie($find). incearca asa:


$find= $_POST['find'];
$find = strtoupper($find);
$find = strip_tags($find);
$find = trim ($find);

kytionut
28.01.2011, 11:28
<!-- CSS Stylesheet -->
<style type="text/css" id="dinBacau_css">
<!--

/* dinBacau CSS For Style 'Default' */
.text_normal
{
color: black;
font-family: arial;
font-size: 11px;
text-decoration: none;
}.titlu
{
color: #FFFFFF;
font-family: arial;
font-size: 12px;
text-decoration: none;
font-weight: bold;
}
table.blog {
border: 1px solid #999999;
width: 500;
color: #FFFFFF;
font-family: arial;
font-size: 12px;
text-decoration: none;
font-weight: bold;
} .blog2{
border: 1px solid #999999;
color: #000000;
text-align: center;
font-family: arial;
font-size: 12px;
text-decoration: none;
}

-->
</style>
<form name="search" method="post" action="<?$_SERVER['PHP_SELF']?>">
Cauta:
<input type="text" name="find" /> in
<Select NAME="field">
<Option VALUE="localitate">Localitatea</option>
<Option VALUE="strada">Strada</option>
<Option VALUE="numar">Numarul</option>
</Select>
<input type="hidden" name="searching" value="yes" />
<input type="submit" name="search" value="Cauta" />
</form>
<p>
<?
//This is only displayed if they have submitted the form
if ($_POST['searching'] =="yes")
{
echo "<h2>Rezultate Cautare</h2><p>";

//If they did not enter a search term we give them an error
if ($_POST['find'] == "")
{
echo "<p>You forgot to enter a search term";
exit;
}

// Otherwise we connect to our Database
mysql_connect("localhost", "abcconst_cod", "test007") or die(mysql_error());
mysql_select_db("abcconst_cod") or die(mysql_error());

// We preform a bit of filtering
$find= $_POST['find'];
$find = strtoupper($find);
$find = strip_tags($find);
$find = trim ($find);

//Now we search for our search term, in the field the user specified
$data = mysql_query("SELECT * FROM users WHERE upper($field) LIKE'%$find%'");
echo "<table class='blog' >";
echo "<tr><th align='center' valign='top' width='100' bgcolor='#999999'>Localitate</th><th align='center' valign='top' width='100' style='width=250;' bgcolor='#999999'>Numele Strazii</th> <th align='center' valign='top' bgcolor='#999999' >Judet</th><th align='center' valign='top' width='100' bgcolor='#999999'>Cod Postal</th></tr>";
//And we display the results
while($result = mysql_fetch_array( $data ))
{
echo "<tr ><td class='blog2'>";
echo $result['localitate'];
echo "</td><td class='blog2'>";
echo $result['strada'];
echo "</td><td class='blog2'>";
echo $result['judet'];
echo "<td class='blog2' >";
echo $result['cp'];
echo "</td></tr>";
}
echo "</table>";
//This counts the number or results - and if there wasn't any it gives them a little message explaining that
$anymatches=mysql_num_rows($data);
if ($_POST['anymatches'] == 0)
{
echo "Sorry, but we can not find an entry to match your query<br><br>";
}

//And we remind them what they searched for
echo "<b>Ai cautat Codul Postal pentru:</b> " .$_POST['find'];
}
?>
link http://www.abc-construct.ro/yd/
deci tot nu merge

crt_
28.01.2011, 13:04
$data = mysql_query("SELECT * FROM users WHERE upper($field) LIKE'%$find%'");

Selectezi din tabela "users". Eu zic ca nu ai tabela asta in baza de date. Cred ca ai chiar mai multe. Deci nu are cum sa mearga scriptul asta. Si mai sunt cateva probleme in el. Posteaza structura bazei de date (nu toata baza de date) ca sa incercam sa te ajutam.

Ar fi ok sa ca scriptul sa faca mai intai o sortare dupa judet sau/si localitate (in functie de cum arata baza de date). Ar reduce timpul de cautare in baza de date. Apoi sa faca cautare dupa adresa. Aici e putin mai complicat dar depinde cum e baza de date. Apoi afisarea datelor Judet/Localitate, Adresa, Cod Postal.

socu
28.01.2011, 16:15
acum nu ai nicaieri $field.
da echo la queryul ce vrei sa-l executi, fa debug!
ar trebui sa citesti niste tutoriale pentru ca nu intelegi anumite lucruri de baza.

kytionut
08.02.2011, 15:28
-- phpMyAdmin SQL Dump
-- version 2.10.1
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Apr 17, 2009 at 10:56 PM
-- Server version: 5.0.45
-- PHP Version: 5.2.5

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

--
-- Database: `anunturi`
--

-- --------------------------------------------------------

--
-- Table structure for table `coduri_postale`
--

CREATE TABLE `coduri_postale` (
`id` int(11) NOT NULL auto_increment,
`judet` text NOT NULL,
`localitate` text NOT NULL,
`tip_strada` text NOT NULL,
`denumire` text NOT NULL,
`cod` varchar(10) NOT NULL,
`sector` varchar(1) NOT NULL,
`oficiu` text NOT NULL,
`adresa` text NOT NULL,
UNIQUE KEY `id` (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=51899 ;

--
-- Dumping data for table `coduri_postale`
--

INSERT INTO `coduri_postale` (`id`, `judet`, `localitate`, `tip_strada`, `denumire`, `cod`, `sector`, `oficiu`, `adresa`)

kytionut
10.02.2011, 22:07
Nu ma mai poate ajuta nimeni?