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 ";
}
}
You can use the comparison operator:
OR, use the case sensitive string compare function strcmp
OR, use the case insensitive string compare function strcasecmp
Edit:
You can use any of the above methods to check if the two strings are equal, and set your variable appropriately. E.g.
Edit: You have an error with your function (it’s not returning anything). Try this: