FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

Creating Alias in mysql

 


bukaida
I want to perform the following--

A table contains the attribute Name, Address and Alias. Each name in the database should have multiple entries in alias column. If an user types the main name or any of the alias name, the main name and the address should be displayed. PHP can be used as scripting language.Please suggest the database structure and PHP script for this purpose. The main name and address is one entry per record.
rvec
If you have to be able to order by alias I think the best way is to make two tables. One with all aliases and the names (if the name is unique else an id), and the other one with name and address (and id if name isn't unique). You can join the 2 tables to combine the data.

A php script to the alias with the name:
Code:

<?php

$username = "Your_database_username";
$password = "Your_pass";
$database = "The_database_name";

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$query = "SELECT * FROM table1 RIGHT JOIN table2 ORDER BY alias";
$result = mysql_query($query) or die(mysql_error());

while($row = mysql_fetch_array($result)){
   echo $row[alias] ."-". $row[name];
   echo "<br />";
}
?>


I think it should work like that.
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.