Re: Problem with array

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thursday 16 December 2004 13:33, Ahmed Abdel-Aliem wrote:

Put this at the beginning of all your code:

    error_reporting(E_ALL);
    ini_set('display_errors', TRUE);

Then run your code to see all the errors and warnings and notices that it 
generates. Then incorporate the changes below:

> i am retrieving records from database and putting each row in a array
> here is the code
> @ $db = mysql_connect ($server, $user, $pass);

Remove all '@'. Put in error checking and make use of mysql_error(), see 
examples in manual.

> while ($record=mysql_fetch_array($test_tr)){
>  $record[Game_ID] = stripslashes($record[Game_ID]);

This whole stripslashes() business may not be needed. In general you should 
only use it if magic_quotes_runtime is enabled in php.ini.

Also the correct syntax is:

  $record['Game_ID'] = stripslashes($record['Game_ID']);

And if you find that you really do need to use stripslashes() because 
magic_quotes_runtime is enabled then use this instead:

  foreach ($record as $key => $val) {
    $record[$key] = stripslashes($record[$val];
  }

>  echo $record[Game_Esrb_Rating];
>  if($Game_Esrb_Rating < 1){
>     $Esrb_Rate_Pic = "bar_rating_star_0.gif";

If you can be certain that $Game_Esrb_Rating is within 0-5 (ie you have 
validated your data properly before inserting into the database) then you can 
simply do 

  $Esrb_Rate_Pic = "bar_rating_star_{$Game_Esrb_Rating}.gif";

> my problem is with $Esrb_Rate_Pic, i can't put its value to the array
> , i used $row[Esrb_Rate_Pic] = $Esrb_Rate_Pic; but it didn't work

That's because it should be:

  $row['Esrb_Rate_Pic'] = $Esrb_Rate_Pic;

-- 
Jason Wong -> Gremlins Associates -> www.gremlins.biz
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *
------------------------------------------
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
------------------------------------------
/*
Robot, n.:
 University administrator.
*/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux