Jump to content

Get the different information in a field


miligraf

Recommended Posts

YOu need to be more specific. Is this a text field where the user has entered four values? Are they separated by a delimiter such as a comma?

 

Is it a select field? If so, you will probably need some javascript with a hidden field to capture all the values into PHP.

 

Specifics please.

ok i was not so specific, sorry  ::)

 

Heres an example with a table:

 

id-----------name-------------thing----------color

01----------Jones-------------car------------red

02----------Al-----------------house---------blue

03----------Cher--------------bottle----------yellow

04----------Santana-----------cat------------red

05----------Maggie------------bicycle---------green

06----------Homer-------------plane-----------yellow

 

How can i get the info in the "color" field like this: red, blue, yellow, green. (with the colors not being repeated)

Instead of getting each "color" of each "id": red, blue, yellow, red, green, yellow.

 

I hope you understand me, thanks.

Sorry still not 100% sure what your asking!

you asking about a database (if so what database) or a form!

 

for a mysql database you could use something like this!

<?php

$conn = mysql_connect("localhost", "mysql_user", "mysql_password");

if (!$conn) {
    echo "Unable to connect to DB: " . mysql_error();
    exit;
}

if (!mysql_select_db("mydbname")) {
    echo "Unable to select mydbname: " . mysql_error();
    exit;
}

$sql = "SELECT * FROM thetable";
//or
//$sql = "SELECT * FROM thetable WHERE ID = 1";
//or
//$sql = "SELECT * FROM thetable WHERE color = 'red' "; //note the single quotes

$result = mysql_query($sql);

if (!$result) {
    echo "Could not successfully run query ($sql) from DB: " . mysql_error();
    exit;
}

if (mysql_num_rows($result) == 0) {
    echo "No rows found, nothing to print so am exiting";
    exit;
}

while ($row = mysql_fetch_assoc($result)) {
    echo $row["id"];
    echo "=";
    echo $row["color"];
    echo "<br>";
}

mysql_free_result($result);

?> 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.