SQL query for many, many databases in PHP

enter image description here

SQL query to show all tool_tip_links related to pages_learn_more ids?

How to structure this query?

$SQL = "SELECT ptt.tool_tip_link FROM pages_tool_tip ptt JOIN pages_to_pages ptp ON ptp.tool_tip_id = ptt.tool_tip_id WHERE ptp.learn_more_id = 2"; $result = mysql_query($SQL); // or die(mysql_error()); while ($db_field = mysql_fetch_array($result)) { $reference_keys = $db_field['tool_tip_link']; } echo $reference_keys; 

How to combine these queries to make them clean and efficient? Thanks for the help.

-------------------------------------- -------- UPDATE --- ----------------------- Using this code:

  "SELECT ptt.tool_tip_link FROM pages_tool_tip ptt JOIN pages_to_pages ptp ON ptp.tool_tip_id = ptt.tool_tip_id JOIN pages_learn_more plm ON plm.id = ptp.learn_more_id WHERE plm.id = 2"; 

Gotta show me 3 tool_tip_links. However, it only returns the last field in the database, which is 4 → LINK 4

enter image description here

So, how do I get all the links, not just the latest? again..

-------------------------------------- -------- UPDATE --- -----------------------

When I exit mysql_num_rows, it correctly displays 3 for id # 2.

So, what code do I need to display all three lines? ONION ARRAY? I do not get it because it needs to be looped in my array . Can I just respond with $reference_keys or should I do something else?

I also tried foreach and returned an error. What am I doing wrong? please inform.

more db views → hope this helps to find a solution.

this is the pages_learn_more table

this is the pages tooltip table

+4
source share
2 answers

According to your criteria:

SQL query to show all tool_tip_links associated with pages_learn_more ids

Here you go

 SELECT ptt.tool_tip_link FROM pages_tool_tip ptt JOIN pages_to_pages ptp ON ptp.tool_tip_id = ptt.tool_tip_id WHERE ptp.learn_more_id = :id 

:id - here is the variable.

+2
source

You must rewrite your request to:

 "SELECT ptt.tool_tip_link FROM pages_learn_more plm JOIN pages_to_pages ptp ON plm.id = ptp.learn_more_id JOIN pages_tool_tip ptt ON ptp.tool_tip_id = ptt.tool_tip_id WHERE plm.id = 2"; 

This makes page_learn_more the main table of your join and finds what you want.

+1
source

All Articles