Page 1 of 1
pulling from mysql
Posted: Wed Jul 12, 2006 4:08 pm
by ziggy1621
hello all,
I would like to pull info from a mysql table very specifically.
I have a form that submits the following to the db:
-Name
-Address
-City
-State
-Zip
Now i want to use a form that will draw all listings based on the first 4 digits of the zip, so I have a form that allows them to put in the zip, on the action page it changes to:
Code: Select all
$zip="$_REQUEST[zip]";
$ziplookup=substr($zip,0,4);
So how do I get it to look through the table for
$ziplookup and display the items in that line?
thanks in advance,
ziggy
Posted: Wed Jul 12, 2006 4:16 pm
by RobertGonzalez
Code: Select all
<?php
$zip = $_POST['zip'];
$ziplookup = substr($zip, 0, 4);
$sql = 'SELECT * FROM `thistable` WHERE `zipfield` LIKE \'' . $ziplookup . '%\'';
?>
Posted: Wed Jul 12, 2006 4:22 pm
by ziggy1621
Everah wrote:Code: Select all
<?php
$zip = $_POST['zip'];
$ziplookup = substr($zip, 0, 4);
$sql = 'SELECT * FROM `thistable` WHERE `zipfield` LIKE \'' . $ziplookup . '%\'';
?>
Works like a charm!... Thanks
Posted: Wed Jul 12, 2006 4:25 pm
by RobertGonzalez
You're welcome. Glad I could help.
Posted: Wed Jul 12, 2006 4:48 pm
by ziggy1621
Everah wrote:You're welcome. Glad I could help.
got another question. If you can't help... I'll start another thread, but I'd like to have those items that are displayed each be their own form.
By that I mean have a "submit" button next to each displayed result that sends the info in that line only to a form.
I.E.
Name1
Address
Phone
SUBMIT BUTTON
Name2
Address
Phone
SUBMIT BUTTON.
Each submit button works only for its line in the mysql table.
Hope I'm not too far out there. Thx for the help
ziggy
Posted: Wed Jul 12, 2006 11:15 pm
by RobertGonzalez
When you loop through the results, instead of echoing the result data, echoing out a form with the data. I would recommend you give each form a unique ID.
Posted: Thu Jul 13, 2006 7:34 am
by ziggy1621
Everah wrote:When you loop through the results, instead of echoing the result data, echoing out a form with the data. I would recommend you give each form a unique ID.
okay, but how would I give it a unique ID if its looping? wait... each has its own unique ID in the table, so I can just have it echo its ID from the db right?
Posted: Thu Jul 13, 2006 8:35 am
by RobertGonzalez
Why not give it a try to test it out? See what works.
PS You're on the right track. Loops work by incrementing in some capacity, so as you run through a loop, you can use the loops increment if it is available to you or you can create one. But try it, then let us know how it is going.