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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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);

?> 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.