• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A newbie on php and CI

#11
[eluser]sandwormusmc[/eluser]
When you did the print_r of $result, you were printing out a reference to the resulting data set of your SQL statement. This is how PHP keeps track of the data it pulled as a result of your query. Hence the "mysql_result" part of the CI_DB_mysql_result object.

What you could have done from there is something like:

Code:
while($row=mysql_fetch_row($result)){
  print_r($result);
}

This would have printed out all of the resulting rows from the original query. CI does this for you with the functions "result()", "result_array()", and "result_object()".

Also, another observation ... you could have used double quotes in your first SQL call. Instead of
Code:
$this->db->query(’Select nam_first_name from NAM where nam_id = “.$var1.“‘);
, you could have used something like
Code:
$this->db->query("SELECT nam_first_name FROM NAM WHERE nam_id = $var1;");

Single quotes: doesn't parse the variables in the string; Double quotes: will automatically expand the variables.

Not sure on the performance impact, but it makes the code a bit readable. Big Grin

#12
[eluser]sophistry[/eluser]
just to note... if you are coding for database portability don't use PHP mysql functions right in the code - use CI's active record to buffer youself from change and take advantage of security features and string escaping.

#13
[eluser]Gweg[/eluser]
[quote author="sophistry" date="1202877557"]just to note... if you are coding for database portability don't use PHP mysql functions right in the code - use CI's active record to buffer youself from change and take advantage of security features and string escaping.[/quote]

So new ask : what is the mysql function in my code (the code display in my past post) ?

#14
[eluser]sophistry[/eluser]
you must mean "So, new question:" because "So new ask:" doesn't make any sense in English. :-) But, I knew what you meant!

I was mentioning it because sandwormusmc dropped the mysql function into his example code and I wanted to highlight it.

#15
[eluser]Gweg[/eluser]
Ok Smile Thx to teach me english, php and Ci... Good professor Smile


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.