Jump to content

Recommended Posts

Hi Guys,

Basically i have 2 tables:

- thumbs (this stores all the thumbs on the site)

- pages (this stores all the pages on the site)

 

i am trying to establish a link between the thumbs table and the pages table via the page_id on both tables.

 

i've considered using a JOIN in my mysql query but only problem is that not every record from the pages table will have a thumb, which will result in displaying only records that contain thumbs in them.

 

my other solution was to have 2 SELECT queries:

- one query for thumbs

- one query for pages

 

and then try to combine them using arrays like this:

$sql="SELECT * FROM thumbnails";
$result = db_query($sql);
while($row=mysql_fetch_array($result))
{
	$page_id = $row["page_id"];
	$thumbnail_name = $row["thumbnail_name"];
	$thumbnail_array[$page_id] = array($thumbnail_name);
}

$sql="SELECT * FROM pages";
$result = db_query($sql);
while($row=mysql_fetch_array($result))
{
	$nav_array[$row['page_id']] = array(
	'page_id' => $row['page_id'],
	'page_title' => $row['page_title'],
	'page_parent_id' => $row['page_parent_id'],
	'thumbnail_name' => $thumbnail_array[$page_id]
	);
}

 

as you can see, i've already tried to combine them but i dont think it works unless i dont know how to output it correctly.

 

to be perferctly honest, i am abit slow when it comes to arrays but hopefully any suggestions or help will just make me a little bit better at it

 

Link to comment
https://forums.phpfreaks.com/topic/184263-combining-arrays/
Share on other sites

i've considered using a JOIN in my mysql query but only problem is that not every record from the pages table will have a thumb, which will result in displaying only records that contain thumbs in them.

Not if you use a LEFT JOIN. All the records from the left-hand table will be used, even if there is no matching value in the second or right-hand table.

Link to comment
https://forums.phpfreaks.com/topic/184263-combining-arrays/#findComment-972766
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.