ecopetition Posted August 16, 2009 Share Posted August 16, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/170568-solved-adding-hack-to-php-to-mimick-database-row/ Share on other sites More sharing options...
taquitosensei Posted August 16, 2009 Share Posted August 16, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/170568-solved-adding-hack-to-php-to-mimick-database-row/#findComment-899690 Share on other sites More sharing options...
ecopetition Posted August 17, 2009 Author Share Posted August 17, 2009 Thank you Sir, much appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/170568-solved-adding-hack-to-php-to-mimick-database-row/#findComment-899727 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.