Jump to content

Recommended Posts

Hi all,

 

I have the following sample code for selecting a row:

$sql = "SELECT *
FROM names
WHERE surname = $input_surname
AND gender = $input_gender
ORDER BY surname ASC";
$result = $db->query($sql);
while($row = $db->fetch_assoc($result))
{
$names[] = $row;
}

 

Is it at all possible to add entries into the the $names[] array which are not in the names table but in a different table with different column titles?

 

For example, I have my $names array, with a first_name column, surname column and gender column, but have another table called more_names, with a surname_column, location column, and height column. I don't care too much about the location and height column, but of the surname column, is it possible to merge these rows into the $names array (whilst assigning default values for the first_name column and gender column?)?

 

I hope this is understandable enough.

 

Thanks a lot

Eco

more of a mysql question. But you'll want to use a UNION

$sql = "SELECT first_name,surname,gender 
FROM names
where surname=$input_surname 
and gender=$input_gender
UNION 
select 
'default_firstname' as first_name, 
surname, 
'default_gender' as gender 
from more_names
WHERE surname = $input_surname
ORDER BY surname ASC";

you may have to tweak it some and it hasn't been test yet. But that should point you in the right direction.

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.