Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

C to PHP

Status
Not open for further replies.

PCHomepage

Programmer
Feb 24, 2009
609
US
I am trying to convert a compiled C Web site project created by someone else into PHP and have much of it working but there are some things about it that I do not understand and am concerned of the worth of converting it.

For example, this block seems to be initializing some values from a MySQL query. I don't know C at all so I'm not sure which query it is using as the script has many:

Code:
MYSQL_RES *result;
  MYSQL_ROW row;
  int num_fields;
  int i,j,k;
  unsigned char selected=FALSE;
  char sqlstr[BUFSIZ*4];

and this is using the values

Code:
if (variable[0]) {
          k=0;
          while (variable[k]) {
              if(strcmp(variable[k],row[i]) == 0)  
              selected=TRUE;
              else if (strstr(row[i],"itemname"))
              selected=TRUE;
              k++;
          }
       }

but it's not clear to me what it's doing because of the way the script receives data from the form. For example, if I used $variable[0] (in PHP) it would just give me the first letter of the word "itemname" if that were the one submitted, $variable[1] the second letter and so on because $variable contains an array. $variable[k] and any other letter would also give only the first letter of the word.

Any thoughts or am I spinning my wheels here? Thanks.
 
the first code block is just initialising and dimensioning variables. this is not needed in php. the only one you might want to add to your code as a default position is
Code:
$selected = false;

for the second code block
Code:
if ($variable[0]):
          $k=0;
          while ( isset( $variable[$k]) ): 
              if($variable[$k] == $row[$i]):
              $selected=TRUE;
              elseif ($row[$i] == "itemname"):
              $selected=TRUE;
              endif;              
              $k++;
          endwhile
endif;
although it would be more usual to do this with a while ($row = myqsl_fetch_*()) loop

my working assumption is that the variable (variable) is an array of strings and not a char array. so normal string comparisons are the order of the day.

you'd need to post all the c (cpp and headers) for me to give more informed advice.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top