0

i want make a different link for array data in mysql database.

for example i store data like below in my database:

data1,data2,data3 in one column

and i want fetch them like below by one query:

echo'
<a href="mydomain.php?'.$row[data1].'">data1</a>
<a href="mydomain.php?'.$row[data2].'">data2</a>
<a href="mydomain.php?'.$row[data3].'">data3</a>';
3
  • 1
    Storing data1,data2,data3 in a single column should make you physically uncomfortable. This is a sign that your database is in desperate need of refactoring. Commented Dec 3, 2016 at 20:57
  • In any case, what is stopping you from retrieving data1,data2,data3 from your one column and using it in your output? Commented Dec 3, 2016 at 20:58
  • i get some data from html form and this data maybe will one or several and i store them in one column in table like data1 or data1,data2 maybe i am wrong if you have database solution for store them please Guidance me. thanks Commented Dec 3, 2016 at 21:05

2 Answers 2

1

If your data is stored as "data1,data2,data3" in a column named "column" of your table:

$data = explode(",", $row["column"]);

echo '<a href="mydomain.php?'.$data[0].'">data1</a>';

But as said above, you should avoid storing multiple data in one column.

Sign up to request clarification or add additional context in comments.

Comments

0

Something like this in your database retrieving loop :

$data = explode(',',$row['COLOUMN_NAME']);
echo'
<a href="mydomain.php?'.$data[0].'">data1</a>
<a href="mydomain.php?'.$data[1].'">data2</a>
<a href="mydomain.php?'.$data[2].'">data3</a>';

2 Comments

thanks but one question. is this query correct for fetch data? SELECT * FROM table WHERE column LIKE '%data1,data2%' ?
Yes , if they are in this order , i mean data1,data2 not data2,data1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.