Results 1 to 10 of 10
  1. #1
    Join Date
    Jan 2010
    Posts
    1

    Post Unanswered: Search engine help

    unction escape($mixed){
    if(empty($mixed))
    return false;
    elseif(!is_array($mixed))
    return mysql_real_escape_string($mixed);
    else
    foreach($mixed as $key => $val)
    $mixed[$key] = escape($val);
    return $mixed;
    }

    require_once('connect.php');

    if(!empty($_POST['call_sign'])){
    $query = mysql_query("SELECT * FROM `en` WHERE `call_sign` LIKE '%".escape($_POST['call_sign'])."%'");
    while(($row = mysql_fetch_assoc($query)) !== FALSE)
    {
    // Print out the contents of the entry
    T1------------------------------------------------------------------------------
    echo "Call Sign :{$row['call_sign']} <br>" ;
    echo "First Name : {$row['first_name']} <br>";
    echo "Last Name : {$row['last_name']} <br>";
    T2------------------------------------------------------------------------------
    echo "Address : {$row['street_address']}<br>";
    echo "PO Box : {$row['po_box']}<br>";
    echo "City : {$row['city']}<br>";
    echo "State : {$row['state']}<br>";
    echo "Zip Code : {$row['zip_code']}<br>";
    T3-----------------------------------------------------------------------------
    echo "Previous Call:{$row['previous_callsign']}<br>";
    echo "Previous license class:{$row['previous_operator_class']}<br>";
    }
    } else
    {


    Could someone help in this, as you can see the MySQL code will look in one table for this information, but I need to pull it from three tables. As I have these separated with ---- indicates the three tables and the rows that each have.

    Could someone push me in the right direction.

    Thanks

  2. #2
    Join Date
    Feb 2010
    Posts
    5

    if you get an answer

    if you get an answer to this please shoot me an email about it at ronf57@yahoo.com
    I have similar issues where i am pulling from a few tables and my forms are posting to a few tables and i am concerned about the data integriry if one of the inserts fails.
    It seems your issue is close enough to be valuable as a pointer to a solution for mine.
    thanks in advance...sorry, if i could help ya i would have but i am quite new at this.

  3. #3
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    gentlemen, may i respectfully suggest that if you want help with your php coding, you post in the php forum

    thank you

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  4. #4
    Join Date
    Feb 2010
    Posts
    5

    i am sorry

    I thought this was a sql issue as opposed to php exclusively.
    i respect your knowledge and would consider ordering your book but i couldn't find a link to look at it that worked on your site.
    My issue...
    having to use multiple INSERTs and worrying about data integrity i thought was mysql issue.
    i don't know a way to insert into multiple tables simultaneously. As such I have a series of INSERT into `tablename`; statements, that is why I asked.
    I do know how to combine data retrieval from multiple tables via SELECT and concatation. But can't find info on the INSERTing.
    sorry if i offended you by asking.
    please point me to a phpforum you think won't tell me it's a mysql issue.
    thank you
    Ron

  5. #5
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by ronf57 View Post
    having to use multiple INSERTs and worrying about data integrity i thought was mysql issue.
    you're right

    and data integrity would be managed by foreign keys


    Quote Originally Posted by ronf57 View Post
    i don't know a way to insert into multiple tables simultaneously.
    you can't

    Quote Originally Posted by ronf57 View Post
    As such I have a series of INSERT into `tablename`; statements, that is why I asked.
    and they all work?

    if they don't work, perhaps you can post them

    without the php code, of course
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  6. #6
    Join Date
    Feb 2010
    Posts
    5

    thank you

    i think i must then have a basic table design issue then with foriegn key misunderstanding.
    my tables ALL relate to userID and they are the primary key in each.
    table: users
    >>>>userID
    >>>>username
    >>>>userpassword
    >>>>useremail

    table: useraddress
    >>>>userID
    >>>>addressstreetnumber
    >>>>addressstreetname
    >>>>addresscity
    >>>>addressstate
    >>>>addresszipcode

    table:userfirstposition
    >>>>userID
    >>>>firstcompanyname
    ect....

    tables all follow that format with userID the primary key in each. I don't get what I would need to do to have a foriegn key as the primary is the foreign key is my design basically "just wrong?"
    my inserts all looks like :
    insert into tablename userID,other items. (item list)

    I readilly admit being a newbie that is why I am buying books like mad right now and said i couldn't find a good link to your book.
    I'd appreciate any help.
    thanks in advance

  7. #7
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by ronf57 View Post
    my tables ALL relate to userID and they are the primary key in each.
    in that case, they should really not be separate tables, but rather, just one table

    for example, let's consider your users table

    userID is the primary key, which means that it must be unique

    so you can have only one Todd, only one Fred, only one Biff, and so on

    in your useraddress table, if userID is the primary key, this again means that you can have only one Todd, only one Fred, only one Biff, and so on

    in other words, you can have only one address per user

    therefore you should combine the users and useraddress tables

    on the other hand, if you ~want~ a user to have more than one address, you ~do~ need separate tables, and the userID ~cannot~ be the primary key of the useraddress table, simply because of the fact that you want there to be more than one row for any given userID

    make sense?

    it is in this latter case (where there will be multiple rows in the useraddress table for each userID), that you will want userID to be a foreign key, not the primary key

    this leaves open the question of what should be the primary key for the useraddress table, and without going into a lot of detail, an auto_increment here is probably your best bet



    p.s. here's a link where you can order my book --https://sitepoint.com/bookstore/go/150/9cdb0e6

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  8. #8
    Join Date
    Feb 2010
    Posts
    5

    i again a noob

    I follow the logic fine.
    this is a major issue for me.
    It is my understanding(misunderstanding?) that...
    in database design.
    1) each table contains ONLY ONE type of data..i.e user identification, user address, user employer current, ect....
    2) the primary key is related to the data in the table and is unique.
    my use is userID a auto incrementing INT(11)
    in my user table USERID is the primary key and USERNAME field is unique also.
    so user jbwhitenburg2 only exits once (to use at login, users are unaware of their userID number)
    I am creating a database for resumes and as such have tables userfirstcompany, usersecondcompany, ...ect each containing userid, companyname, companycity, companystate, startdate, enddate, positionheld,..ect...
    the only thing these tables have in common is the userID.
    3) i understand IF i break these usercompany tables into multiple tables one with companyinfo and one with positioninfo the userID would still be primary and Companyname would be a foreign key.
    As you can probably see somewhere in all this I am missing something about making foreign keys or table design.

  9. #9
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by ronf57 View Post
    ...I am missing something about making foreign keys or table design.
    yes... experience

    i recommend that you take a course in data modelling, and there are numerous free tutorials on the web

    you could also probably find a free app that does recruiting, rather than reinventing the wheel

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  10. #10
    Join Date
    Feb 2010
    Posts
    5

    thanks

    I will look elsewhere for help on this.
    I am surprised you answer newbie questions as it seems they annoy you.
    unfortunately, NO ONE starts out as an expert.
    I wish you well but I think some of your answers are not noob friendly and encourage folkes to do as I will do...go elsewhere for help.
    It is a shame you appear to be able to be helpful.
    And yes, even though you did not ask, I have taught courses at university level in computers and ALL students come with different backgrounds and a helpful mentor/teacher needs to meet them where the mentee is not where the mentor wants them to be.
    If you do not like to "bring the talk down to" the level of the mentee then selectively answer only those that meet your high standards.
    That is why some professors will only teach Master and Phd level courses.
    Thank you for your help- as it were.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •