Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6854161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:35:58+00:00 2026-05-27T01:35:58+00:00

Table1: id, cr_id 10 | 81 10 | 82 Table2: cr_id, name 80 |

  • 0
Table1: id, cr_id 
10 | 81
10 | 82

Table2: cr_id, name
80 | Title80
81 | Title81
82 | Title82
83 | Title83

I have two mysql queries for them (getting results with mysql_fetch_array()). I’m doing a html select box, in which some values will be selected.

How to compare strings cr_id.Table1 and cr_id.Table2 without using mysql query?

Upd. I want to achieve a php function which will return “selected” if cr_id.Table1==ccr_id.Table2 and Null if the not.

Upd2. What’s wrong?

function checked($result_creative, $result_creative_chkd) {
                $select_row = null;
                if( strcmp( $result_creative['creative_id'], $result_creative_chkd['creative_id']) == 0)
                    {
                        $select_row = 'selected';
                    }
                };

            $query_creative_chkd=mysql_query("SELECT * FROM s_s_creative WHERE $id=id");
            $creative_chkd=mysql_num_rows($query_creative_chkd);
                if($creative_chkd != 0) 
                    {
                        while ($result_creative_chkd = mysql_fetch_array($query_creative_chkd)) 
                        {
                        $creative_s_id_chkd = $result_creative_chkd['id'];
                        $creative_id_chkd = $result_creative_chkd['creative_id'];
                        }
                    };

            $query_creative=mysql_query("SELECT * FROM s_creative ORDER BY creative_id ASC");
            $numrows_creative=mysql_num_rows($query_creative);
                if($numrows_creative != 0) 
                    {
                    while ($result_creative = mysql_fetch_array($query_creative)) 
                        {
                        $creative_id = $result_creative['creative_id'];
                        $creative_name = $result_creative['name'];

                        $select_row = checked($result_creative, $result_creative_chkd);

                        echo "<option value=\"".$creative_id."\" ". $select_row ." >".$creative_name."</option>\n  ";   
                        }
                    } 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T01:35:59+00:00Added an answer on May 27, 2026 at 1:35 am

    You can use the comparison operator:

    if( $row['cr_id'] == $row2['cr_id'])
    

    OR, use the case sensitive string compare function strcmp

    if( strcmp( $row['cr_id'], $row2['cr_id']) == 0)
    

    OR, use the case insensitive string compare function strcasecmp

    if( strcasecmp( $row['cr_id'], $row2['cr_id']) == 0)
    

    Edit:

    Upd. I want to achieve a php function which will return “selected” if
    cr_id.Table1==ccr_id.Table2 and Null if the not.

    You can use any of the above methods to check if the two strings are equal, and set your variable appropriately. E.g.

    // Case sensitive string compare:
    $selected = null;
    if( strcmp( $row['cr_id'], $row2['cr_id']) == 0)
    {
        $selected = 'selected';
    }
    

    Edit: You have an error with your function (it’s not returning anything). Try this:

    function checked( $result_creative, $result_creative_chkd) 
    {    
        return ( strcmp( $result_creative['creative_id'], $result_creative_chkd['creative_id']) == 0) ? 'selected' : null;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Table1: id - name 1 - john 2 - david 3 - dilio Table2:
table1 is the parent table with a column ID and table2 has a column
Table1: ResourceID Name0 (STRING) NumberOfLongons0 (INT) LastLogon0 (DateTIME) Table2: ResourceID NetbiosName0 I am trying
Table1 ID Loc ----------- 001 null 002 null 003 PYD 004 null .... Table2
I have joining two tables,There are hundreds of records in table a and there
Let's say I have 2 tables, Contacts and Phones . User can input name
i have a function : def tong_thoigian (self,cr,uid,ids,context={}): obj=self.browse(cr,uid,ids,context=context)[0] cr.execute('''select name,giolam from x_giolam where
I have used FrameLayout in which I have used two LinearLayouts. The second one
I have a schema like this CREATE TABLE TrainManager( train_name VARCHAR(5) REFERENCES Train(name), station_id
Table1 Time 10:00:00 12:00:00 Absent 14:00:00 Holiday ..., Time column Datatype is varchar I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.