pulling from mysql

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ziggy1621
Forum Commoner
Posts: 37
Joined: Mon Sep 12, 2005 5:12 pm

pulling from mysql

Post 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
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Code: Select all

<?php
$zip = $_POST['zip']; 
$ziplookup = substr($zip, 0, 4);
$sql = 'SELECT * FROM `thistable` WHERE `zipfield` LIKE \'' . $ziplookup . '%\'';
?>
ziggy1621
Forum Commoner
Posts: 37
Joined: Mon Sep 12, 2005 5:12 pm

Post 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
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

You're welcome. Glad I could help.
ziggy1621
Forum Commoner
Posts: 37
Joined: Mon Sep 12, 2005 5:12 pm

Post 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
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
ziggy1621
Forum Commoner
Posts: 37
Joined: Mon Sep 12, 2005 5:12 pm

Post 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?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
Post Reply